diff --git a/monitoring/create_custom_metric.js b/monitoring/create_custom_metric.js deleted file mode 100644 index cf0e223a8d..0000000000 --- a/monitoring/create_custom_metric.js +++ /dev/null @@ -1,275 +0,0 @@ -// Copyright 2015, Google, Inc. -// 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. - -/** - * @fileoverview Simple command-line program to demonstrate creating a custom - * metric with the Stackdriver Monitoring API, writing a random value to it, - * and reading it back. - */ -'use strict'; - -/* jshint camelcase: false */ - -var google = require('googleapis'); -var async = require('async'); - -var monitoringScopes = [ - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/monitoring', - 'https://www.googleapis.com/auth/monitoring.read', - 'https://www.googleapis.com/auth/monitoring.write' -]; - -/** - * Returns the current timestamp in RFC33339 with milliseconds format. - */ -function getNow () { - var d = new Date(); - return JSON.parse(JSON.stringify(d).replace('Z', '000Z')); -} - -/** - * Returns an hour ago in RFC33339 with milliseconds format. This is used - * to start the window to view the metric written in. - */ -function getStartTime () { - var d = new Date(); - d.setHours(d.getHours() - 1); - return JSON.parse(JSON.stringify(d).replace('Z', '000Z')); -} - -var CUSTOM_METRIC_DOMAIN = 'custom.googleapis.com'; - -/** - * Constructor function. The CustomMetrics class stores the type of metric - * in its instance class allowing unique ones to be used in tests. - */ -function CustomMetrics (projectName, metricType) { - this.projectResource = 'projects/' + projectName; - this.metricType = CUSTOM_METRIC_DOMAIN + '/' + metricType; - this.metricName = this.projectResource + - '/metricDescriptors/' + this.metricType; - this.valueOverride = false; -} - -/** - * Creates a custom metric. For demonstration purposes, this is a hypothetical - * measurement (measured in the 'items' unit, with random values written to - * it. - * @param {Object} authClient The authorized Monitoring client. - * @param {Function} callback Callback function. - */ -CustomMetrics.prototype.createCustomMetric = function (client, callback) { - var monitoring = google.monitoring('v3'); - - monitoring.projects.metricDescriptors.create({ - auth: client, - name: this.projectResource, - resource: { - name: this.metricName, - type: this.metricType, - labels: [ - { - key: 'environment', - valueType: 'STRING', - description: 'An abritrary measurement' - } - ], - metricKind: 'GAUGE', - valueType: 'INT64', - unit: 'items', - description: 'An arbitrary measurement.', - displayName: 'Custom Metric' - } - }, function (err, customMetric) { - if (err) { - return callback(err); - } - - console.log('Created custom metric', customMetric); - callback(null, customMetric); - }); -}; - -/** - * Writes a time series value for the custom metric just created. It uses a - * GAUGE measurement which indicates the value at this point in time. For - * demonstration purposes, this is a random value. For GAUGE measurements, - * the start time and end time of the value must be the same. The - * resource for this value is a hypothetical GCE instance. - * @param {Object} authClient The authorized Stackdriver Monitoring API client - * @param {Function} callback Callback Function. - */ -// [START write_timeseries] -CustomMetrics.prototype.writeTimeSeriesForCustomMetric = - function (client, callback) { - var monitoring = google.monitoring('v3'); - var now = getNow(); - - var timeSeries = [{ - metric: { - type: this.metricType, - labels: { - environment: 'production' - } - }, - resource: { - type: 'gce_instance', - labels: { - instance_id: 'test_instance', - zone: 'us-central1-f' - } - }, - points: { - interval: { - startTime: now, - endTime: now - }, - value: { - int64Value: this.getRandomInt(1, 20) - } - } - }]; - - monitoring.projects.timeSeries.create({ - auth: client, - name: this.projectResource, - resource: { - timeSeries: timeSeries - } - }, function (err) { - if (err) { - return callback(err); - } - - console.log('Wrote time series', timeSeries); - callback(null, timeSeries); - }); - }; -// [END write_timeseries] - -/** - * Lists the time series written for the custom metric. The window - * to read the timeseries starts an hour ago and extends unti the current - * time, so should include the metric value written by - * the earlier calls. - * @param {Object} authClient The authorized Stackdriver Monitoring API client - * @param {Function} callback Callback function. - */ -CustomMetrics.prototype.listTimeSeries = function (client, callback) { - var monitoring = google.monitoring('v3'); - var startTime = getStartTime(); - var endTime = getNow(); - - console.log('Reading metric type', this.metricType); - monitoring.projects.timeSeries.list({ - auth: client, - name: this.projectResource, - filter: `metric.type = "${this.metricType}"`, - pageSize: 3, - 'interval.startTime': startTime, - 'interval.endTime': endTime - }, function (err, timeSeries) { - if (err) { - return callback(err); - } - - console.log('Time series', timeSeries); - callback(null, timeSeries); - }); -}; - -/** - * @param {Object} authClient The authorized Stackdriver Monitoring API client - * @param {Function} callback Callback function. - */ -CustomMetrics.prototype.deleteMetric = function (client, callback) { - var monitoring = google.monitoring('v3'); - - console.log(this.metricName); - monitoring.projects.metricDescriptors.delete({ - auth: client, - name: this.metricName - }, function (err, result) { - if (err) { - return callback(err); - } - - console.log('Deleted metric', result); - callback(null, result); - }); -}; - -/** - * Gets random integer between low and high (exclusive). Used to fill in - * a random value for the measurement. - */ -CustomMetrics.prototype.getRandomInt = function (low, high) { - return Math.floor((Math.random() * (high - low)) + low); -}; - -CustomMetrics.prototype.getMonitoringClient = function (callback) { - google.auth.getApplicationDefault(function (err, authClient) { - if (err) { - return callback(err); - } - - // Depending on the environment that provides the default credentials - // (e.g. Compute Engine, App Engine), the credentials retrieved may - // require you to specify the scopes you need explicitly. - // Check for this case, and inject the Cloud Storage scope if required. - if (authClient.createScopedRequired && - authClient.createScopedRequired()) { - authClient = authClient.createScoped(monitoringScopes); - } - callback(null, authClient); - }); -}; - -// Run the examples -exports.main = function (projectId, name, cb) { - var customMetrics = new CustomMetrics(projectId, name); - customMetrics.getMonitoringClient(function (err, authClient) { - if (err) { - return cb(err); - } - // Create the service object. - async.series([ - function (cb) { - customMetrics.createCustomMetric(authClient, cb); - }, - function (cb) { - setTimeout(function () { - customMetrics.writeTimeSeriesForCustomMetric(authClient, cb); - }, 10000); - }, - function (cb) { - setTimeout(function () { - customMetrics.listTimeSeries(authClient, cb); - }, 45000); - }, - function (cb) { - customMetrics.deleteMetric(authClient, cb); - } - ], cb); - }); -}; - -if (require.main === module) { - var args = process.argv.slice(2); - exports.main( - args[0] || process.env.GCLOUD_PROJECT, - args[1] || 'custom_measurement', - console.log - ); -} diff --git a/monitoring/list_resources.js b/monitoring/list_resources.js deleted file mode 100644 index 11a92d289c..0000000000 --- a/monitoring/list_resources.js +++ /dev/null @@ -1,189 +0,0 @@ -// Copyright 2015, Google, Inc. -// 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. - -/** - * @fileoverview Simple command-line program to demonstrate connecting to the - * Stackdriver Monitoring API to retrieve API data. - */ -'use strict'; - -var google = require('googleapis'); -var async = require('async'); - -var monitoringScopes = [ - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/monitoring', - 'https://www.googleapis.com/auth/monitoring.read', - 'https://www.googleapis.com/auth/monitoring.write' -]; - -var METRIC = 'compute.googleapis.com/instance/cpu/usage_time'; - -/** - * Returns an hour ago minus 5 minutes in RFC33339 format. - */ -function getStartTime () { - var d = new Date(); - d.setHours(d.getHours() - 1); - d.setMinutes(d.getMinutes() - 5); - return JSON.parse(JSON.stringify(d).replace('Z', '000Z')); -} - -/** - * Returns an hour ago in RFC33339 format. - */ -function getEndTime () { - var d = new Date(); - d.setHours(d.getHours() - 1); - return JSON.parse(JSON.stringify(d).replace('Z', '000Z')); -} - -var ListResources = { - - /** - * This Lists all the resources available to be monitored in the API. - * - * @param {googleAuthClient} authClient - The authenticated Google api client - * @param {String} projectId - the project id - * @param {requestCallback} callback - a function to be called when the server - * responds with the list of monitored resource descriptors - */ - listMonitoredResourceDescriptors: function (authClient, projectId, callback) { - var monitoring = google.monitoring('v3'); - monitoring.projects.monitoredResourceDescriptors.list({ - auth: authClient, - name: projectId, - pageSize: 3 - }, function (err, monitoredResources) { - if (err) { - return callback(err); - } - - console.log('Monitored resources', monitoredResources); - callback(null, monitoredResources); - }); - }, - - /** - * This Lists the metric descriptors that start with our METRIC name, in this - * case the CPU usage time. - * @param {googleAuthClient} authClient - The authenticated Google api client - * @param {String} projectId - the project id - * @param {requestCallback} callback - a function to be called when the server - * responds with the list of monitored resource descriptors - */ - listMetricDescriptors: function (authClient, projectId, callback) { - var monitoring = google.monitoring('v3'); - monitoring.projects.metricDescriptors.list({ - auth: authClient, - filter: 'metric.type="' + METRIC + '"', - pageSize: 3, - name: projectId - }, function (err, metricDescriptors) { - if (err) { - return callback(err); - } - - console.log('Metric descriptors', metricDescriptors); - callback(null, metricDescriptors); - }); - }, - - /** - * This Lists all the timeseries created between START_TIME and END_TIME - * for our METRIC. - * @param {googleAuthClient} authClient - The authenticated Google api client - * @param {String} projectId - the project id - * @param {requestCallback} callback - a function to be called when the server - * responds with the list of monitored resource descriptors - */ - listTimeseries: function (authClient, projectId, callback) { - var monitoring = google.monitoring('v3'); - var startTime = getStartTime(); - var endTime = getEndTime(); - - monitoring.projects.timeSeries.list({ - auth: authClient, - filter: 'metric.type="' + METRIC + '"', - pageSize: 3, - 'interval.startTime': startTime, - 'interval.endTime': endTime, - name: projectId - }, function (err, timeSeries) { - if (err) { - return callback(err); - } - - console.log('Time series', timeSeries); - callback(null, timeSeries); - }); - }, - - getMonitoringClient: function (callback) { - google.auth.getApplicationDefault(function (err, authClient) { - if (err) { - return callback(err); - } - // Depending on the environment that provides the default credentials - // (e.g. Compute Engine, App Engine), the credentials retrieved may - // require you to specify the scopes you need explicitly. - // Check for this case, and inject the Cloud Storage scope if required. - if (authClient.createScopedRequired && - authClient.createScopedRequired()) { - authClient = authClient.createScoped(monitoringScopes); - } - callback(null, authClient); - }); - } -}; - -exports.main = function (projectId, cb) { - var projectName = 'projects/' + projectId; - ListResources.getMonitoringClient(function (err, authClient) { - if (err) { - return cb(err); - } - // Create the service object. - async.series([ - function (cb) { - ListResources.listMonitoredResourceDescriptors( - authClient, - projectName, - cb - ); - }, - function (cb) { - ListResources.listMetricDescriptors( - authClient, - projectName, - cb - ); - }, - function (cb) { - ListResources.listTimeseries( - authClient, - projectName, - cb - ); - } - ], cb); - }); -}; - -if (require.main === module) { - var args = process.argv.slice(2); - exports.main( - args[0] || process.env.GCLOUD_PROJECT, - console.log - ); -} diff --git a/monitoring/metrics.js b/monitoring/metrics.js index dc1d7a2b91..ee3a5c0c25 100644 --- a/monitoring/metrics.js +++ b/monitoring/metrics.js @@ -28,8 +28,8 @@ function createMetricDescriptor (projectId) { // Imports the Google Cloud client library const Monitoring = require('@google-cloud/monitoring'); - // Instantiates a client - const client = Monitoring.v3().metricServiceClient(); + // Creates a client + const client = Monitoring.v3.metric(); // The Google Cloud Platform project on which to execute the request // const projectId = 'YOUR_PROJECT_ID'; @@ -81,8 +81,8 @@ function listMetricDescriptors (projectId) { // Imports the Google Cloud client library const Monitoring = require('@google-cloud/monitoring'); - // Instantiates a client - const client = Monitoring.v3().metricServiceClient(); + // Creates a client + const client = Monitoring.v3.metric(); // The Google Cloud Platform project on which to execute the request // const projectId = 'YOUR_PROJECT_ID'; @@ -110,8 +110,8 @@ function getMetricDescriptor (projectId, metricId) { // Imports the Google Cloud client library const Monitoring = require('@google-cloud/monitoring'); - // Instantiates a client - const client = Monitoring.v3().metricServiceClient(); + // Creates a client + const client = Monitoring.v3.metric(); // The Google Cloud Platform project on which to execute the request // const projectId = 'YOUR_PROJECT_ID'; @@ -150,8 +150,8 @@ function deleteMetricDescriptor (projectId, metricId) { // Imports the Google Cloud client library const Monitoring = require('@google-cloud/monitoring'); - // Instantiates a client - const client = Monitoring.v3().metricServiceClient(); + // Creates a client + const client = Monitoring.v3.metric(); // The Google Cloud Platform project on which to execute the request // const projectId = 'YOUR_PROJECT_ID'; @@ -179,8 +179,8 @@ function writeTimeSeriesData (projectId, metricId) { // Imports the Google Cloud client library const Monitoring = require('@google-cloud/monitoring'); - // Instantiates a client - const client = Monitoring.v3().metricServiceClient(); + // Creates a client + const client = Monitoring.v3.metric(); // The Google Cloud Platform project on which to execute the request // const projectId = 'YOUR_PROJECT_ID'; @@ -237,8 +237,8 @@ function readTimeSeriesData (projectId, filter) { // Imports the Google Cloud client library const Monitoring = require('@google-cloud/monitoring'); - // Instantiates a client - const client = Monitoring.v3().metricServiceClient(); + // Creates a client + const client = Monitoring.v3.metric(); // The Google Cloud Platform project on which to execute the request // const projectId = 'YOUR_PROJECT_ID'; @@ -283,8 +283,8 @@ function readTimeSeriesFields (projectId) { // Imports the Google Cloud client library const Monitoring = require('@google-cloud/monitoring'); - // Instantiates a client - const client = Monitoring.v3().metricServiceClient(); + // Creates a client + const client = Monitoring.v3.metric(); // The Google Cloud Platform project on which to execute the request // const projectId = 'YOUR_PROJECT_ID'; @@ -327,8 +327,8 @@ function readTimeSeriesAggregate (projectId) { // Imports the Google Cloud client library const Monitoring = require('@google-cloud/monitoring'); - // Instantiates a client - const client = Monitoring.v3().metricServiceClient(); + // Creates a client + const client = Monitoring.v3.metric(); // The Google Cloud Platform project on which to execute the request // const projectId = 'YOUR_PROJECT_ID'; @@ -377,8 +377,8 @@ function readTimeSeriesReduce (projectId) { // Imports the Google Cloud client library const Monitoring = require('@google-cloud/monitoring'); - // Instantiates a client - const client = Monitoring.v3().metricServiceClient(); + // Creates a client + const client = Monitoring.v3.metric(); // The Google Cloud Platform project on which to execute the request // const projectId = 'YOUR_PROJECT_ID'; @@ -425,8 +425,8 @@ function listMonitoredResourceDescriptors (projectId) { // Imports the Google Cloud client library const Monitoring = require('@google-cloud/monitoring'); - // Instantiates a client - const client = Monitoring.v3().metricServiceClient(); + // Creates a client + const client = Monitoring.v3.metric(); // The Google Cloud Platform project on which to execute the request // const projectId = 'YOUR_PROJECT_ID'; @@ -454,8 +454,8 @@ function getMonitoredResourceDescriptor (projectId, resourceType) { // Imports the Google Cloud client library const Monitoring = require('@google-cloud/monitoring'); - // Instantiates a client - const client = Monitoring.v3().metricServiceClient(); + // Creates a client + const client = Monitoring.v3.metric(); // The Google Cloud Platform project on which to execute the request // const projectId = 'YOUR_PROJECT_ID'; diff --git a/monitoring/package.json b/monitoring/package.json index d25a85639b..a69f0dd5b6 100644 --- a/monitoring/package.json +++ b/monitoring/package.json @@ -12,21 +12,19 @@ "node": ">=4.3.2" }, "scripts": { - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", - "test": "samples test run --cmd ava -- -T 3m --verbose system-test/*.test.js" + "test": "repo-tools test run --cmd ava -- -T 3m --verbose system-test/*.test.js" }, "dependencies": { - "@google-cloud/monitoring": "0.2.3", - "async": "2.5.0", - "googleapis": "20.1.0", - "yargs": "8.0.2" + "@google-cloud/monitoring": "0.3.0", + "yargs": "9.0.1" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.21.0", + "@google-cloud/nodejs-repo-tools": "2.0.4", + "ava": "0.22.0", "proxyquire": "1.8.0", - "sinon": "3.2.0" + "sinon": "4.0.0" }, "cloud-repo-tools": { "requiresKeyFile": true, @@ -39,28 +37,6 @@ "file": "metrics.js", "docs_link": "https://cloud.google.com/monitoring/docs", "usage": "node metrics.js --help" - }, - { - "id": "list", - "name": "Listing resources", - "file": "list_resources.js", - "docs_link": "https://cloud.google.com/monitoring/demos/#hello-world", - "description": "`list_resources.js` is a command-line program to demonstrate connecting to the\nGoogle Monitoring API to retrieve API data.", - "usage": { - "text": "node list_resources " - }, - "help": "node list_resources my-cool-project" - }, - { - "id": "metrics", - "name": "Custom metrics", - "file": "create_custom_metric.js", - "docs_link": "https://cloud.google.com/monitoring/demos/#custom_metrics", - "description": "`create_custom_metric.js` demonstrates how to create a custom metric, write a\ntimeseries value to it, and read it back.", - "usage": { - "text": "node create_custom_metric " - }, - "help": "node create_custom_metric my-cool-project" } ] } diff --git a/monitoring/quickstart.js b/monitoring/quickstart.js index 0dff897ae3..ca66561fbb 100644 --- a/monitoring/quickstart.js +++ b/monitoring/quickstart.js @@ -22,8 +22,8 @@ const Monitoring = require('@google-cloud/monitoring'); // Your Google Cloud Platform project ID const projectId = 'YOUR_PROJECT_ID'; -// Instantiates a client -const client = Monitoring.v3().metricServiceClient(); +// Creates a client +const client = Monitoring.v3.metric(); // Prepares an individual data point const dataPoint = { diff --git a/monitoring/system-test/create_custom_metric.test.js b/monitoring/system-test/create_custom_metric.test.js deleted file mode 100644 index ba09a252ed..0000000000 --- a/monitoring/system-test/create_custom_metric.test.js +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright 2017, Google, Inc. - * 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. - */ - -'use strict'; - -const customMetricsExample = require('../create_custom_metric'); -const test = require(`ava`); -const tools = require(`@google-cloud/nodejs-repo-tools`); - -/** Refactored out to keep lines shorter */ -function getPointValue (timeSeries) { - return timeSeries[0].points.value.int64Value; -} - -test.before(tools.checkCredentials); -test.before(tools.stubConsole); -test.after.always(tools.restoreConsole); - -test.cb('should create and read back a custom metric', (t) => { - customMetricsExample.main( - process.env.GCLOUD_PROJECT, - Math.random().toString(36).substring(7), - (err, results) => { - t.ifError(err); - t.is(results.length, 4); - // Result of creating metric - t.is(typeof results[0].name, 'string'); - // Result of writing time series - t.deepEqual(results[3], {}); - // Result of reading time series - t.false(isNaN(getPointValue(results[1]))); - // Result of deleting metric - t.deepEqual(results[3], {}); - t.true(console.log.calledWith('Created custom metric')); - t.true(console.log.calledWith('Wrote time series')); - t.true(console.log.calledWith('Reading metric type')); - t.true(console.log.calledWith('Time series')); - t.true(console.log.calledWith('Deleted metric')); - t.end(); - } - ); -}); diff --git a/monitoring/system-test/list_resources.test.js b/monitoring/system-test/list_resources.test.js deleted file mode 100644 index 0221582ab2..0000000000 --- a/monitoring/system-test/list_resources.test.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2017, Google, Inc. - * 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. - */ - -'use strict'; - -const listResourcesExample = require(`../list_resources`); -const test = require(`ava`); -const tools = require(`@google-cloud/nodejs-repo-tools`); - -test.before(tools.checkCredentials); -test.before(tools.stubConsole); -test.after.always(tools.restoreConsole); - -test.cb(`should list a bunch of stuff`, (t) => { - listResourcesExample.main(process.env.GCLOUD_PROJECT, (err, results) => { - t.ifError(err); - t.is(results.length, 3); - // Monitored resources - t.true(Array.isArray(results[0].resourceDescriptors)); - // Metric descriptors - t.true(Array.isArray(results[1].metricDescriptors)); - // Time series - t.true(Array.isArray(results[2].timeSeries)); - t.true(console.log.calledWith('Monitored resources')); - t.true(console.log.calledWith('Metric descriptors')); - t.true(console.log.calledWith('Time series')); - t.end(); - }); -}); diff --git a/monitoring/system-test/metrics.test.js b/monitoring/system-test/metrics.test.js index 62db00c360..5b534209a9 100644 --- a/monitoring/system-test/metrics.test.js +++ b/monitoring/system-test/metrics.test.js @@ -15,7 +15,7 @@ 'use strict'; -const client = require(`@google-cloud/monitoring`).v3().metricServiceClient(); +const client = require(`@google-cloud/monitoring`).v3.metric(); const path = require(`path`); const test = require(`ava`); const tools = require(`@google-cloud/nodejs-repo-tools`); diff --git a/monitoring/system-test/quickstart.test.js b/monitoring/system-test/quickstart.test.js index 8ac5431539..4386d412e7 100644 --- a/monitoring/system-test/quickstart.test.js +++ b/monitoring/system-test/quickstart.test.js @@ -20,7 +20,7 @@ const sinon = require(`sinon`); const test = require(`ava`); const tools = require(`@google-cloud/nodejs-repo-tools`); -const client = proxyquire(`@google-cloud/monitoring`, {}).v3().metricServiceClient(); +const client = proxyquire(`@google-cloud/monitoring`, {}).v3.metric(); test.beforeEach(tools.stubConsole); test.afterEach.always(tools.restoreConsole); @@ -51,9 +51,9 @@ test.cb(`should list time series`, (t) => { proxyquire(`../quickstart`, { '@google-cloud/monitoring': { - v3: sinon.stub().returns({ - metricServiceClient: sinon.stub().returns(clientMock) - }) + v3: { + metric: sinon.stub().returns(clientMock) + } } }); });