Skip to content

Commit

Permalink
chore(slo): simplify error budget calculations (#158941)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme authored Jun 5, 2023
1 parent 8e7e263 commit 4af1bd5
Show file tree
Hide file tree
Showing 12 changed files with 317 additions and 570 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/observability/server/assets/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const SLO_INDEX_TEMPLATE_NAME = '.slo-observability.sli';
export const SLO_RESOURCES_VERSION = 1;
export const SLO_INGEST_PIPELINE_NAME = `${SLO_INDEX_TEMPLATE_NAME}.monthly`;
export const SLO_DESTINATION_INDEX_NAME = `${SLO_INDEX_TEMPLATE_NAME}-v${SLO_RESOURCES_VERSION}`;
export const SLO_DESTINATION_INDEX_PATTERN = `${SLO_DESTINATION_INDEX_NAME}*`;

export const getSLOTransformId = (sloId: string, sloRevision: number) =>
`slo-${sloId}-${sloRevision}`;

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import { computeSLI } from './compute_sli';

describe('computeSLI', () => {
it('returns -1 when no total events', () => {
expect(computeSLI({ good: 100, total: 0 })).toEqual(-1);
expect(computeSLI(100, 0)).toEqual(-1);
});

it('returns the sli value', () => {
expect(computeSLI({ good: 100, total: 1000 })).toEqual(0.1);
expect(computeSLI(100, 1000)).toEqual(0.1);
});

it('returns 1 when good is greater than total events', () => {
expect(computeSLI({ good: 9999, total: 9 })).toEqual(1);
expect(computeSLI(9999, 9)).toEqual(1);
});

it('returns rounds the value to 6 digits', () => {
expect(computeSLI({ good: 33, total: 90 })).toEqual(0.366667);
expect(computeSLI(33, 90)).toEqual(0.366667);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
* 2.0.
*/

import { IndicatorData } from '../models';
import { toHighPrecision } from '../../utils/number';

const NO_DATA = -1;

export function computeSLI(sliData: Pick<IndicatorData, 'good' | 'total'>): number {
const { good, total } = sliData;
export function computeSLI(good: number, total: number): number {
if (total === 0) {
return NO_DATA;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function computeSummaryStatus(slo: SLO, sliValue: number, errorBudget: Er
return 'NO_DATA';
}

if (slo.objective.target <= sliValue) {
if (sliValue >= slo.objective.target) {
return 'HEALTHY';
} else {
return errorBudget.remaining > 0 ? 'DEGRADING' : 'VIOLATED';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { toHighPrecision } from '../../utils/number';
import { ErrorBudget } from '../models';

export function toErrorBudget(
initial: number,
consumed: number,
isEstimated: boolean = false
): ErrorBudget {
return {
initial: toHighPrecision(initial),
consumed: toHighPrecision(consumed),
remaining: toHighPrecision(1 - consumed),
isEstimated,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

export * from './compute_burn_rate';
export * from './compute_error_budget';
export * from './error_budget';
export * from './compute_sli';
export * from './compute_summary_status';
export * from './date_range';
Expand Down
Loading

0 comments on commit 4af1bd5

Please sign in to comment.