Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
fix: update alert policies one at a time because (concurrent updates …
Browse files Browse the repository at this point in the history
…are not supported) (#507)
  • Loading branch information
syedashrafulla authored Dec 22, 2020
1 parent afa651f commit 2bf75a2
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 24 deletions.
33 changes: 15 additions & 18 deletions samples/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,26 +254,23 @@ async function enablePolicies(projectId, enabled, filter) {
};

const [policies] = await client.listAlertPolicies(listAlertPoliciesRequest);
const tasks = await Promise.all(
policies
.map(policy => {
return {
updateMask: {
paths: ['enabled'],
},
alertPolicy: {
name: policy.name,
enabled: {
value: enabled,
},
const responses = [];
for (const policy of policies) {
responses.push(
await client.updateAlertPolicy({
updateMask: {
paths: ['enabled'],
},
alertPolicy: {
name: policy.name,
enabled: {
value: enabled,
},
};
},
})
.map(updateAlertPolicyRequest =>
client.updateAlertPolicy(updateAlertPolicyRequest)
)
);
tasks.forEach(response => {
);
}
responses.forEach(response => {
const alertPolicy = response[0];
console.log(`${enabled ? 'Enabled' : 'Disabled'} ${alertPolicy.name}.`);
});
Expand Down
2 changes: 1 addition & 1 deletion samples/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ const cli = require('yargs')
.options({
projectId: {
alias: 'p',
default: process.env.GCLOUD_PROJECT,
default: process.env.GCLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT,
global: true,
requiresArg: true,
type: 'string',
Expand Down
5 changes: 4 additions & 1 deletion samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const monitoring = require('@google-cloud/monitoring');

async function quickstart() {
// Your Google Cloud Platform project ID
const projectId = process.env.GCLOUD_PROJECT || 'YOUR_PROJECT_ID';
const projectId =
process.env.GCLOUD_PROJECT ||
process.env.GOOGLE_CLOUD_PROJECT ||
'YOUR_PROJECT_ID';

// Creates a client
const client = new monitoring.MetricServiceClient();
Expand Down
3 changes: 2 additions & 1 deletion samples/test/alerts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const client = new monitoring.AlertPolicyServiceClient();
const channelClient = new monitoring.NotificationChannelServiceClient();
const projectId = process.env.GCLOUD_PROJECT;
const projectId =
process.env.GCLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT;
const cmd = 'node alerts';

let policyOneName, policyTwoName, channelName;
Expand Down
3 changes: 2 additions & 1 deletion samples/test/metrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ 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 projectId =
process.env.GCLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT;
const resourceId = 'cloudsql_database';

// A helper for delaying integration tests with an exponential backoff.
Expand Down
3 changes: 2 additions & 1 deletion samples/test/uptime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const cp = require('child_process');
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const cmd = 'node uptime.js';
const projectId = process.env.GCLOUD_PROJECT;
const projectId =
process.env.GCLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT;
const hostname = 'mydomain.com';

function getResourceObjects(output) {
Expand Down
2 changes: 1 addition & 1 deletion samples/uptime.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ require('yargs')
.options({
projectId: {
alias: 'p',
default: process.env.GCLOUD_PROJECT,
default: process.env.GCLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT,
global: true,
requiresArg: true,
type: 'string',
Expand Down

0 comments on commit 2bf75a2

Please sign in to comment.