Skip to content

Commit

Permalink
[8.15] fix(slo): use correct uisettings (#193362) (#193575)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.15`:
- [fix(slo): use correct uisettings
(#193362)](#193362)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Kevin
Delemme","email":"kevin.delemme@elastic.co"},"sourceCommit":{"committedDate":"2024-09-19T17:23:55Z","message":"fix(slo):
use correct uisettings
(#193362)","sha":"92b2c0324779711b6c95b1f90027cef210401ce9","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["backport","release_note:skip","v9.0.0","backport:prev-minor","backport:prev-major","ci:project-deploy-observability","Team:obs-ux-management","v8.16.0"],"number":193362,"url":"https://github.com/elastic/kibana/pull/193362","mergeCommit":{"message":"fix(slo):
use correct uisettings
(#193362)","sha":"92b2c0324779711b6c95b1f90027cef210401ce9"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193362","number":193362,"mergeCommit":{"message":"fix(slo):
use correct uisettings
(#193362)","sha":"92b2c0324779711b6c95b1f90027cef210401ce9"}},{"branch":"8.x","label":"v8.16.0","labelRegex":"^v8.16.0$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/193457","number":193457,"state":"MERGED","mergeCommit":{"sha":"0125a030f9055117476c4139d425cd112a43e0dc","message":"[8.x]
fix(slo): use correct uisettings (#193362) (#193457)\n\n#
Backport\n\nThis will backport the following commits from `main` to
`8.x`:\n- [fix(slo): use correct
uisettings\n(#193362)](https://github.com/elastic/kibana/pull/193362)\n\n<!---
Backport version: 9.4.3 -->\n\n### Questions ?\nPlease refer to the
[Backport
tool\ndocumentation](https://github.com/sqren/backport)\n\n<!--BACKPORT
[{\"author\":{\"name\":\"Kevin\nDelemme\",\"email\":\"kevin.delemme@elastic.co\"},\"sourceCommit\":{\"committedDate\":\"2024-09-19T17:23:55Z\",\"message\":\"fix(slo):\nuse
correct
uisettings\n(#193362)\",\"sha\":\"92b2c0324779711b6c95b1f90027cef210401ce9\",\"branchLabelMapping\":{\"^v9.0.0$\":\"main\",\"^v8.16.0$\":\"8.x\",\"^v(\\\\d+).(\\\\d+).\\\\d+$\":\"$1.$2\"}},\"sourcePullRequest\":{\"labels\":[\"backport\",\"release_note:skip\",\"v9.0.0\",\"backport:prev-minor\",\"backport:prev-major\",\"ci:project-deploy-observability\",\"Team:obs-ux-management\",\"v8.16.0\"],\"title\":\"fix(slo):\nuse
correct\nuisettings\",\"number\":193362,\"url\":\"https://github.com/elastic/kibana/pull/193362\",\"mergeCommit\":{\"message\":\"fix(slo):\nuse
correct
uisettings\n(#193362)\",\"sha\":\"92b2c0324779711b6c95b1f90027cef210401ce9\"}},\"sourceBranch\":\"main\",\"suggestedTargetBranches\":[\"8.x\"],\"targetPullRequestStates\":[{\"branch\":\"main\",\"label\":\"v9.0.0\",\"branchLabelMappingKey\":\"^v9.0.0$\",\"isSourceBranch\":true,\"state\":\"MERGED\",\"url\":\"https://github.com/elastic/kibana/pull/193362\",\"number\":193362,\"mergeCommit\":{\"message\":\"fix(slo):\nuse
correct
uisettings\n(#193362)\",\"sha\":\"92b2c0324779711b6c95b1f90027cef210401ce9\"}},{\"branch\":\"8.x\",\"label\":\"v8.16.0\",\"branchLabelMappingKey\":\"^v8.16.0$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"}]}]\nBACKPORT-->\n\nCo-authored-by:
Kevin Delemme <kevin.delemme@elastic.co>"}}]}] BACKPORT-->
  • Loading branch information
kdelemme authored Sep 25, 2024
1 parent da3b27f commit bb0b2c9
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import { i18n } from '@kbn/i18n';
import { GetPreviewDataResponse, SLOWithSummaryResponse } from '@kbn/slo-schema';
import moment from 'moment';
import React, { useRef } from 'react';
import { TimeBounds } from '../../../slo_details/types';
import { getBrushTimeBounds } from '../../../../utils/slo/duration';
import { useKibana } from '../../../../utils/kibana_react';
import { openInDiscover } from '../../../../utils/slo/get_discover_link';
import { TimeBounds } from '../../pages/slo_details/types';
import { getBrushTimeBounds } from '../../utils/slo/duration';
import { useKibana } from '../../utils/kibana_react';
import { openInDiscover } from '../../utils/slo/get_discover_link';

export interface Props {
data: GetPreviewDataResponse;
Expand Down Expand Up @@ -85,7 +85,7 @@ export function GoodBadEventsChart({
to: moment(datanum.x).add(intervalInMilliseconds, 'ms').toISOString(),
mode: 'absolute' as const,
};
openInDiscover(discover, slo, isBad, !isBad, timeRange);
openInDiscover({ slo, showBad: isBad, showGood: !isBad, timeRange, discover, uiSettings });
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { SloTabId } from './slo_details';
import { useGetPreviewData } from '../../../hooks/use_get_preview_data';
import { useKibana } from '../../../utils/kibana_react';
import { COMPARATOR_MAPPING } from '../../slo_edit/constants';
import { GoodBadEventsChart } from '../../slos/components/common/good_bad_events_chart';
import { GoodBadEventsChart } from '../../../components/good_bad_events_chart/good_bad_events_chart';
import { getDiscoverLink } from '../../../utils/slo/get_discover_link';

export interface Props {
Expand Down Expand Up @@ -173,10 +173,15 @@ export function EventsChartPanel({ slo, range, selectedTabId, onBrushed }: Props
<EuiFlexItem grow={0}>
<EuiLink
color="text"
href={getDiscoverLink(discover, slo, {
from: 'now-24h',
to: 'now',
mode: 'relative',
href={getDiscoverLink({
slo,
timeRange: {
from: 'now-24h',
to: 'now',
mode: 'relative',
},
discover,
uiSettings,
})}
data-test-subj="sloDetailDiscoverLink"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import moment from 'moment';
import React, { useState } from 'react';
import { useFormContext } from 'react-hook-form';
import { useKibana } from '../../../../utils/kibana_react';
import { GoodBadEventsChart } from '../../../slos/components/common/good_bad_events_chart';
import { GoodBadEventsChart } from '../../../../components/good_bad_events_chart/good_bad_events_chart';
import { useDebouncedGetPreviewData } from '../../hooks/use_preview';
import { useSectionFormValidation } from '../../hooks/use_section_form_validation';
import { CreateSLOForm } from '../../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ import { i18n } from '@kbn/i18n';
import { buildEsQuery } from '@kbn/observability-plugin/public';
import { v4 } from 'uuid';
import { isEmpty } from 'lodash';
import { getEsQueryConfig } from '@kbn/data-plugin/public';
import { IUiSettingsClient } from '@kbn/core/public';

function createDiscoverLocator(
slo: SLOWithSummaryResponse,
function createDiscoverLocator({
slo,
showBad = false,
showGood = false,
timeRange?: TimeRange
) {
timeRange,
uiSettings,
}: {
slo: SLOWithSummaryResponse;
showBad: boolean;
showGood: boolean;
timeRange: TimeRange;
uiSettings?: IUiSettingsClient;
}) {
const indexId = v4();
const filters: Filter[] = [];

Expand All @@ -42,8 +51,17 @@ function createDiscoverLocator(
const totalFilters = kqlWithFiltersSchema.is(slo.indicator.params.total)
? slo.indicator.params.total.filters
: [];
const customGoodFilter = buildEsQuery({ kuery: goodKuery, filters: goodFilters });
const customTotalFilter = buildEsQuery({ kuery: totalKuery, filters: totalFilters });

const customGoodFilter = buildEsQuery({
kuery: goodKuery,
filters: goodFilters,
...(uiSettings && { config: getEsQueryConfig(uiSettings) }),
});
const customTotalFilter = buildEsQuery({
kuery: totalKuery,
filters: totalFilters,
...(uiSettings && { config: getEsQueryConfig(uiSettings) }),
});
const customBadFilter = { bool: { filter: customTotalFilter, must_not: customGoodFilter } };

filters.push({
Expand Down Expand Up @@ -144,22 +162,42 @@ function createDiscoverLocator(
};
}

export function getDiscoverLink(
discover: DiscoverStart,
slo: SLOWithSummaryResponse,
timeRange: TimeRange
) {
const config = createDiscoverLocator(slo, false, false, timeRange);
return discover?.locator?.getRedirectUrl(config);
export function getDiscoverLink({
slo,
timeRange,
discover,
uiSettings,
}: {
slo: SLOWithSummaryResponse;
timeRange: TimeRange;
discover?: DiscoverStart;
uiSettings?: IUiSettingsClient;
}) {
const locatorConfig = createDiscoverLocator({
slo,
showBad: false,
showGood: false,
timeRange,
uiSettings,
});
return discover?.locator?.getRedirectUrl(locatorConfig);
}

export function openInDiscover(
discover: DiscoverStart,
slo: SLOWithSummaryResponse,
export function openInDiscover({
slo,
showBad = false,
showGood = false,
timeRange?: TimeRange
) {
const config = createDiscoverLocator(slo, showBad, showGood, timeRange);
discover?.locator?.navigate(config);
timeRange,
discover,
uiSettings,
}: {
slo: SLOWithSummaryResponse;
showBad: boolean;
showGood: boolean;
timeRange: TimeRange;
discover?: DiscoverStart;
uiSettings?: IUiSettingsClient;
}) {
const locatorConfig = createDiscoverLocator({ slo, showBad, showGood, timeRange, uiSettings });
discover?.locator?.navigate(locatorConfig);
}

0 comments on commit bb0b2c9

Please sign in to comment.