Skip to content

Commit

Permalink
update references
Browse files Browse the repository at this point in the history
  • Loading branch information
mgiota committed Mar 4, 2024
1 parent 905cf5a commit dc12fda
Show file tree
Hide file tree
Showing 157 changed files with 1,647 additions and 284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,4 @@ export const rulesLocatorID = 'RULES_LOCATOR';
import { paths } from './locators/paths';
export const observabilityPaths = paths.observability;
export type { AlertsLocatorParams } from './locators/alerts';
export { AlertsLocatorDefinition } from './locators/alerts';
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"observabilityShared",
"observabilityAIAssistant",
"ruleRegistry",
"taskManager",
"triggersActionsUi",
"security",
"share",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 * as t from 'io-ts';

import {
dateRangeSchema,
historicalSummarySchema,
statusSchema,
summarySchema,
groupSummarySchema,
} from '@kbn/slo-schema';

type Status = t.TypeOf<typeof statusSchema>;
type DateRange = t.TypeOf<typeof dateRangeSchema>;
type HistoricalSummary = t.TypeOf<typeof historicalSummarySchema>;
type Summary = t.TypeOf<typeof summarySchema>;
type GroupSummary = t.TypeOf<typeof groupSummarySchema>;

export type { DateRange, HistoricalSummary, Status, Summary, GroupSummary };
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 * as t from 'io-ts';
import { errorBudgetSchema } from '@kbn/slo-schema';

type ErrorBudget = t.TypeOf<typeof errorBudgetSchema>;

export type { ErrorBudget };
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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.
*/

export * from './common';
export { Duration, DurationUnit, toDurationUnit, toMomentUnitOfTime } from '@kbn/slo-schema';
export * from './error_budget';
export * from './indicators';
export * from './slo';
export * from './time_window';
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 * as t from 'io-ts';
import {
apmTransactionDurationIndicatorSchema,
apmTransactionErrorRateIndicatorSchema,
indicatorDataSchema,
indicatorSchema,
indicatorTypesSchema,
kqlCustomIndicatorSchema,
metricCustomIndicatorSchema,
} from '@kbn/slo-schema';

type APMTransactionErrorRateIndicator = t.TypeOf<typeof apmTransactionErrorRateIndicatorSchema>;
type APMTransactionDurationIndicator = t.TypeOf<typeof apmTransactionDurationIndicatorSchema>;
type KQLCustomIndicator = t.TypeOf<typeof kqlCustomIndicatorSchema>;
type MetricCustomIndicator = t.TypeOf<typeof metricCustomIndicatorSchema>;
type Indicator = t.TypeOf<typeof indicatorSchema>;
type IndicatorTypes = t.TypeOf<typeof indicatorTypesSchema>;
type IndicatorData = t.TypeOf<typeof indicatorDataSchema>;

export type {
Indicator,
IndicatorTypes,
APMTransactionErrorRateIndicator,
APMTransactionDurationIndicator,
KQLCustomIndicator,
MetricCustomIndicator,
IndicatorData,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 * as t from 'io-ts';
import { sloIdSchema, sloSchema, sloWithSummarySchema } from '@kbn/slo-schema';

type SLO = t.TypeOf<typeof sloSchema>;
type SLOId = t.TypeOf<typeof sloIdSchema>;
type SLOWithSummary = t.TypeOf<typeof sloWithSummarySchema>;
type StoredSLO = t.OutputOf<typeof sloSchema>;

export type { SLO, SLOWithSummary, SLOId, StoredSLO };
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 {
calendarAlignedTimeWindowSchema,
rollingTimeWindowSchema,
timeWindowSchema,
} from '@kbn/slo-schema';
import moment from 'moment';
import * as t from 'io-ts';

type TimeWindow = t.TypeOf<typeof timeWindowSchema>;
type RollingTimeWindow = t.TypeOf<typeof rollingTimeWindowSchema>;
type CalendarAlignedTimeWindow = t.TypeOf<typeof calendarAlignedTimeWindowSchema>;

export type { RollingTimeWindow, TimeWindow, CalendarAlignedTimeWindow };

export function toCalendarAlignedTimeWindowMomentUnit(
timeWindow: CalendarAlignedTimeWindow
): moment.unitOfTime.StartOf {
const unit = timeWindow.duration.unit;
switch (unit) {
case 'w':
return 'isoWeeks';
case 'M':
return 'months';
default:
throw new Error(`Invalid calendar aligned time window duration unit: ${unit}`);
}
}

export function toRollingTimeWindowMomentUnit(
timeWindow: RollingTimeWindow
): moment.unitOfTime.Diff {
const unit = timeWindow.duration.unit;
switch (unit) {
case 'd':
return 'days';
default:
throw new Error(`Invalid rolling time window duration unit: ${unit}`);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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 { computeBurnRate } from './compute_burn_rate';
import { toDateRange } from './date_range';
import { createSLO } from '../../services/slo/fixtures/slo';
import { ninetyDaysRolling } from '../../services/slo/fixtures/time_window';

describe('computeBurnRate', () => {
it('computes 0 when total is 0', () => {
expect(
computeBurnRate(createSLO(), {
good: 10,
total: 0,
dateRange: toDateRange(ninetyDaysRolling()),
})
).toEqual(0);
});

it('computes 0 when good is greater than total', () => {
expect(
computeBurnRate(createSLO(), {
good: 9999,
total: 1,
dateRange: toDateRange(ninetyDaysRolling()),
})
).toEqual(0);
});

it('computes the burn rate as 1x the error budget', () => {
expect(
computeBurnRate(createSLO({ objective: { target: 0.9 } }), {
good: 90,
total: 100,
dateRange: toDateRange(ninetyDaysRolling()),
})
).toEqual(1);
});

it('computes the burn rate as 10x the error budget', () => {
expect(
computeBurnRate(createSLO({ objective: { target: 0.99 } }), {
good: 90,
total: 100,
dateRange: toDateRange(ninetyDaysRolling()),
})
).toEqual(10);
});

it('computes the burn rate as 0.5x the error budget', () => {
expect(
computeBurnRate(createSLO({ objective: { target: 0.8 } }), {
good: 90,
total: 100,
dateRange: toDateRange(ninetyDaysRolling()),
})
).toEqual(0.5);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { IndicatorData, SLO } from '../models';

/**
* A Burn Rate is computed with the Indicator Data retrieved from a specific lookback period
* It tells how fast we are consumming our error budget during a specific period
*/
export function computeBurnRate(slo: SLO, sliData: IndicatorData): number {
const { good, total } = sliData;
if (total === 0 || good >= total) {
return 0;
}

const errorBudget = 1 - slo.objective.target;
const errorRate = 1 - good / total;
return toHighPrecision(errorRate / errorBudget);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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 { computeSLI } from './compute_sli';

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

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

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

it('returns rounds the value to 6 digits', () => {
expect(computeSLI(33, 90)).toEqual(0.366667);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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';

const NO_DATA = -1;

export function computeSLI(good: number, total: number): number {
if (total === 0) {
return NO_DATA;
}

return toHighPrecision(good / total);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 { createErrorBudget } from '../../services/slo/fixtures/error_budget';
import { createSLO } from '../../services/slo/fixtures/slo';
import { computeSummaryStatus } from './compute_summary_status';

describe('ComputeSummaryStatus', () => {
it("returns 'NO_DATA' when sliValue is -1", () => {
expect(computeSummaryStatus(createSLO(), -1, createErrorBudget())).toBe('NO_DATA');
});

it("returns 'HEALTHY' when sliValue >= target objective", () => {
expect(
computeSummaryStatus(createSLO({ objective: { target: 0.9 } }), 0.9, createErrorBudget())
).toBe('HEALTHY');

expect(
computeSummaryStatus(createSLO({ objective: { target: 0.9 } }), 0.99, createErrorBudget())
).toBe('HEALTHY');
});

it("returns 'DEGRADING' when sliValue < target objective with some remaining error budget", () => {
expect(
computeSummaryStatus(
createSLO({ objective: { target: 0.9 } }),
0.8,
createErrorBudget({ remaining: 0.01, consumed: 0.99 })
)
).toBe('DEGRADING');
});

it("returns 'VIOLATED' when sliValue < target objective and error budget is consummed", () => {
expect(
computeSummaryStatus(
createSLO({ objective: { target: 0.9 } }),
0.8,
createErrorBudget({ remaining: 0, consumed: 1.34 })
)
).toBe('VIOLATED');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 { ErrorBudget, SLO, Status } from '../models';

export function computeSummaryStatus(slo: SLO, sliValue: number, errorBudget: ErrorBudget): Status {
if (sliValue === -1) {
return 'NO_DATA';
}

if (sliValue >= slo.objective.target) {
return 'HEALTHY';
} else {
return errorBudget.remaining > 0 ? 'DEGRADING' : 'VIOLATED';
}
}
Loading

0 comments on commit dc12fda

Please sign in to comment.