Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOPS-1034 added handling of summarize(sumSeries) healthchecks #164

Merged
merged 1 commit into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
81 changes: 81 additions & 0 deletions test/graphiteThreshold.check.spec.js
Original file line number Diff line number Diff line change
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: to make the test more targeted to what we're testing, we can call the tick() function specifically instead of check.start() and assert the result of tick()
eg.

const result = await tick();

expect(result.isFailing).to.be.false;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very neat idea, but a bit out of scope - if I change it here, then I'd need to change it throughout this file - and possibly the repo. Maybe something to add to Platforms' Gardening Day?

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