Skip to content

Commit

Permalink
added handling of summarize(sumSeries) healthchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
AniaMakes committed Oct 25, 2021
1 parent 2656a9d commit 0f726b4
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/checks/graphiteThreshold.check.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,19 @@ class GraphiteThresholdCheck extends Check {
const results = await fetch(this.sampleUrl, {
headers: { key: this.ftGraphiteKey }
}).then(fetchres.json);

const simplifiedResults = results.map(result => {

if(result.target && result.target.includes('summarize(sumSeries')){
const fetchCountPerTimeUnit = result.datapoints.map(item => Number(item[0]));
const sumUp = (previousValue, currentValue) => previousValue + currentValue;
const talliedUp = fetchCountPerTimeUnit.reduce(sumUp);
const isFailing = this.direction === 'above' ?
Number(talliedUp) > this.threshold :
Number(talliedUp) < this.threshold;
return { target: result.target, isFailing };
}

const isFailing = result.datapoints.some(value => {
if (value[0] === null) {
// metric data is unavailable, we don't fail this threshold check if metric data is unavailable
Expand Down
83 changes: 82 additions & 1 deletion test/graphiteThreshold.check.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function mockGraphite (results) {
});
}

describe('Graphite Threshold Check', function(){
describe.only('Graphite Threshold Check', function(){

let check;

Expand Down Expand Up @@ -169,6 +169,87 @@ describe('Graphite Threshold Check', function(){
});
});

});

context('It handles summarize(sumSeries)', function () {

it('Should be healthy if sum above lower threshold', function (done) {
mockGraphite([
{
datapoints: [
[ null, 1635125640],[null,1635129240],[1,1635132840],[1,1635136440],[null,1635140040],[3,1635143640]],
target: 'summarize(sumSeries)'
}
]);
check = new Check(getCheckConfig({
threshold: 1,
direction: 'below'
}));
check.start();
setTimeout(() => {
expect(check.getStatus().ok).to.be.true;
done();
});
});

it('Should be healthy if sum below upper threshold', function (done) {
mockGraphite([
{ datapoints: [
[ null, 1635125640],[null,1635129240],[1,1635132840],[1,1635136440],[null,1635140040],[3,1635143640]],
target: 'summarize(sumSeries)'
}
]);
check = new Check(getCheckConfig({
threshold: 8
}));
check.start();
setTimeout(() => {
expect(check.getStatus().ok).to.be.true;
done();
});
});

it('Should be unhealthy if sum above lower threshold', function (done) {
mockGraphite([
{ datapoints: [
[ null, 1635125640],[null,1635129240],[1,1635132840],[1,1635136440],[null,1635140040],[3,1635143640]],
target: 'summarize(sumSeries)'

}
]);
check = new Check(getCheckConfig({
threshold: 6,
direction: 'below'
}));
check.start();
setTimeout(() => {
expect(check.getStatus().ok).to.be.false;
done();
});
});

it('Should be unhealthy if sum below upper threshold', function (done) {
mockGraphite([
{ datapoints: [
[ null, 1635125640],[null,1635129240],[1,1635132840],[1,1635136440],[null,1635140040],[3,1635143640]],
target: 'summarize(sumSeries)'

},

]);
check = new Check(getCheckConfig({
threshold: 4
}));
check.start();
setTimeout(() => {
expect(check.getStatus().ok).to.be.false;
done();
});
});




});

it('Should be possible to configure sample period', function(done){
Expand Down

0 comments on commit 0f726b4

Please sign in to comment.