Skip to content

Commit

Permalink
Change line chart color based on burn rate status or SLO status when …
Browse files Browse the repository at this point in the history
…used outside of the burn rate panel
  • Loading branch information
kdelemme committed Oct 31, 2024
1 parent f1f10fb commit a5fdf77
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export function ErrorRatePanel({ alert, slo, isLoading }: Props) {
dataTimeRange={dataTimeRange}
alertTimeRange={alertTimeRange}
threshold={actionGroupWindow!.burnRateThreshold}
variant="danger"
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface Props {
alertTimeRange?: TimeRange;
annotations?: AlertAnnotation[];
onBrushed?: (timeBounds: TimeBounds) => void;
variant?: 'success' | 'danger';
}

export function ErrorRateChart({
Expand All @@ -30,6 +31,7 @@ export function ErrorRateChart({
alertTimeRange,
annotations,
onBrushed,
variant = 'success',
}: Props) {
const {
lens: { EmbeddableComponent },
Expand All @@ -40,6 +42,7 @@ export function ErrorRateChart({
alertTimeRange,
dataTimeRange,
annotations,
variant,
});
const delayInSeconds = getDelayInSecondsFromSLO(slo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface Props {
dataTimeRange: TimeRange;
alertTimeRange?: TimeRange;
annotations?: AlertAnnotation[];
variant: 'success' | 'danger';
}

export function useLensDefinition({
Expand All @@ -39,9 +40,12 @@ export function useLensDefinition({
dataTimeRange,
alertTimeRange,
annotations,
variant,
}: Props): TypedLensByValueInput['attributes'] {
const { euiTheme } = useEuiTheme();

const lineColor = variant === 'danger' ? euiTheme.colors.danger : euiTheme.colors.success;

const interval = getLensDefinitionInterval(dataTimeRange, slo);

return {
Expand Down Expand Up @@ -92,7 +96,7 @@ export function useLensDefinition({
yConfig: [
{
forAccessor: '9f69a7b0-34b9-4b76-9ff7-26dc1a06ec14',
color: euiTheme.colors.primary,
color: lineColor,
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ErrorRateChart } from '../../../../components/slo/error_rate_chart';
import { useFetchSloBurnRates } from '../../../../hooks/use_fetch_slo_burn_rates';
import { BurnRateWindow, useFetchBurnRateWindows } from '../../hooks/use_fetch_burn_rate_windows';
import { BurnRateStatus } from './burn_rate_status';
import { getStatus } from './utils';

interface Props {
slo: SLOWithSummaryResponse;
Expand Down Expand Up @@ -48,6 +49,8 @@ export function BurnRatePanel({ slo, isAutoRefreshing }: Props) {
data?.burnRates.find((curr) => curr.name === shortWindowName(selectedWindow.name))?.burnRate ??
0;

const currentStatus = getStatus(threshold, longWindowBurnRate, shortWindowbBurnRate);

return (
<EuiPanel paddingSize="m" color="transparent" hasBorder data-test-subj="burnRatePanel">
<EuiFlexGroup direction="column" gutterSize="m">
Expand Down Expand Up @@ -97,6 +100,7 @@ export function BurnRatePanel({ slo, isAutoRefreshing }: Props) {
to: new Date(),
}}
threshold={threshold}
variant={currentStatus === 'BREACHED' ? 'danger' : 'success'}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import numeral from '@elastic/numeral';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { BurnRateWindow } from '../../hooks/use_fetch_burn_rate_windows';
import { getStatus } from './utils';

export interface BurnRateParams {
isLoading: boolean;
Expand All @@ -26,7 +27,7 @@ export interface BurnRateParams {
shortWindowBurnRate: number;
}

type Status = 'BREACHED' | 'RECOVERING' | 'INCREASING' | 'ACCEPTABLE';
export type Status = 'BREACHED' | 'RECOVERING' | 'INCREASING' | 'ACCEPTABLE';

export function BurnRateStatus({
selectedWindow,
Expand Down Expand Up @@ -84,25 +85,6 @@ export function BurnRateStatus({
);
}

function getStatus(
threshold: number,
longWindowBurnRate: number,
shortWindowBurnRate: number
): Status {
const isLongWindowBurnRateAboveThreshold = longWindowBurnRate > threshold;
const isShortWindowBurnRateAboveThreshold = shortWindowBurnRate > threshold;
const areBothBurnRatesAboveThreshold =
isLongWindowBurnRateAboveThreshold && isShortWindowBurnRateAboveThreshold;

return areBothBurnRatesAboveThreshold
? 'BREACHED'
: isLongWindowBurnRateAboveThreshold && !isShortWindowBurnRateAboveThreshold
? 'RECOVERING'
: !isLongWindowBurnRateAboveThreshold && isShortWindowBurnRateAboveThreshold
? 'INCREASING'
: 'ACCEPTABLE';
}

function getColor(status: Status) {
return status === 'BREACHED' ? 'danger' : status === 'INCREASING' ? 'warning' : 'success';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 type { Status } from './burn_rate_status';

export function getStatus(
threshold: number,
longWindowBurnRate: number,
shortWindowBurnRate: number
): Status {
const isLongWindowBurnRateAboveThreshold = longWindowBurnRate > threshold;
const isShortWindowBurnRateAboveThreshold = shortWindowBurnRate > threshold;
const areBothBurnRatesAboveThreshold =
isLongWindowBurnRateAboveThreshold && isShortWindowBurnRateAboveThreshold;

return areBothBurnRatesAboveThreshold
? 'BREACHED'
: isLongWindowBurnRateAboveThreshold && !isShortWindowBurnRateAboveThreshold
? 'RECOVERING'
: !isLongWindowBurnRateAboveThreshold && isShortWindowBurnRateAboveThreshold
? 'INCREASING'
: 'ACCEPTABLE';
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ export function SLODetailsHistory({ slo, isAutoRefreshing, selectedTabId }: Prop
</h2>
</EuiTitle>
</EuiFlexItem>
<ErrorRateChart slo={slo} dataTimeRange={range} onBrushed={onBrushed} />
<ErrorRateChart
slo={slo}
dataTimeRange={range}
onBrushed={onBrushed}
variant={['VIOLATED', 'DEGRADING'].includes(slo.summary.status) ? 'danger' : 'success'}
/>
</EuiFlexGroup>
</EuiPanel>

Expand Down

0 comments on commit a5fdf77

Please sign in to comment.