Skip to content

Commit a953912

Browse files
Make samples tests permissive of lack of data. (#7)
1 parent 97258d0 commit a953912

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

monitoring/snippets/metrics.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ function readTimeSeriesReduce(projectId) {
429429
client
430430
.listTimeSeries(request)
431431
.then(results => {
432+
if (results[0].length === 0) {
433+
console.log('No data');
434+
return;
435+
}
432436
const reductions = results[0][0].points;
433437

434438
console.log('Average CPU utilization across all GCE instances:');

monitoring/snippets/system-test/metrics.test.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ test(`should read time series data`, async t => {
102102
},
103103
});
104104
const output = await tools.runAsync(`${cmd} read '${filter}'`, cwd);
105+
t.true(true); // Do not fail if there is simply no data to return.
105106
timeSeries.forEach(data => {
106107
t.true(output.includes(`${data.metric.labels.instance_name}:`));
107108
data.points.forEach(point => {
@@ -187,7 +188,14 @@ test(`should read time series data reduced`, async t => {
187188
},
188189
});
189190
const output = await tools.runAsync(`${cmd} read-reduce`, cwd);
190-
t.true(output.includes(`Average CPU utilization across all GCE instances:`));
191-
t.true(output.includes(` Last 10 min`));
192-
t.true(output.includes(` 10-20 min ago`));
191+
// Special case: No output.
192+
if (output === 'No data') {
193+
t.true(output.includes('No data'));
194+
} else {
195+
t.true(
196+
output.includes(`Average CPU utilization across all GCE instances:`)
197+
);
198+
t.true(output.includes(` Last 10 min`));
199+
t.true(output.includes(` 10-20 min ago`));
200+
}
193201
});

0 commit comments

Comments
 (0)