Skip to content

Commit

Permalink
Make samples tests permissive of lack of data. (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesneeringer authored Oct 19, 2017
1 parent 97258d0 commit a953912
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions monitoring/snippets/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ function readTimeSeriesReduce(projectId) {
client
.listTimeSeries(request)
.then(results => {
if (results[0].length === 0) {
console.log('No data');
return;
}
const reductions = results[0][0].points;

console.log('Average CPU utilization across all GCE instances:');
Expand Down
14 changes: 11 additions & 3 deletions monitoring/snippets/system-test/metrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ test(`should read time series data`, async t => {
},
});
const output = await tools.runAsync(`${cmd} read '${filter}'`, cwd);
t.true(true); // Do not fail if there is simply no data to return.
timeSeries.forEach(data => {
t.true(output.includes(`${data.metric.labels.instance_name}:`));
data.points.forEach(point => {
Expand Down Expand Up @@ -187,7 +188,14 @@ test(`should read time series data reduced`, async t => {
},
});
const output = await tools.runAsync(`${cmd} read-reduce`, cwd);
t.true(output.includes(`Average CPU utilization across all GCE instances:`));
t.true(output.includes(` Last 10 min`));
t.true(output.includes(` 10-20 min ago`));
// Special case: No output.
if (output === 'No data') {
t.true(output.includes('No data'));
} else {
t.true(
output.includes(`Average CPU utilization across all GCE instances:`)
);
t.true(output.includes(` Last 10 min`));
t.true(output.includes(` 10-20 min ago`));
}
});

0 comments on commit a953912

Please sign in to comment.