-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
157 changed files
with
1,647 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
x-pack/plugins/observability_solution/observability/server/domain/models/common.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
13 changes: 13 additions & 0 deletions
13
x-pack/plugins/observability_solution/observability/server/domain/models/error_budget.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
13 changes: 13 additions & 0 deletions
13
x-pack/plugins/observability_solution/observability/server/domain/models/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
35 changes: 35 additions & 0 deletions
35
x-pack/plugins/observability_solution/observability/server/domain/models/indicators.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
16 changes: 16 additions & 0 deletions
16
x-pack/plugins/observability_solution/observability/server/domain/models/slo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
46 changes: 46 additions & 0 deletions
46
x-pack/plugins/observability_solution/observability/server/domain/models/time_window.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...ins/observability_solution/observability/server/domain/services/compute_burn_rate.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
.../plugins/observability_solution/observability/server/domain/services/compute_burn_rate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
26 changes: 26 additions & 0 deletions
26
...k/plugins/observability_solution/observability/server/domain/services/compute_sli.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
x-pack/plugins/observability_solution/observability/server/domain/services/compute_sli.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
46 changes: 46 additions & 0 deletions
46
...bservability_solution/observability/server/domain/services/compute_summary_status.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
...ins/observability_solution/observability/server/domain/services/compute_summary_status.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
Oops, something went wrong.