-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
feat(slo): health status #181351
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 53f803d
feat: Add slo health callout on slo details page
kdelemme 6e6ce8f
chore: refactor summary fixtures and add more tests for slo health
kdelemme b0d7db6
chore: Add more test scenarios
kdelemme 84be0d4
Merge branch 'main' into slo/health-status
kdelemme c0127c9
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 0ecdcf9
Update copy
kdelemme 7f4eeba
Merge branch 'main' into slo/health-status
kdelemme 769e195
remove added dep
kdelemme 47f2ec2
use moment instead of date-fns
kdelemme 1284f67
feat: Add callout on list page
kdelemme 6760c5f
Merge branch 'main' into slo/health-status
kdelemme deb1808
Fix tests
kdelemme 0c740ad
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 36961e0
fix remote slo
kdelemme 06d109b
Add i18n
kdelemme 2b9c492
Add dismissible callout
kdelemme b65fa3d
chore: hide content by defualt
kdelemme f30e309
fix: click causing closing
kdelemme c679389
Update x-pack/plugins/observability_solution/slo/server/services/get_…
kdelemme 4a606ee
chore: design change
kdelemme 82df712
Merge branch 'main' into slo/health-status
kdelemme b81c4be
Merge branch 'main' into slo/health-status
shahzad31 89ea0b4
Merge branch 'main' into slo/health-status
kdelemme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
x-pack/packages/kbn-slo-schema/src/rest_specs/routes/get_slo_health.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 { 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 }; |
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
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 }; |
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
57 changes: 57 additions & 0 deletions
57
x-pack/plugins/observability_solution/slo/public/hooks/use_fetch_slo_health.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,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', | ||
{ | ||
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, | ||
}; | ||
} |
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
113 changes: 113 additions & 0 deletions
113
...ins/observability_solution/slo/public/pages/slo_details/components/slo_health_callout.tsx
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,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> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.