From d2bfedc35570619a7f9eff57f977232b00ef7184 Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Tue, 31 Mar 2020 15:28:17 -0700 Subject: [PATCH] feat!: drop node8 support, support for async iterators (#396) BREAKING CHANGE: The library now supports Node.js v10+. The last version to support Node.js v8 is tagged legacy-8 on NPM. New feature: methods with pagination now support async iteration. --- monitoring/snippets/alerts.js | 70 +++++++++++------------ monitoring/snippets/metrics.js | 72 ++++++++++++------------ monitoring/snippets/quickstart.js | 2 +- monitoring/snippets/test/metrics.test.js | 16 +++--- monitoring/snippets/uptime.js | 62 ++++++++++---------- 5 files changed, 111 insertions(+), 111 deletions(-) diff --git a/monitoring/snippets/alerts.js b/monitoring/snippets/alerts.js index 7af4d098b9..5e40f94c8f 100644 --- a/monitoring/snippets/alerts.js +++ b/monitoring/snippets/alerts.js @@ -308,23 +308,23 @@ async function listPolicies(projectId) { // [END monitoring_alert_list_policies] } -require(`yargs`) +require('yargs') .demand(1) .command( - `backup `, - `Save alert policies to a ./policies_backup.json file.`, + 'backup ', + 'Save alert policies to a ./policies_backup.json file.', {}, opts => backupPolicies(opts.projectId, opts.filter || '') ) .command( - `restore `, - `Restore alert policies from a ./policies_backup.json file.`, + 'restore ', + 'Restore alert policies from a ./policies_backup.json file.', {}, opts => restorePolicies(opts.projectId, opts.filter || '') ) .command( - `replace `, - `Replace the notification channels of the specified alert policy.`, + 'replace ', + 'Replace the notification channels of the specified alert policy.', {}, opts => { const parts = opts.alertPolicyName.split('/'); @@ -333,28 +333,28 @@ require(`yargs`) } ) .command( - `disable [filter]`, - `Disables policies that match the given filter.`, + 'disable [filter]', + 'Disables policies that match the given filter.', {}, - opts => enablePolicies(opts.projectId, false, opts.filter || ``) + opts => enablePolicies(opts.projectId, false, opts.filter || '') ) .command( - `enable [filter]`, - `Enables policies that match the given filter.`, + 'enable [filter]', + 'Enables policies that match the given filter.', {}, - opts => enablePolicies(opts.projectId, true, opts.filter || ``) + opts => enablePolicies(opts.projectId, true, opts.filter || '') ) .command( - `list `, - `Lists alert policies in the specified project.`, + 'list ', + 'Lists alert policies in the specified project.', {}, opts => listPolicies(opts.projectId) ) .command( - `deleteChannels [filter]`, - `Lists and deletes all channels in the specified project.`, + 'deleteChannels [filter]', + 'Lists and deletes all channels in the specified project.', {}, - opts => deleteChannels(opts.projectId, opts.filter || ``) + opts => deleteChannels(opts.projectId, opts.filter || '') ) .options({ alertPolicyName: { @@ -362,40 +362,40 @@ require(`yargs`) requiresArg: true, }, }) - .example(`node $0 backup my-project-id`, `Backup policies.`) - .example(`node $0 restore my-project-id`, `Restore policies.`) + .example('node $0 backup my-project-id', 'Backup policies.') + .example('node $0 restore my-project-id', 'Restore policies.') .example( - `node $0 replace projects/my-project-id/alertPolicies/12345 channel-1 channel-2 channel-3`, - `Replace the notification channels of the specified alert policy.` + 'node $0 replace projects/my-project-id/alertPolicies/12345 channel-1 channel-2 channel-3', + 'Replace the notification channels of the specified alert policy.' ) .example( - `node $0 disable my-project-id "(NOT display_name.empty OR NOT description.empty) AND user_labels='active'"`, - `Disables policies that match the given filter.` + 'node $0 disable my-project-id "(NOT display_name.empty OR NOT description.empty) AND user_labels=\'active\'"', + 'Disables policies that match the given filter.' ) .example( - `node $0 disable my-project-id "description:'cloud'"`, - `Disables policies that match the given filter.` + 'node $0 disable my-project-id "description:\'cloud\'"', + 'Disables policies that match the given filter.' ) .example( - `node $0 disable my-project-id "display_name=monitoring.regex.full_match('Temp \\d{4}')"`, - `Disables policies that match the given filter.` + 'node $0 disable my-project-id "display_name=monitoring.regex.full_match(\'Temp \\d{4}\')"', + 'Disables policies that match the given filter.' ) .example( - `node $0 enable my-project-id "(NOT display_name.empty OR NOT description.empty) AND user_labels='active'"`, - `Enables policies that match the given filter.` + 'node $0 enable my-project-id "(NOT display_name.empty OR NOT description.empty) AND user_labels=\'active\'"', + 'Enables policies that match the given filter.' ) .example( - `node $0 enable my-project-id "description:'cloud'"`, - `Enables policies that match the given filter.` + 'node $0 enable my-project-id "description:\'cloud\'"', + 'Enables policies that match the given filter.' ) .example( - `node $0 enable my-project-id "display_name=monitoring.regex.full_match('Temp \\d{4}')"`, - `Enables policies that match the given filter.` + 'node $0 enable my-project-id "display_name=monitoring.regex.full_match(\'Temp \\d{4}\')"', + 'Enables policies that match the given filter.' ) .wrap(120) .recommendCommands() .epilogue( - `For more information, see https://cloud.google.com/monitoring/docs/` + 'For more information, see https://cloud.google.com/monitoring/docs/' ) .help() .strict().argv; diff --git a/monitoring/snippets/metrics.js b/monitoring/snippets/metrics.js index 0aeb0d43c5..0df8929d55 100644 --- a/monitoring/snippets/metrics.js +++ b/monitoring/snippets/metrics.js @@ -200,7 +200,7 @@ async function writeTimeSeriesData(projectId) { // Writes time series data const result = await client.createTimeSeries(request); - console.log(`Done writing time series data.`, result); + console.log('Done writing time series data.', result); // [END monitoring_write_timeseries] } @@ -330,7 +330,7 @@ async function readTimeSeriesAggregate(projectId) { } console.log(` Now: ${data.points[0].value.doubleValue}`); console.log(` 10 min ago: ${data.points[1].value.doubleValue}`); - console.log(`=====`); + console.log('====='); }); // [END monitoring_read_timeseries_align] } @@ -409,7 +409,7 @@ async function listMonitoredResourceDescriptors(projectId) { console.log(descriptor.name); console.log(` Type: ${descriptor.type}`); if (descriptor.labels) { - console.log(` Labels:`); + console.log(' Labels:'); descriptor.labels.forEach(label => { console.log( ` ${label.key} (${label.valueType}): ${label.description}` @@ -456,65 +456,65 @@ async function getMonitoredResourceDescriptor(projectId, resourceType) { // [END monitoring_get_resource] } -const cli = require(`yargs`) +const cli = require('yargs') .demand(1) .command( - `create [projectId]`, - `Creates an example 'custom.googleapis.com/stores/daily_sales' custom metric descriptor.`, + 'create [projectId]', + "Creates an example 'custom.googleapis.com/stores/daily_sales' custom metric descriptor.", {}, opts => createMetricDescriptor(opts.projectId) ) - .command(`list [projectId]`, `Lists metric descriptors.`, {}, opts => + .command('list [projectId]', 'Lists metric descriptors.', {}, opts => listMetricDescriptors(opts.projectId) ) - .command(`get [projectId]`, `Get a metric descriptor.`, {}, opts => + .command('get [projectId]', 'Get a metric descriptor.', {}, opts => getMetricDescriptor(opts.projectId, opts.metricId) ) .command( - `delete [projectId]`, - `Deletes a custom metric descriptor.`, + 'delete [projectId]', + 'Deletes a custom metric descriptor.', {}, opts => deleteMetricDescriptor(opts.projectId, opts.metricId) ) .command( - `write [projectId]`, - `Writes example time series data to 'custom.googleapis.com/stores/daily_sales'.`, + 'write [projectId]', + "Writes example time series data to 'custom.googleapis.com/stores/daily_sales'.", {}, opts => writeTimeSeriesData(opts.projectId) ) .command( - `read [projectId]`, - `Reads time series data that matches the given filter.`, + 'read [projectId]', + 'Reads time series data that matches the given filter.', {}, opts => readTimeSeriesData(opts.projectId, opts.filter) ) .command( - `read-fields [projectId]`, - `Reads headers of time series data that matches 'compute.googleapis.com/instance/cpu/utilization'.`, + 'read-fields [projectId]', + "Reads headers of time series data that matches 'compute.googleapis.com/instance/cpu/utilization'.", {}, opts => readTimeSeriesFields(opts.projectId) ) .command( - `read-aggregate [projectId]`, - `Aggregates time series data that matches 'compute.googleapis.com/instance/cpu/utilization'.`, + 'read-aggregate [projectId]', + "Aggregates time series data that matches 'compute.googleapis.com/instance/cpu/utilization'.", {}, opts => readTimeSeriesAggregate(opts.projectId) ) .command( - `read-reduce [projectId]`, - `Reduces time series data that matches 'compute.googleapis.com/instance/cpu/utilization'.`, + 'read-reduce [projectId]', + "Reduces time series data that matches 'compute.googleapis.com/instance/cpu/utilization'.", {}, opts => readTimeSeriesReduce(opts.projectId) ) .command( - `list-resources [projectId]`, - `Lists monitored resource descriptors.`, + 'list-resources [projectId]', + 'Lists monitored resource descriptors.', {}, opts => listMonitoredResourceDescriptors(opts.projectId) ) .command( - `get-resource [projectId]`, - `Get a monitored resource descriptor.`, + 'get-resource [projectId]', + 'Get a monitored resource descriptor.', {}, opts => getMonitoredResourceDescriptor(opts.projectId, opts.resourceType) ) @@ -527,23 +527,23 @@ const cli = require(`yargs`) type: 'string', }, }) - .example(`node $0 create`) - .example(`node $0 list`) - .example(`node $0 get logging.googleapis.com/log_entry_count`) - .example(`node $0 delete custom.googleapis.com/stores/daily_sales`) - .example(`node $0 list-resources`) - .example(`node $0 get-resource cloudsql_database`) - .example(`node $0 write`) + .example('node $0 create') + .example('node $0 list') + .example('node $0 get logging.googleapis.com/log_entry_count') + .example('node $0 delete custom.googleapis.com/stores/daily_sales') + .example('node $0 list-resources') + .example('node $0 get-resource cloudsql_database') + .example('node $0 write') .example( - `node $0 read 'metric.type="compute.googleapis.com/instance/cpu/utilization"'` + 'node $0 read \'metric.type="compute.googleapis.com/instance/cpu/utilization"\'' ) - .example(`node $0 read-fields`) - .example(`node $0 read-aggregate`) - .example(`node $0 read-reduce`) + .example('node $0 read-fields') + .example('node $0 read-aggregate') + .example('node $0 read-reduce') .wrap(120) .recommendCommands() .epilogue( - `For more information, see https://cloud.google.com/monitoring/docs` + 'For more information, see https://cloud.google.com/monitoring/docs' ); if (module === require.main) { diff --git a/monitoring/snippets/quickstart.js b/monitoring/snippets/quickstart.js index 54d132476f..1be7d2e182 100644 --- a/monitoring/snippets/quickstart.js +++ b/monitoring/snippets/quickstart.js @@ -63,7 +63,7 @@ async function quickstart() { // Writes time series data const [result] = await client.createTimeSeries(request); - console.log(`Done writing time series data.`, result); + console.log('Done writing time series data.', result); } // [END monitoring_quickstart] diff --git a/monitoring/snippets/test/metrics.test.js b/monitoring/snippets/test/metrics.test.js index 4a0b1e44d1..d0829da582 100644 --- a/monitoring/snippets/test/metrics.test.js +++ b/monitoring/snippets/test/metrics.test.js @@ -23,12 +23,12 @@ const retry = require('p-retry'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const client = new monitoring.MetricServiceClient(); -const cmd = `node metrics.js`; -const customMetricId = `custom.googleapis.com/stores/daily_sales`; -const computeMetricId = `compute.googleapis.com/instance/cpu/utilization`; +const cmd = 'node metrics.js'; +const customMetricId = 'custom.googleapis.com/stores/daily_sales'; +const computeMetricId = 'compute.googleapis.com/instance/cpu/utilization'; const filter = `metric.type="${computeMetricId}"`; const projectId = process.env.GCLOUD_PROJECT; -const resourceId = `cloudsql_database`; +const resourceId = 'cloudsql_database'; describe('metrics', () => { it('should create a metric descriptors', () => { @@ -121,7 +121,7 @@ describe('metrics', () => { }, // Don't return time series data, instead just return information about // the metrics that match the filter - view: `HEADERS`, + view: 'HEADERS', }); const output = execSync(`${cmd} read-fields`); assert.include(output, 'Found data points for the following instances'); @@ -148,7 +148,7 @@ describe('metrics', () => { alignmentPeriod: { seconds: 600, }, - perSeriesAligner: `ALIGN_MEAN`, + perSeriesAligner: 'ALIGN_MEAN', }, }); let output; @@ -184,8 +184,8 @@ describe('metrics', () => { alignmentPeriod: { seconds: 600, }, - crossSeriesReducer: `REDUCE_MEAN`, - perSeriesAligner: `ALIGN_MEAN`, + crossSeriesReducer: 'REDUCE_MEAN', + perSeriesAligner: 'ALIGN_MEAN', }, }); const output = execSync(`${cmd} read-reduce`); diff --git a/monitoring/snippets/uptime.js b/monitoring/snippets/uptime.js index e4d19eb58c..442edc85cf 100644 --- a/monitoring/snippets/uptime.js +++ b/monitoring/snippets/uptime.js @@ -66,12 +66,12 @@ async function createUptimeCheckConfig(projectId, hostname) { console.log('Uptime check created:'); console.log(`ID: ${uptimeCheckConfig.name}`); console.log(`Display Name: ${uptimeCheckConfig.displayName}`); - console.log(`Resource: %j`, uptimeCheckConfig.monitoredResource); - console.log(`Period: %j`, uptimeCheckConfig.period); - console.log(`Timeout: %j`, uptimeCheckConfig.timeout); + console.log('Resource: %j', uptimeCheckConfig.monitoredResource); + console.log('Period: %j', uptimeCheckConfig.period); + console.log('Timeout: %j', uptimeCheckConfig.timeout); console.log(`Check type: ${uptimeCheckConfig.check_request_type}`); console.log( - `Check: %j`, + 'Check: %j', uptimeCheckConfig.httpCheck || uptimeCheckConfig.tcpCheck ); console.log( @@ -107,12 +107,12 @@ async function listUptimeCheckConfigs(projectId) { uptimeCheckConfigs.forEach(uptimeCheckConfig => { console.log(`ID: ${uptimeCheckConfig.name}`); console.log(` Display Name: ${uptimeCheckConfig.displayName}`); - console.log(` Resource: %j`, uptimeCheckConfig.monitoredResource); - console.log(` Period: %j`, uptimeCheckConfig.period); - console.log(` Timeout: %j`, uptimeCheckConfig.timeout); + console.log(' Resource: %j', uptimeCheckConfig.monitoredResource); + console.log(' Period: %j', uptimeCheckConfig.period); + console.log(' Timeout: %j', uptimeCheckConfig.timeout); console.log(` Check type: ${uptimeCheckConfig.check_request_type}`); console.log( - ` Check: %j`, + ' Check: %j', uptimeCheckConfig.httpCheck || uptimeCheckConfig.tcpCheck ); console.log( @@ -172,12 +172,12 @@ async function getUptimeCheckConfig(projectId, uptimeCheckConfigId) { const [uptimeCheckConfig] = await client.getUptimeCheckConfig(request); console.log(`ID: ${uptimeCheckConfig.name}`); console.log(`Display Name: ${uptimeCheckConfig.displayName}`); - console.log(`Resource: %j`, uptimeCheckConfig.monitoredResource); - console.log(`Period: %j`, uptimeCheckConfig.period); - console.log(`Timeout: %j`, uptimeCheckConfig.timeout); + console.log('Resource: %j', uptimeCheckConfig.monitoredResource); + console.log('Period: %j', uptimeCheckConfig.period); + console.log('Timeout: %j', uptimeCheckConfig.timeout); console.log(`Check type: ${uptimeCheckConfig.check_request_type}`); console.log( - `Check: %j`, + 'Check: %j', uptimeCheckConfig.httpCheck || uptimeCheckConfig.tcpCheck ); console.log( @@ -265,35 +265,35 @@ async function updateUptimeCheckConfigDisplayName( // [END monitoring_uptime_check_update] } -require(`yargs`) +require('yargs') .demand(1) .command( - `create [projectId]`, - `Creates an uptime check config.`, + 'create [projectId]', + 'Creates an uptime check config.', {}, opts => createUptimeCheckConfig(opts.projectId, '' + opts.hostname) ) - .command(`list [projectId]`, `Lists uptime check configs.`, {}, opts => + .command('list [projectId]', 'Lists uptime check configs.', {}, opts => listUptimeCheckConfigs(opts.projectId) ) - .command(`list-ips`, `Lists uptime check config IPs.`, {}, () => + .command('list-ips', 'Lists uptime check config IPs.', {}, () => listUptimeCheckIps() ) .command( - `get [projectId]`, - `Gets an uptime check config.`, + 'get [projectId]', + 'Gets an uptime check config.', {}, opts => getUptimeCheckConfig(opts.projectId, opts.uptimeCheckConfigId) ) .command( - `delete [projectId]`, - `Deletes an uptime check config.`, + 'delete [projectId]', + 'Deletes an uptime check config.', {}, opts => deleteUptimeCheckConfig(opts.projectId, opts.uptimeCheckConfigId) ) .command( - `update [projectId]`, - `Update the display name of an uptime check config.`, + 'update [projectId]', + 'Update the display name of an uptime check config.', {}, opts => updateUptimeCheckConfigDisplayName( @@ -312,20 +312,20 @@ require(`yargs`) type: 'string', }, }) - .example(`node $0 create mydomain.com`, 'Create an uptime check.') - .example(`node $0 list`, 'List all uptime check configs.') + .example('node $0 create mydomain.com', 'Create an uptime check.') + .example('node $0 list', 'List all uptime check configs.') .example( - `node $0 list "resource.type = gce_instance AND resource.label.instance_id = mongodb"`, + 'node $0 list "resource.type = gce_instance AND resource.label.instance_id = mongodb"', 'List all uptime check configs for a specific GCE instance.' ) - .example(`node $0 list-ips`) - .example(`node $0 get My-Uptime-Check`) - .example(`node $0 delete My-Uptime-Check`) - .example(`node $0 update My-Uptime-Check "My New Uptime Check" /some/path`) + .example('node $0 list-ips') + .example('node $0 get My-Uptime-Check') + .example('node $0 delete My-Uptime-Check') + .example('node $0 update My-Uptime-Check "My New Uptime Check" /some/path') .wrap(120) .recommendCommands() .epilogue( - `For more information, see https://cloud.google.com/monitoring/uptime-checks/` + 'For more information, see https://cloud.google.com/monitoring/uptime-checks/' ) .help() .strict().argv;