Skip to content

Commit

Permalink
test: sometimes there are no metrics from 10 minutes ago (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Apr 6, 2020
1 parent 71a0a84 commit 6b900be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 3 additions & 5 deletions monitoring/snippets/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ async function readTimeSeriesAggregate(projectId) {
// [START monitoring_read_timeseries_align]
// Imports the Google Cloud client library
const monitoring = require('@google-cloud/monitoring');
const util = require('util');

// Creates a client
const client = new monitoring.MetricServiceClient();
Expand Down Expand Up @@ -325,11 +324,10 @@ async function readTimeSeriesAggregate(projectId) {
console.log('CPU utilization:');
timeSeries.forEach(data => {
console.log(data.metric.labels.instance_name);
for (const p of data.points) {
console.log(util.inspect(p));
}
console.log(` Now: ${data.points[0].value.doubleValue}`);
console.log(` 10 min ago: ${data.points[1].value.doubleValue}`);
if (data.points.length > 1) {
console.log(` 10 min ago: ${data.points[1].value.doubleValue}`);
}
console.log('=====');
});
// [END monitoring_read_timeseries_align]
Expand Down
6 changes: 5 additions & 1 deletion monitoring/snippets/test/metrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ describe('metrics', async () => {
timeSeries.forEach(data => {
assert.include(output, data.metric.labels.instance_name);
assert.include(output, ' Now: 0.');
assert.include(output, ' 10 min ago: 0.');
// Don't assert against a value from 10 minutes ago, if none is
// being reported by stackdriver:
if (data.points.length > 1) {
assert.include(output, ' 10 min ago: 0.');
}
});
});

Expand Down

0 comments on commit 6b900be

Please sign in to comment.