forked from googleapis/google-cloud-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetrics_service_v2_client.js
More file actions
558 lines (521 loc) · 19.4 KB
/
metrics_service_v2_client.js
File metadata and controls
558 lines (521 loc) · 19.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
/*
* Copyright 2016 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* EDITING INSTRUCTIONS
* This file was generated from the file
* https://github.com/googleapis/googleapis/blob/master/google/logging/v2/logging_metrics.proto,
* and updates to that file get reflected here through a refresh process.
* For the short term, the refresh process will only be runnable by Google
* engineers.
*
* The only allowed edits are to method and file documentation. A 3-way
* merge preserves those additions if the generated source changes.
*/
/* TODO: introduce line-wrapping so that it never exceeds the limit. */
/* jscs: disable maximumLineLength */
'use strict';
var configData = require('./metrics_service_v2_client_config');
var extend = require('extend');
var gax = require('google-gax');
var SERVICE_ADDRESS = 'logging.googleapis.com';
var DEFAULT_SERVICE_PORT = 443;
var CODE_GEN_NAME_VERSION = 'gapic/0.1.0';
var PAGE_DESCRIPTORS = {
listLogMetrics: new gax.PageDescriptor(
'pageToken',
'nextPageToken',
'metrics')
};
/**
* The scopes needed to make gRPC calls to all of the methods defined in
* this service.
*/
var ALL_SCOPES = [
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/cloud-platform.read-only',
'https://www.googleapis.com/auth/logging.admin',
'https://www.googleapis.com/auth/logging.read',
'https://www.googleapis.com/auth/logging.write'
];
/**
* Service for configuring logs-based metrics.
*
* This will be created through a builder function which can be obtained by the module.
* See the following example of how to initialize the module and how to access to the builder.
* @see {@link metricsServiceV2Client}
*
* @example
* var loggingV2 = require('@google-cloud/logging').v2({
* // optional auth parameters.
* });
* var client = loggingV2.metricsServiceV2Client();
*
* @class
*/
function MetricsServiceV2Client(gaxGrpc, grpcClients, opts) {
opts = extend({
servicePath: SERVICE_ADDRESS,
port: DEFAULT_SERVICE_PORT,
clientConfig: {}
}, opts);
var googleApiClient = [
'gl-node/' + process.versions.node
];
if (opts.libName && opts.libVersion) {
googleApiClient.push(opts.libName + '/' + opts.libVersion);
}
googleApiClient.push(
CODE_GEN_NAME_VERSION,
'gax/' + gax.version,
'grpc/' + gaxGrpc.grpcVersion
);
var defaults = gaxGrpc.constructSettings(
'google.logging.v2.MetricsServiceV2',
configData,
opts.clientConfig,
{'x-goog-api-client': googleApiClient.join(' ')});
var self = this;
this.auth = gaxGrpc.auth;
var metricsServiceV2Stub = gaxGrpc.createStub(
grpcClients.google.logging.v2.MetricsServiceV2,
opts);
var metricsServiceV2StubMethods = [
'listLogMetrics',
'getLogMetric',
'createLogMetric',
'updateLogMetric',
'deleteLogMetric'
];
metricsServiceV2StubMethods.forEach(function(methodName) {
self['_' + methodName] = gax.createApiCall(
metricsServiceV2Stub.then(function(metricsServiceV2Stub) {
return function() {
var args = Array.prototype.slice.call(arguments, 0);
return metricsServiceV2Stub[methodName].apply(metricsServiceV2Stub, args);
};
}),
defaults[methodName],
PAGE_DESCRIPTORS[methodName]);
});
}
// Path templates
var PROJECT_PATH_TEMPLATE = new gax.PathTemplate(
'projects/{project}');
var METRIC_PATH_TEMPLATE = new gax.PathTemplate(
'projects/{project}/metrics/{metric}');
/**
* Returns a fully-qualified project resource name string.
* @param {String} project
* @returns {String}
*/
MetricsServiceV2Client.prototype.projectPath = function(project) {
return PROJECT_PATH_TEMPLATE.render({
project: project
});
};
/**
* Parses the projectName from a project resource.
* @param {String} projectName
* A fully-qualified path representing a project resources.
* @returns {String} - A string representing the project.
*/
MetricsServiceV2Client.prototype.matchProjectFromProjectName = function(projectName) {
return PROJECT_PATH_TEMPLATE.match(projectName).project;
};
/**
* Returns a fully-qualified metric resource name string.
* @param {String} project
* @param {String} metric
* @returns {String}
*/
MetricsServiceV2Client.prototype.metricPath = function(project, metric) {
return METRIC_PATH_TEMPLATE.render({
project: project,
metric: metric
});
};
/**
* Parses the metricName from a metric resource.
* @param {String} metricName
* A fully-qualified path representing a metric resources.
* @returns {String} - A string representing the project.
*/
MetricsServiceV2Client.prototype.matchProjectFromMetricName = function(metricName) {
return METRIC_PATH_TEMPLATE.match(metricName).project;
};
/**
* Parses the metricName from a metric resource.
* @param {String} metricName
* A fully-qualified path representing a metric resources.
* @returns {String} - A string representing the metric.
*/
MetricsServiceV2Client.prototype.matchMetricFromMetricName = function(metricName) {
return METRIC_PATH_TEMPLATE.match(metricName).metric;
};
/**
* Get the project ID used by this class.
* @aram {function(Error, string)} callback - the callback to be called with
* the current project Id.
*/
MetricsServiceV2Client.prototype.getProjectId = function(callback) {
return this.auth.getProjectId(callback);
};
// Service calls
/**
* Lists logs-based metrics.
*
* @param {Object} request
* The request object that will be sent.
* @param {string} request.parent
* Required. The name of the project containing the metrics:
*
* "projects/[PROJECT_ID]"
* @param {number=} request.pageSize
* The maximum number of resources contained in the underlying API
* response. If page streaming is performed per-resource, this
* parameter does not affect the return value. If page streaming is
* performed per-page, this determines the maximum number of
* resources in a page.
* @param {Object=} options
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
* @param {function(?Error, ?Array, ?Object, ?Object)=} callback
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is Array of [LogMetric]{@link LogMetric}.
*
* When autoPaginate: false is specified through options, it contains the result
* in a single response. If the response indicates the next page exists, the third
* parameter is set to be used for the next request object. The fourth parameter keeps
* the raw response object of an object representing [ListLogMetricsResponse]{@link ListLogMetricsResponse}.
* @return {Promise} - The promise which resolves to an array.
* The first element of the array is Array of [LogMetric]{@link LogMetric}.
*
* When autoPaginate: false is specified through options, the array has three elements.
* The first element is Array of [LogMetric]{@link LogMetric} in a single response.
* The second element is the next request object if the response
* indicates the next page exists, or null. The third element is
* an object representing [ListLogMetricsResponse]{@link ListLogMetricsResponse}.
*
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* var client = loggingV2.metricsServiceV2Client();
* var formattedParent = client.projectPath("[PROJECT]");
* // Iterate over all elements.
* client.listLogMetrics({parent: formattedParent}).then(function(responses) {
* var resources = responses[0];
* for (var i = 0; i < resources.length; ++i) {
* // doThingsWith(resources[i])
* }
* }).catch(function(err) {
* console.error(err);
* });
*
* // Or obtain the paged response.
* var options = {autoPaginate: false};
* function callback(responses) {
* // The actual resources in a response.
* var resources = responses[0];
* // The next request if the response shows there's more responses.
* var nextRequest = responses[1];
* // The actual response object, if necessary.
* // var rawResponse = responses[2];
* for (var i = 0; i < resources.length; ++i) {
* // doThingsWith(resources[i]);
* }
* if (nextRequest) {
* // Fetch the next page.
* return client.listLogMetrics(nextRequest, options).then(callback);
* }
* }
* client.listLogMetrics({parent: formattedParent}, options)
* .then(callback)
* .catch(function(err) {
* console.error(err);
* });
*/
MetricsServiceV2Client.prototype.listLogMetrics = function(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
if (options === undefined) {
options = {};
}
return this._listLogMetrics(request, options, callback);
};
/**
* Equivalent to {@link listLogMetrics}, but returns a NodeJS Stream object.
*
* This fetches the paged responses for {@link listLogMetrics} continuously
* and invokes the callback registered for 'data' event for each element in the
* responses.
*
* The returned object has 'end' method when no more elements are required.
*
* autoPaginate option will be ignored.
*
* @see {@link https://nodejs.org/api/stream.html}
*
* @param {Object} request
* The request object that will be sent.
* @param {string} request.parent
* Required. The name of the project containing the metrics:
*
* "projects/[PROJECT_ID]"
* @param {number=} request.pageSize
* The maximum number of resources contained in the underlying API
* response. If page streaming is performed per-resource, this
* parameter does not affect the return value. If page streaming is
* performed per-page, this determines the maximum number of
* resources in a page.
* @param {Object=} options
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
* @return {Stream}
* An object stream which emits an object representing [LogMetric]{@link LogMetric} on 'data' event.
*
* @example
*
* var client = loggingV2.metricsServiceV2Client();
* var formattedParent = client.projectPath("[PROJECT]");
* client.listLogMetricsStream({parent: formattedParent}).on('data', function(element) {
* // doThingsWith(element)
* }).on('error', function(err) {
* console.error(err);
* });
*/
MetricsServiceV2Client.prototype.listLogMetricsStream = function(request, options) {
if (options === undefined) {
options = {};
}
return PAGE_DESCRIPTORS.listLogMetrics.createStream(this._listLogMetrics, request, options);
};
/**
* Gets a logs-based metric.
*
* @param {Object} request
* The request object that will be sent.
* @param {string} request.metricName
* The resource name of the desired metric:
*
* "projects/[PROJECT_ID]/metrics/[METRIC_ID]"
* @param {Object=} options
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
* @param {function(?Error, ?Object)=} callback
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [LogMetric]{@link LogMetric}.
* @return {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [LogMetric]{@link LogMetric}.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* var client = loggingV2.metricsServiceV2Client();
* var formattedMetricName = client.metricPath("[PROJECT]", "[METRIC]");
* client.getLogMetric({metricName: formattedMetricName}).then(function(responses) {
* var response = responses[0];
* // doThingsWith(response)
* }).catch(function(err) {
* console.error(err);
* });
*/
MetricsServiceV2Client.prototype.getLogMetric = function(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
if (options === undefined) {
options = {};
}
return this._getLogMetric(request, options, callback);
};
/**
* Creates a logs-based metric.
*
* @param {Object} request
* The request object that will be sent.
* @param {string} request.parent
* The resource name of the project in which to create the metric:
*
* "projects/[PROJECT_ID]"
*
* The new metric must be provided in the request.
* @param {Object} request.metric
* The new logs-based metric, which must not have an identifier that
* already exists.
*
* This object should have the same structure as [LogMetric]{@link LogMetric}
* @param {Object=} options
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
* @param {function(?Error, ?Object)=} callback
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [LogMetric]{@link LogMetric}.
* @return {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [LogMetric]{@link LogMetric}.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* var client = loggingV2.metricsServiceV2Client();
* var formattedParent = client.projectPath("[PROJECT]");
* var metric = {};
* var request = {
* parent: formattedParent,
* metric: metric
* };
* client.createLogMetric(request).then(function(responses) {
* var response = responses[0];
* // doThingsWith(response)
* }).catch(function(err) {
* console.error(err);
* });
*/
MetricsServiceV2Client.prototype.createLogMetric = function(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
if (options === undefined) {
options = {};
}
return this._createLogMetric(request, options, callback);
};
/**
* Creates or updates a logs-based metric.
*
* @param {Object} request
* The request object that will be sent.
* @param {string} request.metricName
* The resource name of the metric to update:
*
* "projects/[PROJECT_ID]/metrics/[METRIC_ID]"
*
* The updated metric must be provided in the request and it's
* `name` field must be the same as `[METRIC_ID]` If the metric
* does not exist in `[PROJECT_ID]`, then a new metric is created.
* @param {Object} request.metric
* The updated metric.
*
* This object should have the same structure as [LogMetric]{@link LogMetric}
* @param {Object=} options
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
* @param {function(?Error, ?Object)=} callback
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [LogMetric]{@link LogMetric}.
* @return {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [LogMetric]{@link LogMetric}.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* var client = loggingV2.metricsServiceV2Client();
* var formattedMetricName = client.metricPath("[PROJECT]", "[METRIC]");
* var metric = {};
* var request = {
* metricName: formattedMetricName,
* metric: metric
* };
* client.updateLogMetric(request).then(function(responses) {
* var response = responses[0];
* // doThingsWith(response)
* }).catch(function(err) {
* console.error(err);
* });
*/
MetricsServiceV2Client.prototype.updateLogMetric = function(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
if (options === undefined) {
options = {};
}
return this._updateLogMetric(request, options, callback);
};
/**
* Deletes a logs-based metric.
*
* @param {Object} request
* The request object that will be sent.
* @param {string} request.metricName
* The resource name of the metric to delete:
*
* "projects/[PROJECT_ID]/metrics/[METRIC_ID]"
* @param {Object=} options
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
* @param {function(?Error)=} callback
* The function which will be called with the result of the API call.
* @return {Promise} - The promise which resolves when API call finishes.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* var client = loggingV2.metricsServiceV2Client();
* var formattedMetricName = client.metricPath("[PROJECT]", "[METRIC]");
* client.deleteLogMetric({metricName: formattedMetricName}).catch(function(err) {
* console.error(err);
* });
*/
MetricsServiceV2Client.prototype.deleteLogMetric = function(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
if (options === undefined) {
options = {};
}
return this._deleteLogMetric(request, options, callback);
};
function MetricsServiceV2ClientBuilder(gaxGrpc) {
if (!(this instanceof MetricsServiceV2ClientBuilder)) {
return new MetricsServiceV2ClientBuilder(gaxGrpc);
}
var metricsServiceV2Client = gaxGrpc.load([{
root: require('google-proto-files')('..'),
file: 'google/logging/v2/logging_metrics.proto'
}]);
extend(this, metricsServiceV2Client.google.logging.v2);
/**
* Build a new instance of {@link MetricsServiceV2Client}.
*
* @param {Object=} opts - The optional parameters.
* @param {String=} opts.servicePath
* The domain name of the API remote host.
* @param {number=} opts.port
* The port on which to connect to the remote host.
* @param {grpc.ClientCredentials=} opts.sslCreds
* A ClientCredentials for use with an SSL-enabled channel.
* @param {Object=} opts.clientConfig
* The customized config to build the call settings. See
* {@link gax.constructSettings} for the format.
*/
this.metricsServiceV2Client = function(opts) {
return new MetricsServiceV2Client(gaxGrpc, metricsServiceV2Client, opts);
};
extend(this.metricsServiceV2Client, MetricsServiceV2Client);
}
module.exports = MetricsServiceV2ClientBuilder;
module.exports.SERVICE_ADDRESS = SERVICE_ADDRESS;
module.exports.ALL_SCOPES = ALL_SCOPES;