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

feat(slo): health status #181351

Merged
merged 24 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d43a0a3
feat: create slo health route
kdelemme Apr 22, 2024
53f803d
feat: Add slo health callout on slo details page
kdelemme Apr 22, 2024
6e6ce8f
chore: refactor summary fixtures and add more tests for slo health
kdelemme Apr 22, 2024
b0d7db6
chore: Add more test scenarios
kdelemme Apr 22, 2024
84be0d4
Merge branch 'main' into slo/health-status
kdelemme Apr 23, 2024
c0127c9
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Apr 23, 2024
0ecdcf9
Update copy
kdelemme Apr 23, 2024
7f4eeba
Merge branch 'main' into slo/health-status
kdelemme Apr 23, 2024
769e195
remove added dep
kdelemme Apr 23, 2024
47f2ec2
use moment instead of date-fns
kdelemme Apr 23, 2024
1284f67
feat: Add callout on list page
kdelemme Apr 23, 2024
6760c5f
Merge branch 'main' into slo/health-status
kdelemme Apr 23, 2024
deb1808
Fix tests
kdelemme Apr 23, 2024
0c740ad
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Apr 23, 2024
36961e0
fix remote slo
kdelemme Apr 23, 2024
06d109b
Add i18n
kdelemme Apr 24, 2024
2b9c492
Add dismissible callout
kdelemme Apr 24, 2024
b65fa3d
chore: hide content by defualt
kdelemme Apr 24, 2024
f30e309
fix: click causing closing
kdelemme Apr 24, 2024
c679389
Update x-pack/plugins/observability_solution/slo/server/services/get_…
kdelemme Apr 24, 2024
4a606ee
chore: design change
kdelemme Apr 25, 2024
82df712
Merge branch 'main' into slo/health-status
kdelemme Apr 26, 2024
b81c4be
Merge branch 'main' into slo/health-status
shahzad31 Apr 30, 2024
89ea0b4
Merge branch 'main' into slo/health-status
kdelemme Apr 30, 2024
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
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 { healthStatusSchema, sloIdSchema, stateSchema } from '../../schema';
import { allOrAnyString } from '../../schema/common';

const fetchSLOHealthResponseSchema = t.array(
t.type({
sloId: sloIdSchema,
sloInstanceId: allOrAnyString,
sloRevision: t.number,
state: stateSchema,
health: t.type({
overall: healthStatusSchema,
rollup: healthStatusSchema,
summary: healthStatusSchema,
}),
})
);

const fetchSLOHealthParamsSchema = t.type({
body: t.type({
list: t.array(t.type({ sloId: sloIdSchema, sloInstanceId: allOrAnyString })),
}),
});

type FetchSLOHealthResponse = t.OutputOf<typeof fetchSLOHealthResponseSchema>;
type FetchSLOHealthParams = t.TypeOf<typeof fetchSLOHealthParamsSchema.props.body>;

export { fetchSLOHealthParamsSchema, fetchSLOHealthResponseSchema };
export type { FetchSLOHealthResponse, FetchSLOHealthParams };
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export * from './delete_instance';
export * from './fetch_historical_summary';
export * from './put_settings';
export * from './get_suggestions';
export * from './get_slo_health';
18 changes: 18 additions & 0 deletions x-pack/packages/kbn-slo-schema/src/schema/health.ts
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 * as t from 'io-ts';

const healthStatusSchema = t.union([t.literal('healthy'), t.literal('unhealthy')]);
const stateSchema = t.union([
t.literal('no_data'),
t.literal('indexing'),
t.literal('running'),
t.literal('stale'),
]);

export { healthStatusSchema, stateSchema };
1 change: 1 addition & 0 deletions x-pack/packages/kbn-slo-schema/src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from './indicators';
export * from './time_window';
export * from './slo';
export * from './settings';
export * from './health';
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const sloKeys = {
definitions: (search: string, page: number, perPage: number, includeOutdatedOnly: boolean) =>
[...sloKeys.all, 'definitions', search, page, perPage, includeOutdatedOnly] as const,
globalDiagnosis: () => [...sloKeys.all, 'globalDiagnosis'] as const,
health: (list: Array<{ sloId: string; sloInstanceId: string }>) =>
[...sloKeys.all, 'health', list] as const,
burnRates: (
sloId: string,
instanceId: string | undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 { ALL_VALUE, FetchSLOHealthResponse, SLOWithSummaryResponse } from '@kbn/slo-schema';
import { useQuery } from '@tanstack/react-query';
import { useKibana } from '../utils/kibana_react';
import { sloKeys } from './query_key_factory';

export interface UseFetchSloHealth {
data: FetchSLOHealthResponse | undefined;
isLoading: boolean;
isError: boolean;
}

export interface Params {
list: SLOWithSummaryResponse[];
}

export function useFetchSloHealth({ list }: Params): UseFetchSloHealth {
const { http } = useKibana().services;
const payload = list.map((slo) => ({
sloId: slo.id,
sloInstanceId: slo.instanceId ?? ALL_VALUE,
}));

const { isLoading, isError, data } = useQuery({
queryKey: sloKeys.health(payload),
queryFn: async ({ signal }) => {
try {
const response = await http.post<FetchSLOHealthResponse>(
'/internal/observability/slos/_health',
Copy link
Contributor

@mgiota mgiota Apr 26, 2024

Choose a reason for hiding this comment

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

@kdelemme We were discussing with @lucabelluccini about enhancing the Kibana diagnostic tool to pull from this API. One question that was brought up was the fact that it is a POST request. We can inject the appropriate 'kbn-xsrf' and 'elastic-api-version: 1' headers for this to the diagnostic tool.

What I was wondering now is the list payload that is required for this endpoint. Looking at this file, I am wondering how would we pass the list of SLOs? Looks like all requests in kibana yml file are GET requests, no? Could we make the list prop optional and if not passed, then it accepts all SLOs by default? What are your thoughts on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have to limit to the provided list because fetching all SLOs at once would be too much in some case. Same way we don't return all SLOs in the find API.

But what we can do instead, is use directly the transform stats endpoint from this diagnostic tool with the slo-* id, this will return in one request all the SLO transform stats. (I think there is still a limit on this API, like 1000)
Then the diagnostic tool could filter & transform the result to keep only the health.status part of it, or return the payload as is.

This API is already available and GET.

{
body: JSON.stringify({ list: payload }),
signal,
}
);

return response;
} catch (error) {
// ignore error
}
},
enabled: Boolean(list.length > 0),
refetchOnWindowFocus: false,
keepPreviousData: true,
});

return {
data,
isLoading,
isError,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { EventsChartPanel } from './events_chart_panel';
import { Overview } from './overview/overview';
import { SliChartPanel } from './sli_chart_panel';
import { SloDetailsAlerts } from './slo_detail_alerts';
import { SloHealthCallout } from './slo_health_callout';
import { SloRemoteCallout } from './slo_remote_callout';

export const TAB_ID_URL_PARAM = 'tabId';
Expand Down Expand Up @@ -126,6 +127,7 @@ export function SloDetails({ slo, isAutoRefreshing, selectedTabId }: Props) {
return selectedTabId === OVERVIEW_TAB_ID ? (
<EuiFlexGroup direction="column" gutterSize="xl">
<SloRemoteCallout slo={slo} />
<SloHealthCallout slo={slo} />
<EuiFlexItem>
<Overview slo={slo} />
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* 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 {
EuiButton,
EuiButtonIcon,
EuiCallOut,
EuiCopy,
EuiFlexGroup,
EuiFlexItem,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { SLOWithSummaryResponse } from '@kbn/slo-schema';
import React from 'react';
import { getSLOSummaryTransformId, getSLOTransformId } from '../../../../common/constants';
import { useFetchSloHealth } from '../../../hooks/use_fetch_slo_health';
import { useKibana } from '../../../utils/kibana_react';

export function SloHealthCallout({ slo }: { slo: SLOWithSummaryResponse }) {
const { http } = useKibana().services;
const { isLoading, isError, data } = useFetchSloHealth({ list: [slo] });

if (isLoading || isError || data === undefined || data?.length !== 1) {
return null;
}

const health = data[0].health;
if (health.overall === 'healthy') {
return null;
}

const count = health.rollup === 'unhealthy' && health.summary === 'unhealthy' ? 2 : 1;

return (
<EuiCallOut
color="danger"
iconType="warning"
title={i18n.translate('xpack.slo.sloDetails.healthCallout.title', {
defaultMessage: 'This SLO has issues with its transforms',
})}
>
<EuiFlexGroup direction="column" alignItems="flexStart">
<EuiFlexItem>
<FormattedMessage
id="xpack.slo.sloDetails.healthCallout.description"
defaultMessage="The following {count, plural, one {transform is} other {transforms are}
} in an unhealthy state:"
values={{ count }}
/>
<ul>
{health.rollup === 'unhealthy' && (
<li>
{getSLOTransformId(slo.id, slo.revision)}
<EuiCopy textToCopy={getSLOTransformId(slo.id, slo.revision)}>
{(copy) => (
<EuiButtonIcon
data-test-subj="sloSloHealthCalloutCopyButton"
aria-label={i18n.translate(
'xpack.slo.sloDetails.healthCallout.copyToClipboard',
{ defaultMessage: 'Copy to clipboard' }
)}
color="text"
iconType="copy"
onClick={copy}
/>
)}
</EuiCopy>
</li>
)}
{health.summary === 'unhealthy' && (
<li>
{getSLOSummaryTransformId(slo.id, slo.revision)}
<EuiCopy textToCopy={getSLOSummaryTransformId(slo.id, slo.revision)}>
{(copy) => (
<EuiButtonIcon
data-test-subj="sloSloHealthCalloutCopyButton"
aria-label={i18n.translate(
'xpack.slo.sloDetails.healthCallout.copyToClipboard',
{ defaultMessage: 'Copy to clipboard' }
)}
color="text"
iconType="copy"
onClick={copy}
/>
)}
</EuiCopy>
</li>
)}
</ul>
</EuiFlexItem>

<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="sloSloHealthCalloutInspectTransformButton"
color="danger"
fill
href={http?.basePath.prepend('/app/management/data/transform')}
>
<FormattedMessage
id="xpack.slo.sloDetails.healthCallout.buttonTransformLabel"
defaultMessage="Inspect transform"
/>
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiCallOut>
);
}
Loading