From fbfacf4531ca804d6612774c41894adddc0835cb Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Fri, 21 Oct 2016 12:37:18 -0400 Subject: [PATCH] monitoring: update gapic layer --- packages/monitoring/package.json | 2 +- .../monitoring/src/v3/group_service_api.js | 242 +++++--------- .../monitoring/src/v3/metric_service_api.js | 307 +++++++----------- 3 files changed, 204 insertions(+), 347 deletions(-) diff --git a/packages/monitoring/package.json b/packages/monitoring/package.json index 9721bc0d9c4..f559affb517 100644 --- a/packages/monitoring/package.json +++ b/packages/monitoring/package.json @@ -52,7 +52,7 @@ "stackdriver" ], "dependencies": { - "google-gax": "^0.7.0", + "google-gax": "^0.8.1", "google-proto-files": "^0.8.3", "extend": "^3.0.0" }, diff --git a/packages/monitoring/src/v3/group_service_api.js b/packages/monitoring/src/v3/group_service_api.js index 6951426d977..19e0fb5722b 100644 --- a/packages/monitoring/src/v3/group_service_api.js +++ b/packages/monitoring/src/v3/group_service_api.js @@ -194,54 +194,53 @@ GroupServiceApi.prototype.matchGroupFromGroupName = function(groupName) { /** * Lists the existing groups. * - * @param {string} name + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name * The project whose groups are to be listed. The format is * `"projects/{project_id_or_number}"`. - * @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. - * - * In addition, options may contain the following optional parameters. - * @param {string=} options.childrenOfGroup + * @param {string=} request.childrenOfGroup * A group name: `"projects/{project_id_or_number}/groups/{group_id}"`. * Returns groups whose `parentName` field contains the group * name. If no groups have this parent, the results are empty. - * @param {string=} options.ancestorsOfGroup + * @param {string=} request.ancestorsOfGroup * A group name: `"projects/{project_id_or_number}/groups/{group_id}"`. * Returns groups that are ancestors of the specified group. * The groups are returned in order, starting with the immediate parent and * ending with the most distant ancestor. If the specified group has no * immediate parent, the results are empty. - * @param {string=} options.descendantsOfGroup + * @param {string=} request.descendantsOfGroup * A group name: `"projects/{project_id_or_number}/groups/{group_id}"`. * Returns the descendants of the specified group. This is a superset of * the results returned by the `childrenOfGroup` filter, and includes * children-of-children, and so forth. - * @param {number=} options.pageSize + * @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, ?Object, ?string)=} callback * When specified, the results are not streamed but this callback * will be called with the response object representing [ListGroupsResponse]{@link ListGroupsResponse}. * The third item will be set if the response contains the token for the further results * and can be reused to `pageToken` field in the options in the next request. - * @returns {Stream|gax.EventEmitter} + * @returns {Stream|Promise} * An object stream which emits an object representing * [Group]{@link Group} on 'data' event. * When the callback is specified or streaming is suppressed through options, - * it will return an event emitter to handle the call status and the callback - * will be called with the response object. + * it will return a promise that resolves to the response object. The promise + * has a method named "cancel" which cancels the ongoing API call. * * @example * * var api = monitoringV3.groupServiceApi(); * var formattedName = api.projectPath("[PROJECT]"); * // Iterate over all elements. - * api.listGroups(formattedName).on('data', function(element) { + * api.listGroups({name: formattedName}).on('data', function(element) { * // doThingsWith(element) * }); * @@ -254,15 +253,12 @@ GroupServiceApi.prototype.matchGroupFromGroupName = function(groupName) { * // doThingsWith(response) * if (nextPageToken) { * // fetch the next page. - * api.listGroups(formattedName, {pageToken: nextPageToken}, callback); + * api.listGroups({name: formattedName}, {pageToken: nextPageToken}, callback); * } * } - * api.listGroups(formattedName, {flattenPages: false}, callback); + * api.listGroups({name: formattedName}, {flattenPages: false}, callback); */ -GroupServiceApi.prototype.listGroups = function( - name, - options, - callback) { +GroupServiceApi.prototype.listGroups = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -270,28 +266,15 @@ GroupServiceApi.prototype.listGroups = function( if (options === undefined) { options = {}; } - var req = { - name: name - }; - if ('childrenOfGroup' in options) { - req.childrenOfGroup = options.childrenOfGroup; - } - if ('ancestorsOfGroup' in options) { - req.ancestorsOfGroup = options.ancestorsOfGroup; - } - if ('descendantsOfGroup' in options) { - req.descendantsOfGroup = options.descendantsOfGroup; - } - if ('pageSize' in options) { - req.pageSize = options.pageSize; - } - return this._listGroups(req, options, callback); + return this._listGroups(request, options, callback); }; /** * Gets a single group. * - * @param {string} name + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name * The group to retrieve. The format is * `"projects/{project_id_or_number}/groups/{group_id}"`. * @param {Object=} options @@ -301,25 +284,20 @@ GroupServiceApi.prototype.listGroups = function( * The function which will be called with the result of the API call. * * The second parameter to the callback is an object representing [Group]{@link Group} - * @returns {gax.EventEmitter} - the event emitter to handle the call - * status. + * @returns {Promise} - The promise which resolves to the response object. + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * * var api = monitoringV3.groupServiceApi(); * var formattedName = api.groupPath("[PROJECT]", "[GROUP]"); - * api.getGroup(formattedName, function(err, response) { - * if (err) { - * console.error(err); - * return; - * } + * api.getGroup({name: formattedName}).then(function(response) { * // doThingsWith(response) + * }).catch(function(err) { + * console.error(err); * }); */ -GroupServiceApi.prototype.getGroup = function( - name, - options, - callback) { +GroupServiceApi.prototype.getGroup = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -327,56 +305,50 @@ GroupServiceApi.prototype.getGroup = function( if (options === undefined) { options = {}; } - var req = { - name: name - }; - return this._getGroup(req, options, callback); + return this._getGroup(request, options, callback); }; /** * Creates a new group. * - * @param {string} name + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name * The project in which to create the group. The format is * `"projects/{project_id_or_number}"`. - * @param {Object} group + * @param {Object} request.group * A group definition. It is an error to define the `name` field because * the system assigns the name. * * This object should have the same structure as [Group]{@link Group} + * @param {boolean=} request.validateOnly + * If true, validate this request but do not create the group. * @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. - * - * In addition, options may contain the following optional parameters. - * @param {boolean=} options.validateOnly - * If true, validate this request but do not create the group. - * * @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 [Group]{@link Group} - * @returns {gax.EventEmitter} - the event emitter to handle the call - * status. + * @returns {Promise} - The promise which resolves to the response object. + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * * var api = monitoringV3.groupServiceApi(); * var formattedName = api.projectPath("[PROJECT]"); * var group = {}; - * api.createGroup(formattedName, group, function(err, response) { - * if (err) { - * console.error(err); - * return; - * } + * var request = { + * name: formattedName, + * group: group + * }; + * api.createGroup(request).then(function(response) { * // doThingsWith(response) + * }).catch(function(err) { + * console.error(err); * }); */ -GroupServiceApi.prototype.createGroup = function( - name, - group, - options, - callback) { +GroupServiceApi.prototype.createGroup = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -384,56 +356,43 @@ GroupServiceApi.prototype.createGroup = function( if (options === undefined) { options = {}; } - var req = { - name: name, - group: group - }; - if ('validateOnly' in options) { - req.validateOnly = options.validateOnly; - } - return this._createGroup(req, options, callback); + return this._createGroup(request, options, callback); }; /** * Updates an existing group. * You can change any group attributes except `name`. * - * @param {Object} group + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.group * The new definition of the group. All fields of the existing group, * excepting `name`, are replaced with the corresponding fields of this group. * * This object should have the same structure as [Group]{@link Group} + * @param {boolean=} request.validateOnly + * If true, validate this request but do not update the existing group. * @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. - * - * In addition, options may contain the following optional parameters. - * @param {boolean=} options.validateOnly - * If true, validate this request but do not update the existing group. - * * @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 [Group]{@link Group} - * @returns {gax.EventEmitter} - the event emitter to handle the call - * status. + * @returns {Promise} - The promise which resolves to the response object. + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * * var api = monitoringV3.groupServiceApi(); * var group = {}; - * api.updateGroup(group, function(err, response) { - * if (err) { - * console.error(err); - * return; - * } + * api.updateGroup({group: group}).then(function(response) { * // doThingsWith(response) + * }).catch(function(err) { + * console.error(err); * }); */ -GroupServiceApi.prototype.updateGroup = function( - group, - options, - callback) { +GroupServiceApi.prototype.updateGroup = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -441,19 +400,15 @@ GroupServiceApi.prototype.updateGroup = function( if (options === undefined) { options = {}; } - var req = { - group: group - }; - if ('validateOnly' in options) { - req.validateOnly = options.validateOnly; - } - return this._updateGroup(req, options, callback); + return this._updateGroup(request, options, callback); }; /** * Deletes an existing group. * - * @param {string} name + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name * The group to delete. The format is * `"projects/{project_id_or_number}/groups/{group_id}"`. * @param {Object=} options @@ -461,23 +416,18 @@ GroupServiceApi.prototype.updateGroup = function( * 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. - * @returns {gax.EventEmitter} - the event emitter to handle the call - * status. + * @returns {Promise} - The promise which resolves to the response object. + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * * var api = monitoringV3.groupServiceApi(); * var formattedName = api.groupPath("[PROJECT]", "[GROUP]"); - * api.deleteGroup(formattedName, function(err) { - * if (err) { - * console.error(err); - * } + * api.deleteGroup({name: formattedName}).catch(function(err) { + * console.error(err); * }); */ -GroupServiceApi.prototype.deleteGroup = function( - name, - options, - callback) { +GroupServiceApi.prototype.deleteGroup = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -485,30 +435,24 @@ GroupServiceApi.prototype.deleteGroup = function( if (options === undefined) { options = {}; } - var req = { - name: name - }; - return this._deleteGroup(req, options, callback); + return this._deleteGroup(request, options, callback); }; /** * Lists the monitored resources that are members of a group. * - * @param {string} name + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name * The group whose members are listed. The format is * `"projects/{project_id_or_number}/groups/{group_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. - * - * In addition, options may contain the following optional parameters. - * @param {number=} options.pageSize + * @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 {string=} options.filter + * @param {string=} request.filter * An optional [list filter](https://cloud.google.com/monitoring/api/learn_more#filtering) describing * the members to be returned. The filter may reference the type, labels, and * metadata of monitored resources that comprise the group. @@ -516,32 +460,34 @@ GroupServiceApi.prototype.deleteGroup = function( * instances, use this filter: * * resource.type = "gce_instance" - * @param {Object=} options.interval + * @param {Object=} request.interval * An optional time interval for which results should be returned. Only * members that were part of the group during the specified interval are * included in the response. If no interval is provided then the group * membership over the last minute is returned. * * This object should have the same structure as [TimeInterval]{@link TimeInterval} - * + * @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, ?string)=} callback * When specified, the results are not streamed but this callback * will be called with the response object representing [ListGroupMembersResponse]{@link ListGroupMembersResponse}. * The third item will be set if the response contains the token for the further results * and can be reused to `pageToken` field in the options in the next request. - * @returns {Stream|gax.EventEmitter} + * @returns {Stream|Promise} * An object stream which emits an object representing * [google.api.MonitoredResource]{@link external:"google.api.MonitoredResource"} on 'data' event. * When the callback is specified or streaming is suppressed through options, - * it will return an event emitter to handle the call status and the callback - * will be called with the response object. + * it will return a promise that resolves to the response object. The promise + * has a method named "cancel" which cancels the ongoing API call. * * @example * * var api = monitoringV3.groupServiceApi(); * var formattedName = api.groupPath("[PROJECT]", "[GROUP]"); * // Iterate over all elements. - * api.listGroupMembers(formattedName).on('data', function(element) { + * api.listGroupMembers({name: formattedName}).on('data', function(element) { * // doThingsWith(element) * }); * @@ -554,15 +500,12 @@ GroupServiceApi.prototype.deleteGroup = function( * // doThingsWith(response) * if (nextPageToken) { * // fetch the next page. - * api.listGroupMembers(formattedName, {pageToken: nextPageToken}, callback); + * api.listGroupMembers({name: formattedName}, {pageToken: nextPageToken}, callback); * } * } - * api.listGroupMembers(formattedName, {flattenPages: false}, callback); + * api.listGroupMembers({name: formattedName}, {flattenPages: false}, callback); */ -GroupServiceApi.prototype.listGroupMembers = function( - name, - options, - callback) { +GroupServiceApi.prototype.listGroupMembers = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -570,19 +513,7 @@ GroupServiceApi.prototype.listGroupMembers = function( if (options === undefined) { options = {}; } - var req = { - name: name - }; - if ('pageSize' in options) { - req.pageSize = options.pageSize; - } - if ('filter' in options) { - req.filter = options.filter; - } - if ('interval' in options) { - req.interval = options.interval; - } - return this._listGroupMembers(req, options, callback); + return this._listGroupMembers(request, options, callback); }; function GroupServiceApiBuilder(gaxGrpc) { @@ -590,10 +521,7 @@ function GroupServiceApiBuilder(gaxGrpc) { return new GroupServiceApiBuilder(gaxGrpc); } - var groupServiceClient = gaxGrpc.load([{ - root: require('google-proto-files')('..'), - file: 'google/monitoring/v3/group_service.proto' - }]); + var groupServiceClient = require('grpc-google-monitoring-v3').client; extend(this, groupServiceClient.google.monitoring.v3); var grpcClients = { @@ -625,4 +553,4 @@ function GroupServiceApiBuilder(gaxGrpc) { } module.exports = GroupServiceApiBuilder; module.exports.SERVICE_ADDRESS = SERVICE_ADDRESS; -module.exports.ALL_SCOPES = ALL_SCOPES; \ No newline at end of file +module.exports.ALL_SCOPES = ALL_SCOPES; diff --git a/packages/monitoring/src/v3/metric_service_api.js b/packages/monitoring/src/v3/metric_service_api.js index cc97a623f6f..7b9300e4eaa 100644 --- a/packages/monitoring/src/v3/metric_service_api.js +++ b/packages/monitoring/src/v3/metric_service_api.js @@ -226,15 +226,12 @@ MetricServiceApi.prototype.matchMonitoredResourceDescriptorFromMonitoredResource /** * Lists monitored resource descriptors that match a filter. This method does not require a Stackdriver account. * - * @param {string} name + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name * The project on which to execute the request. The format is * `"projects/{project_id_or_number}"`. - * @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. - * - * In addition, options may contain the following optional parameters. - * @param {string=} options.filter + * @param {string=} request.filter * An optional [filter](https://cloud.google.com/monitoring/api/v3/filters) describing * the descriptors to be returned. The filter can reference * the descriptor's type and labels. For example, the @@ -242,31 +239,33 @@ MetricServiceApi.prototype.matchMonitoredResourceDescriptorFromMonitoredResource * that have an `id` label: * * resource.type = starts_with("gce_") AND resource.label:id - * @param {number=} options.pageSize + * @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, ?Object, ?string)=} callback * When specified, the results are not streamed but this callback * will be called with the response object representing [ListMonitoredResourceDescriptorsResponse]{@link ListMonitoredResourceDescriptorsResponse}. * The third item will be set if the response contains the token for the further results * and can be reused to `pageToken` field in the options in the next request. - * @returns {Stream|gax.EventEmitter} + * @returns {Stream|Promise} * An object stream which emits an object representing * [google.api.MonitoredResourceDescriptor]{@link external:"google.api.MonitoredResourceDescriptor"} on 'data' event. * When the callback is specified or streaming is suppressed through options, - * it will return an event emitter to handle the call status and the callback - * will be called with the response object. + * it will return a promise that resolves to the response object. The promise + * has a method named "cancel" which cancels the ongoing API call. * * @example * * var api = monitoringV3.metricServiceApi(); * var formattedName = api.projectPath("[PROJECT]"); * // Iterate over all elements. - * api.listMonitoredResourceDescriptors(formattedName).on('data', function(element) { + * api.listMonitoredResourceDescriptors({name: formattedName}).on('data', function(element) { * // doThingsWith(element) * }); * @@ -279,15 +278,12 @@ MetricServiceApi.prototype.matchMonitoredResourceDescriptorFromMonitoredResource * // doThingsWith(response) * if (nextPageToken) { * // fetch the next page. - * api.listMonitoredResourceDescriptors(formattedName, {pageToken: nextPageToken}, callback); + * api.listMonitoredResourceDescriptors({name: formattedName}, {pageToken: nextPageToken}, callback); * } * } - * api.listMonitoredResourceDescriptors(formattedName, {flattenPages: false}, callback); + * api.listMonitoredResourceDescriptors({name: formattedName}, {flattenPages: false}, callback); */ -MetricServiceApi.prototype.listMonitoredResourceDescriptors = function( - name, - options, - callback) { +MetricServiceApi.prototype.listMonitoredResourceDescriptors = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -295,22 +291,15 @@ MetricServiceApi.prototype.listMonitoredResourceDescriptors = function( if (options === undefined) { options = {}; } - var req = { - name: name - }; - if ('filter' in options) { - req.filter = options.filter; - } - if ('pageSize' in options) { - req.pageSize = options.pageSize; - } - return this._listMonitoredResourceDescriptors(req, options, callback); + return this._listMonitoredResourceDescriptors(request, options, callback); }; /** * Gets a single monitored resource descriptor. This method does not require a Stackdriver account. * - * @param {string} name + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name * The monitored resource descriptor to get. The format is * `"projects/{project_id_or_number}/monitoredResourceDescriptors/{resource_type}"`. * The `{resource_type}` is a predefined type, such as @@ -322,25 +311,20 @@ MetricServiceApi.prototype.listMonitoredResourceDescriptors = function( * The function which will be called with the result of the API call. * * The second parameter to the callback is an object representing [google.api.MonitoredResourceDescriptor]{@link external:"google.api.MonitoredResourceDescriptor"} - * @returns {gax.EventEmitter} - the event emitter to handle the call - * status. + * @returns {Promise} - The promise which resolves to the response object. + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * * var api = monitoringV3.metricServiceApi(); * var formattedName = api.monitoredResourceDescriptorPath("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]"); - * api.getMonitoredResourceDescriptor(formattedName, function(err, response) { - * if (err) { - * console.error(err); - * return; - * } + * api.getMonitoredResourceDescriptor({name: formattedName}).then(function(response) { * // doThingsWith(response) + * }).catch(function(err) { + * console.error(err); * }); */ -MetricServiceApi.prototype.getMonitoredResourceDescriptor = function( - name, - options, - callback) { +MetricServiceApi.prototype.getMonitoredResourceDescriptor = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -348,24 +332,18 @@ MetricServiceApi.prototype.getMonitoredResourceDescriptor = function( if (options === undefined) { options = {}; } - var req = { - name: name - }; - return this._getMonitoredResourceDescriptor(req, options, callback); + return this._getMonitoredResourceDescriptor(request, options, callback); }; /** * Lists metric descriptors that match a filter. This method does not require a Stackdriver account. * - * @param {string} name + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name * The project on which to execute the request. The format is * `"projects/{project_id_or_number}"`. - * @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. - * - * In addition, options may contain the following optional parameters. - * @param {string=} options.filter + * @param {string=} request.filter * If this field is empty, all custom and * system-defined metric descriptors are returned. * Otherwise, the [filter](https://cloud.google.com/monitoring/api/v3/filters) @@ -374,31 +352,33 @@ MetricServiceApi.prototype.getMonitoredResourceDescriptor = function( * [custom metrics](https://cloud.google.com/monitoring/custom-metrics): * * metric.type = starts_with("custom.googleapis.com/") - * @param {number=} options.pageSize + * @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, ?Object, ?string)=} callback * When specified, the results are not streamed but this callback * will be called with the response object representing [ListMetricDescriptorsResponse]{@link ListMetricDescriptorsResponse}. * The third item will be set if the response contains the token for the further results * and can be reused to `pageToken` field in the options in the next request. - * @returns {Stream|gax.EventEmitter} + * @returns {Stream|Promise} * An object stream which emits an object representing * [google.api.MetricDescriptor]{@link external:"google.api.MetricDescriptor"} on 'data' event. * When the callback is specified or streaming is suppressed through options, - * it will return an event emitter to handle the call status and the callback - * will be called with the response object. + * it will return a promise that resolves to the response object. The promise + * has a method named "cancel" which cancels the ongoing API call. * * @example * * var api = monitoringV3.metricServiceApi(); * var formattedName = api.projectPath("[PROJECT]"); * // Iterate over all elements. - * api.listMetricDescriptors(formattedName).on('data', function(element) { + * api.listMetricDescriptors({name: formattedName}).on('data', function(element) { * // doThingsWith(element) * }); * @@ -411,15 +391,12 @@ MetricServiceApi.prototype.getMonitoredResourceDescriptor = function( * // doThingsWith(response) * if (nextPageToken) { * // fetch the next page. - * api.listMetricDescriptors(formattedName, {pageToken: nextPageToken}, callback); + * api.listMetricDescriptors({name: formattedName}, {pageToken: nextPageToken}, callback); * } * } - * api.listMetricDescriptors(formattedName, {flattenPages: false}, callback); + * api.listMetricDescriptors({name: formattedName}, {flattenPages: false}, callback); */ -MetricServiceApi.prototype.listMetricDescriptors = function( - name, - options, - callback) { +MetricServiceApi.prototype.listMetricDescriptors = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -427,22 +404,15 @@ MetricServiceApi.prototype.listMetricDescriptors = function( if (options === undefined) { options = {}; } - var req = { - name: name - }; - if ('filter' in options) { - req.filter = options.filter; - } - if ('pageSize' in options) { - req.pageSize = options.pageSize; - } - return this._listMetricDescriptors(req, options, callback); + return this._listMetricDescriptors(request, options, callback); }; /** * Gets a single metric descriptor. This method does not require a Stackdriver account. * - * @param {string} name + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name * The metric descriptor on which to execute the request. The format is * `"projects/{project_id_or_number}/metricDescriptors/{metric_id}"`. * An example value of `{metric_id}` is @@ -454,25 +424,20 @@ MetricServiceApi.prototype.listMetricDescriptors = function( * The function which will be called with the result of the API call. * * The second parameter to the callback is an object representing [google.api.MetricDescriptor]{@link external:"google.api.MetricDescriptor"} - * @returns {gax.EventEmitter} - the event emitter to handle the call - * status. + * @returns {Promise} - The promise which resolves to the response object. + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * * var api = monitoringV3.metricServiceApi(); * var formattedName = api.metricDescriptorPath("[PROJECT]", "[METRIC_DESCRIPTOR]"); - * api.getMetricDescriptor(formattedName, function(err, response) { - * if (err) { - * console.error(err); - * return; - * } + * api.getMetricDescriptor({name: formattedName}).then(function(response) { * // doThingsWith(response) + * }).catch(function(err) { + * console.error(err); * }); */ -MetricServiceApi.prototype.getMetricDescriptor = function( - name, - options, - callback) { +MetricServiceApi.prototype.getMetricDescriptor = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -480,10 +445,7 @@ MetricServiceApi.prototype.getMetricDescriptor = function( if (options === undefined) { options = {}; } - var req = { - name: name - }; - return this._getMetricDescriptor(req, options, callback); + return this._getMetricDescriptor(request, options, callback); }; /** @@ -491,10 +453,12 @@ MetricServiceApi.prototype.getMetricDescriptor = function( * User-created metric descriptors define * [custom metrics](https://cloud.google.com/monitoring/custom-metrics). * - * @param {string} name + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name * The project on which to execute the request. The format is * `"projects/{project_id_or_number}"`. - * @param {Object} metricDescriptor + * @param {Object} request.metricDescriptor * The new [custom metric](https://cloud.google.com/monitoring/custom-metrics) * descriptor. * @@ -506,27 +470,25 @@ MetricServiceApi.prototype.getMetricDescriptor = function( * The function which will be called with the result of the API call. * * The second parameter to the callback is an object representing [google.api.MetricDescriptor]{@link external:"google.api.MetricDescriptor"} - * @returns {gax.EventEmitter} - the event emitter to handle the call - * status. + * @returns {Promise} - The promise which resolves to the response object. + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * * var api = monitoringV3.metricServiceApi(); * var formattedName = api.projectPath("[PROJECT]"); * var metricDescriptor = {}; - * api.createMetricDescriptor(formattedName, metricDescriptor, function(err, response) { - * if (err) { - * console.error(err); - * return; - * } + * var request = { + * name: formattedName, + * metricDescriptor: metricDescriptor + * }; + * api.createMetricDescriptor(request).then(function(response) { * // doThingsWith(response) + * }).catch(function(err) { + * console.error(err); * }); */ -MetricServiceApi.prototype.createMetricDescriptor = function( - name, - metricDescriptor, - options, - callback) { +MetricServiceApi.prototype.createMetricDescriptor = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -534,18 +496,16 @@ MetricServiceApi.prototype.createMetricDescriptor = function( if (options === undefined) { options = {}; } - var req = { - name: name, - metricDescriptor: metricDescriptor - }; - return this._createMetricDescriptor(req, options, callback); + return this._createMetricDescriptor(request, options, callback); }; /** * Deletes a metric descriptor. Only user-created * [custom metrics](https://cloud.google.com/monitoring/custom-metrics) can be deleted. * - * @param {string} name + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name * The metric descriptor on which to execute the request. The format is * `"projects/{project_id_or_number}/metricDescriptors/{metric_id}"`. * An example of `{metric_id}` is: @@ -555,23 +515,18 @@ MetricServiceApi.prototype.createMetricDescriptor = function( * 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. - * @returns {gax.EventEmitter} - the event emitter to handle the call - * status. + * @returns {Promise} - The promise which resolves to the response object. + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * * var api = monitoringV3.metricServiceApi(); * var formattedName = api.metricDescriptorPath("[PROJECT]", "[METRIC_DESCRIPTOR]"); - * api.deleteMetricDescriptor(formattedName, function(err) { - * if (err) { - * console.error(err); - * } + * api.deleteMetricDescriptor({name: formattedName}).catch(function(err) { + * console.error(err); * }); */ -MetricServiceApi.prototype.deleteMetricDescriptor = function( - name, - options, - callback) { +MetricServiceApi.prototype.deleteMetricDescriptor = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -579,19 +534,18 @@ MetricServiceApi.prototype.deleteMetricDescriptor = function( if (options === undefined) { options = {}; } - var req = { - name: name - }; - return this._deleteMetricDescriptor(req, options, callback); + return this._deleteMetricDescriptor(request, options, callback); }; /** * Lists time series that match a filter. This method does not require a Stackdriver account. * - * @param {string} name + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name * The project on which to execute the request. The format is * "projects/{project_id_or_number}". - * @param {string} filter + * @param {string} request.filter * A [monitoring filter](https://cloud.google.com/monitoring/api/v3/filters) that specifies which time * series should be returned. The filter must specify a single metric type, * and can additionally specify metric labels and other information. For @@ -599,49 +553,46 @@ MetricServiceApi.prototype.deleteMetricDescriptor = function( * * metric.type = "compute.googleapis.com/instance/cpu/usage_time" AND * metric.label.instance_name = "my-instance-name" - * @param {Object} interval + * @param {Object} request.interval * The time interval for which results should be returned. Only time series * that contain data points in the specified interval are included * in the response. * * This object should have the same structure as [TimeInterval]{@link TimeInterval} - * @param {number} view + * @param {number} request.view * Specifies which information is returned about the time series. * * The number should be among the values of [TimeSeriesView]{@link TimeSeriesView} - * @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. - * - * In addition, options may contain the following optional parameters. - * @param {Object=} options.aggregation + * @param {Object=} request.aggregation * By default, the raw time series data is returned. * Use this field to combine multiple time series for different * views of the data. * * This object should have the same structure as [Aggregation]{@link Aggregation} - * @param {string=} options.orderBy + * @param {string=} request.orderBy * Specifies the order in which the points of the time series should * be returned. By default, results are not ordered. Currently, * this field must be left blank. - * @param {number=} options.pageSize + * @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, ?Object, ?string)=} callback * When specified, the results are not streamed but this callback * will be called with the response object representing [ListTimeSeriesResponse]{@link ListTimeSeriesResponse}. * The third item will be set if the response contains the token for the further results * and can be reused to `pageToken` field in the options in the next request. - * @returns {Stream|gax.EventEmitter} + * @returns {Stream|Promise} * An object stream which emits an object representing * [TimeSeries]{@link TimeSeries} on 'data' event. * When the callback is specified or streaming is suppressed through options, - * it will return an event emitter to handle the call status and the callback - * will be called with the response object. + * it will return a promise that resolves to the response object. The promise + * has a method named "cancel" which cancels the ongoing API call. * * @example * @@ -650,8 +601,14 @@ MetricServiceApi.prototype.deleteMetricDescriptor = function( * var filter = ''; * var interval = {}; * var view = TimeSeriesView.FULL; + * var request = { + * name: formattedName, + * filter: filter, + * interval: interval, + * view: view + * }; * // Iterate over all elements. - * api.listTimeSeries(formattedName, filter, interval, view).on('data', function(element) { + * api.listTimeSeries(request).on('data', function(element) { * // doThingsWith(element) * }); * @@ -664,18 +621,12 @@ MetricServiceApi.prototype.deleteMetricDescriptor = function( * // doThingsWith(response) * if (nextPageToken) { * // fetch the next page. - * api.listTimeSeries(formattedName, filter, interval, view, {pageToken: nextPageToken}, callback); + * api.listTimeSeries(request, {pageToken: nextPageToken}, callback); * } * } - * api.listTimeSeries(formattedName, filter, interval, view, {flattenPages: false}, callback); + * api.listTimeSeries(request, {flattenPages: false}, callback); */ -MetricServiceApi.prototype.listTimeSeries = function( - name, - filter, - interval, - view, - options, - callback) { +MetricServiceApi.prototype.listTimeSeries = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -683,22 +634,7 @@ MetricServiceApi.prototype.listTimeSeries = function( if (options === undefined) { options = {}; } - var req = { - name: name, - filter: filter, - interval: interval, - view: view - }; - if ('aggregation' in options) { - req.aggregation = options.aggregation; - } - if ('orderBy' in options) { - req.orderBy = options.orderBy; - } - if ('pageSize' in options) { - req.pageSize = options.pageSize; - } - return this._listTimeSeries(req, options, callback); + return this._listTimeSeries(request, options, callback); }; /** @@ -707,10 +643,12 @@ MetricServiceApi.prototype.listTimeSeries = function( * If any time series could not be written, a corresponding failure message is * included in the error response. * - * @param {string} name + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name * The project on which to execute the request. The format is * `"projects/{project_id_or_number}"`. - * @param {Object[]} timeSeries + * @param {Object[]} request.timeSeries * The new data to be added to a list of time series. * Adds at most one data point to each of several time series. The new data * point must be more recent than any other point in its time series. Each @@ -723,25 +661,23 @@ MetricServiceApi.prototype.listTimeSeries = function( * 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. - * @returns {gax.EventEmitter} - the event emitter to handle the call - * status. + * @returns {Promise} - The promise which resolves to the response object. + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * * var api = monitoringV3.metricServiceApi(); * var formattedName = api.projectPath("[PROJECT]"); * var timeSeries = []; - * api.createTimeSeries(formattedName, timeSeries, function(err) { - * if (err) { - * console.error(err); - * } + * var request = { + * name: formattedName, + * timeSeries: timeSeries + * }; + * api.createTimeSeries(request).catch(function(err) { + * console.error(err); * }); */ -MetricServiceApi.prototype.createTimeSeries = function( - name, - timeSeries, - options, - callback) { +MetricServiceApi.prototype.createTimeSeries = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -749,11 +685,7 @@ MetricServiceApi.prototype.createTimeSeries = function( if (options === undefined) { options = {}; } - var req = { - name: name, - timeSeries: timeSeries - }; - return this._createTimeSeries(req, options, callback); + return this._createTimeSeries(request, options, callback); }; function MetricServiceApiBuilder(gaxGrpc) { @@ -761,10 +693,7 @@ function MetricServiceApiBuilder(gaxGrpc) { return new MetricServiceApiBuilder(gaxGrpc); } - var metricServiceClient = gaxGrpc.load([{ - root: require('google-proto-files')('..'), - file: 'google/monitoring/v3/metric_service.proto' - }]); + var metricServiceClient = require('grpc-google-monitoring-v3').client; extend(this, metricServiceClient.google.monitoring.v3); var grpcClients = { @@ -796,4 +725,4 @@ function MetricServiceApiBuilder(gaxGrpc) { } module.exports = MetricServiceApiBuilder; module.exports.SERVICE_ADDRESS = SERVICE_ADDRESS; -module.exports.ALL_SCOPES = ALL_SCOPES; \ No newline at end of file +module.exports.ALL_SCOPES = ALL_SCOPES;