Skip to content

Commit

Permalink
tell us which specific targets (metrics) fail for wildcarded targets (#…
Browse files Browse the repository at this point in the history
…91)

e.g. instead of:

next.heroku.front-page.sections.*.articles.min

we see:

next.heroku.front-page.sections.topStories.articles.min and next.heroku.front-page.sections.technology.articles.min

 🐿 v2.9.0
  • Loading branch information
bjfletcher authored Jun 29, 2018
1 parent 2b65d7d commit f829526
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ node_modules/@financial-times/n-gage/index.mk:

-include node_modules/@financial-times/n-gage/index.mk

IGNORE_A11Y = true

.PHONY: test

test-unit:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"homepage": "https://github.com/Financial-Times/n-health#readme",
"devDependencies": {
"@financial-times/n-gage": "^1.19.8",
"@financial-times/n-gage": "^1.19.14",
"chai": "^3.5.0",
"dotenv": "^2.0.0",
"lintspaces-cli": "^0.1.1",
Expand Down
12 changes: 8 additions & 4 deletions src/checks/graphiteThreshold.check.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,24 @@ class GraphiteThresholdCheck extends Check {

return fetch(this.sampleUrl, { headers: { key: this.ftGraphiteKey } })
.then(fetchres.json)
.then(sample => {
const failed = sample.some(result => {
return result.datapoints.some(value => {
.then(results => {
const simplifiedResults = results.map(result => {
const isFailing = result.datapoints.some(value => {
return this.direction === 'above' ?
Number(value[0]) > this.threshold :
Number(value[0]) < this.threshold;
});
return { target: result.target, isFailing };
});

const failed = simplifiedResults.some(result => result.isFailing);
const failingMetrics = simplifiedResults.filter(result => result.isFailing).map(result => result.target);

this.status = failed ? status.FAILED : status.PASSED;

// The metric crossed a threshold
this.checkOutput = failed ?
`In the last ${this.samplePeriod}, ${this.metric} has moved ${this.direction} the threshold value of ${this.threshold}.` :
`In the last ${this.samplePeriod}, the following metric(s) have moved ${this.direction} the threshold value of ${this.threshold}: \t${failingMetrics.join('\t')}` :
`No threshold error detected in graphite data for ${this.metric}.`;
})
.catch(err => {
Expand Down
8 changes: 5 additions & 3 deletions test/graphiteThreshold.check.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ describe('Graphite Threshold Check', function(){

it('should be unhealthy if any datapoints are below lower threshold', done => {
mockGraphite([
{ datapoints: [[10, 1234567890], [12, 1234567891]] },
{ datapoints: [[13, 1234567892], [14, 1234567893]] }
{ target: 'next.heroku.cpu.min', datapoints: [[10, 1234567890], [12, 1234567891]] },
{ target: 'next.heroku.disk.min', datapoints: [[10, 1234567890], [12, 1234567891]] },
{ target: 'next.heroku.memory.min', datapoints: [[13, 1234567892], [14, 1234567893]] }
]);
check = new Check(getCheckConfig({
threshold: 11,
Expand All @@ -127,14 +128,15 @@ describe('Graphite Threshold Check', function(){
check.start();
setTimeout(() => {
expect(check.getStatus().ok).to.be.false;
expect(check.getStatus().checkOutput).to.equal('In the last 10min, the following metric(s) have moved below the threshold value of 11: \tnext.heroku.cpu.min\tnext.heroku.disk.min');
done();
});
});

});

it('Should be possible to configure sample period', function(done){
mockGraphite();
mockGraphite([{ datapoints: [] }]);
check = new Check(getCheckConfig({
samplePeriod: '24h'
}));
Expand Down

0 comments on commit f829526

Please sign in to comment.