Skip to content

Commit

Permalink
feat!: drop node8 support, support for async iterators (#396)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexander-fenster authored Mar 31, 2020
1 parent 5c4d3b6 commit d2bfedc
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 111 deletions.
70 changes: 35 additions & 35 deletions monitoring/snippets/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,23 +308,23 @@ async function listPolicies(projectId) {
// [END monitoring_alert_list_policies]
}

require(`yargs`)
require('yargs')
.demand(1)
.command(
`backup <projectId>`,
`Save alert policies to a ./policies_backup.json file.`,
'backup <projectId>',
'Save alert policies to a ./policies_backup.json file.',
{},
opts => backupPolicies(opts.projectId, opts.filter || '')
)
.command(
`restore <projectId>`,
`Restore alert policies from a ./policies_backup.json file.`,
'restore <projectId>',
'Restore alert policies from a ./policies_backup.json file.',
{},
opts => restorePolicies(opts.projectId, opts.filter || '')
)
.command(
`replace <alertPolicyName> <channelNames..>`,
`Replace the notification channels of the specified alert policy.`,
'replace <alertPolicyName> <channelNames..>',
'Replace the notification channels of the specified alert policy.',
{},
opts => {
const parts = opts.alertPolicyName.split('/');
Expand All @@ -333,69 +333,69 @@ require(`yargs`)
}
)
.command(
`disable <projectId> [filter]`,
`Disables policies that match the given filter.`,
'disable <projectId> [filter]',
'Disables policies that match the given filter.',
{},
opts => enablePolicies(opts.projectId, false, opts.filter || ``)
opts => enablePolicies(opts.projectId, false, opts.filter || '')
)
.command(
`enable <projectId> [filter]`,
`Enables policies that match the given filter.`,
'enable <projectId> [filter]',
'Enables policies that match the given filter.',
{},
opts => enablePolicies(opts.projectId, true, opts.filter || ``)
opts => enablePolicies(opts.projectId, true, opts.filter || '')
)
.command(
`list <projectId>`,
`Lists alert policies in the specified project.`,
'list <projectId>',
'Lists alert policies in the specified project.',
{},
opts => listPolicies(opts.projectId)
)
.command(
`deleteChannels <projectId> [filter]`,
`Lists and deletes all channels in the specified project.`,
'deleteChannels <projectId> [filter]',
'Lists and deletes all channels in the specified project.',
{},
opts => deleteChannels(opts.projectId, opts.filter || ``)
opts => deleteChannels(opts.projectId, opts.filter || '')
)
.options({
alertPolicyName: {
type: 'string',
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;
72 changes: 36 additions & 36 deletions monitoring/snippets/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down Expand Up @@ -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]
}
Expand Down Expand Up @@ -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}`
Expand Down Expand Up @@ -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 <metricId> [projectId]`, `Get a metric descriptor.`, {}, opts =>
.command('get <metricId> [projectId]', 'Get a metric descriptor.', {}, opts =>
getMetricDescriptor(opts.projectId, opts.metricId)
)
.command(
`delete <metricId> [projectId]`,
`Deletes a custom metric descriptor.`,
'delete <metricId> [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 <filter> [projectId]`,
`Reads time series data that matches the given filter.`,
'read <filter> [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 <resourceType> [projectId]`,
`Get a monitored resource descriptor.`,
'get-resource <resourceType> [projectId]',
'Get a monitored resource descriptor.',
{},
opts => getMonitoredResourceDescriptor(opts.projectId, opts.resourceType)
)
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion monitoring/snippets/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
16 changes: 8 additions & 8 deletions monitoring/snippets/test/metrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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');
Expand All @@ -148,7 +148,7 @@ describe('metrics', () => {
alignmentPeriod: {
seconds: 600,
},
perSeriesAligner: `ALIGN_MEAN`,
perSeriesAligner: 'ALIGN_MEAN',
},
});
let output;
Expand Down Expand Up @@ -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`);
Expand Down
Loading

0 comments on commit d2bfedc

Please sign in to comment.