Skip to content

Commit

Permalink
chore(slo): rename resource constants and simplify resource installat…
Browse files Browse the repository at this point in the history
…ion process' (elastic#208264)
  • Loading branch information
kdelemme authored Jan 27, 2025
1 parent 45634ed commit d00d867
Show file tree
Hide file tree
Showing 58 changed files with 324 additions and 644 deletions.
40 changes: 18 additions & 22 deletions x-pack/solutions/observability/plugins/slo/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,25 @@ export const SLO_MODEL_VERSION = 2;
export const SLO_RESOURCES_VERSION = 3.4;
export const SLO_RESOURCES_VERSION_MAJOR = 3;

export const SLO_COMPONENT_TEMPLATE_MAPPINGS_NAME = '.slo-observability.sli-mappings';
export const SLO_COMPONENT_TEMPLATE_SETTINGS_NAME = '.slo-observability.sli-settings';

export const SLO_INDEX_TEMPLATE_NAME = '.slo-observability.sli';
export const SLO_INDEX_TEMPLATE_PATTERN = `.slo-observability.sli-*`;

export const SLO_DESTINATION_INDEX_NAME = `.slo-observability.sli-v${SLO_RESOURCES_VERSION}`;
export const SLO_DESTINATION_INDEX_PATTERN = `.slo-observability.sli-v${SLO_RESOURCES_VERSION_MAJOR}*`;

export const SLO_INGEST_PIPELINE_INDEX_NAME_PREFIX = `.slo-observability.sli-v${SLO_RESOURCES_VERSION}.`;

export const SLO_SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME = '.slo-observability.summary-mappings';
export const SLO_SUMMARY_COMPONENT_TEMPLATE_SETTINGS_NAME = '.slo-observability.summary-settings';
export const SLO_SUMMARY_INDEX_TEMPLATE_NAME = '.slo-observability.summary';
export const SLO_SUMMARY_INDEX_TEMPLATE_PATTERN = `.slo-observability.summary-*`;

export const SLO_SUMMARY_DESTINATION_INDEX_NAME = `.slo-observability.summary-v${SLO_RESOURCES_VERSION}`; // store the summary document generated by transform
export const SLO_SUMMARY_TEMP_INDEX_NAME = `.slo-observability.summary-v${SLO_RESOURCES_VERSION}.temp`; // store the temporary summary document
export const SLO_SUMMARY_DESTINATION_INDEX_PATTERN = `.slo-observability.summary-v${SLO_RESOURCES_VERSION_MAJOR}*`; // include temp and non-temp summary indices
export const SLI_COMPONENT_TEMPLATE_MAPPINGS_NAME = '.slo-observability.sli-mappings';
export const SLI_COMPONENT_TEMPLATE_SETTINGS_NAME = '.slo-observability.sli-settings';
export const SLI_INDEX_TEMPLATE_NAME = '.slo-observability.sli';
export const SLI_INDEX_TEMPLATE_PATTERN = `.slo-observability.sli-*`;
export const SLI_DESTINATION_INDEX_NAME = `.slo-observability.sli-v${SLO_RESOURCES_VERSION}`;
export const SLI_DESTINATION_INDEX_PATTERN = `.slo-observability.sli-v${SLO_RESOURCES_VERSION_MAJOR}*`;
export const SLI_INGEST_PIPELINE_INDEX_NAME_PREFIX = `.slo-observability.sli-v${SLO_RESOURCES_VERSION}.`;

export const SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME = '.slo-observability.summary-mappings';
export const SUMMARY_COMPONENT_TEMPLATE_SETTINGS_NAME = '.slo-observability.summary-settings';
export const SUMMARY_INDEX_TEMPLATE_NAME = '.slo-observability.summary';
export const SUMMARY_INDEX_TEMPLATE_PATTERN = `.slo-observability.summary-*`;
export const SUMMARY_DESTINATION_INDEX_NAME = `.slo-observability.summary-v${SLO_RESOURCES_VERSION}`; // store the summary document generated by transform
export const SUMMARY_TEMP_INDEX_NAME = `.slo-observability.summary-v${SLO_RESOURCES_VERSION}.temp`; // store the temporary summary document
export const SUMMARY_DESTINATION_INDEX_PATTERN = `.slo-observability.summary-v${SLO_RESOURCES_VERSION_MAJOR}*`; // include temp and non-temp summary indices

export const getSLOTransformId = (sloId: string, sloRevision: number) =>
`slo-${sloId}-${sloRevision}`;

export const DEFAULT_SLO_PAGE_SIZE = 25;
export const DEFAULT_SLO_GROUPS_PAGE_SIZE = 25;

export const getSLOSummaryTransformId = (sloId: string, sloRevision: number) =>
`slo-summary-${sloId}-${sloRevision}`;

Expand All @@ -97,3 +90,6 @@ export const SYNTHETICS_DEFAULT_GROUPINGS = ['monitor.name', 'observer.geo.name'

// in hours
export const DEFAULT_STALE_SLO_THRESHOLD_HOURS = 48;

export const DEFAULT_SLO_PAGE_SIZE = 25;
export const DEFAULT_SLO_GROUPS_PAGE_SIZE = 25;
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
*/

import { getListOfSloSummaryIndices } from './summary_indices';
import {
DEFAULT_STALE_SLO_THRESHOLD_HOURS,
SLO_SUMMARY_DESTINATION_INDEX_PATTERN,
} from './constants';
import { DEFAULT_STALE_SLO_THRESHOLD_HOURS, SUMMARY_DESTINATION_INDEX_PATTERN } from './constants';

describe('getListOfSloSummaryIndices', () => {
it('should return default index if disabled', function () {
Expand All @@ -19,7 +16,7 @@ describe('getListOfSloSummaryIndices', () => {
staleThresholdInHours: DEFAULT_STALE_SLO_THRESHOLD_HOURS,
};
const result = getListOfSloSummaryIndices(settings, []);
expect(result).toBe(SLO_SUMMARY_DESTINATION_INDEX_PATTERN);
expect(result).toBe(SUMMARY_DESTINATION_INDEX_PATTERN);
});

it('should return all remote clusters when enabled', function () {
Expand All @@ -34,7 +31,7 @@ describe('getListOfSloSummaryIndices', () => {
];
const result = getListOfSloSummaryIndices(settings, clustersByName);
expect(result).toBe(
`${SLO_SUMMARY_DESTINATION_INDEX_PATTERN},cluster1:${SLO_SUMMARY_DESTINATION_INDEX_PATTERN},cluster2:${SLO_SUMMARY_DESTINATION_INDEX_PATTERN}`
`${SUMMARY_DESTINATION_INDEX_PATTERN},cluster1:${SUMMARY_DESTINATION_INDEX_PATTERN},cluster2:${SUMMARY_DESTINATION_INDEX_PATTERN}`
);
});

Expand All @@ -50,7 +47,7 @@ describe('getListOfSloSummaryIndices', () => {
];
const result = getListOfSloSummaryIndices(settings, clustersByName);
expect(result).toBe(
`${SLO_SUMMARY_DESTINATION_INDEX_PATTERN},cluster1:${SLO_SUMMARY_DESTINATION_INDEX_PATTERN}`
`${SUMMARY_DESTINATION_INDEX_PATTERN},cluster1:${SUMMARY_DESTINATION_INDEX_PATTERN}`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
*/

import { GetSLOSettingsResponse } from '@kbn/slo-schema';
import { SLO_SUMMARY_DESTINATION_INDEX_PATTERN } from './constants';
import { SUMMARY_DESTINATION_INDEX_PATTERN } from './constants';

export const getListOfSloSummaryIndices = (
settings: GetSLOSettingsResponse,
clustersByName: Array<{ name: string; isConnected: boolean }>
) => {
const { useAllRemoteClusters, selectedRemoteClusters } = settings;
if (!useAllRemoteClusters && selectedRemoteClusters.length === 0) {
return SLO_SUMMARY_DESTINATION_INDEX_PATTERN;
return SUMMARY_DESTINATION_INDEX_PATTERN;
}

const indices: string[] = [SLO_SUMMARY_DESTINATION_INDEX_PATTERN];
const indices: string[] = [SUMMARY_DESTINATION_INDEX_PATTERN];
clustersByName.forEach(({ name, isConnected }) => {
if (isConnected && (useAllRemoteClusters || selectedRemoteClusters.includes(name))) {
indices.push(`${name}:${SLO_SUMMARY_DESTINATION_INDEX_PATTERN}`);
indices.push(`${name}:${SUMMARY_DESTINATION_INDEX_PATTERN}`);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TypedLensByValueInput } from '@kbn/lens-plugin/public';
import { ALL_VALUE, SLOWithSummaryResponse } from '@kbn/slo-schema';
import moment from 'moment';
import { v4 as uuidv4 } from 'uuid';
import { SLO_DESTINATION_INDEX_PATTERN } from '../../../../common/constants';
import { SLI_DESTINATION_INDEX_PATTERN } from '../../../../common/constants';
import { getLensDefinitionInterval } from './utils';

export interface TimeRange {
Expand Down Expand Up @@ -487,8 +487,8 @@ export function useLensDefinition({
'32ca1ad4-81c0-4daf-b9d1-07118044bdc5': {
id: '32ca1ad4-81c0-4daf-b9d1-07118044bdc5',
title: !!slo.remote
? `${slo.remote.remoteName}:${SLO_DESTINATION_INDEX_PATTERN}`
: SLO_DESTINATION_INDEX_PATTERN,
? `${slo.remote.remoteName}:${SLI_DESTINATION_INDEX_PATTERN}`
: SLI_DESTINATION_INDEX_PATTERN,
timeFieldName: '@timestamp',
sourceFilters: [],
fieldFormats: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import { debounce } from 'lodash';
import React, { useEffect, useMemo, useState } from 'react';
import { sloAppId } from '../../../../../common';
import { SLO_SUMMARY_DESTINATION_INDEX_NAME } from '../../../../../common/constants';
import { SUMMARY_DESTINATION_INDEX_NAME } from '../../../../../common/constants';
import { useCreateDataView } from '../../../../hooks/use_create_data_view';
import { useFetchSloGroups } from '../../../../hooks/use_fetch_slo_groups';
import { SLI_OPTIONS } from '../../../../pages/slo_edit/constants';
Expand Down Expand Up @@ -86,7 +86,7 @@ export function SloGroupFilters({ selectedFilters, onSelected }: Props) {
: []),
];
const { dataView } = useCreateDataView({
indexPatternString: SLO_SUMMARY_DESTINATION_INDEX_NAME,
indexPatternString: SUMMARY_DESTINATION_INDEX_NAME,
});
const [selectedGroupBy, setSelectedGroupBy] =
useState<GroupBy>(selectedFilters.groupBy) ?? 'status';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { useMemo } from 'react';
import {
DEFAULT_SLO_GROUPS_PAGE_SIZE,
SLO_SUMMARY_DESTINATION_INDEX_PATTERN,
SUMMARY_DESTINATION_INDEX_PATTERN,
} from '../../common/constants';
import type { GroupByField } from '../pages/slos/types';
import { SearchState } from '../pages/slos/hooks/use_url_search_state';
Expand Down Expand Up @@ -65,7 +65,7 @@ export function useFetchSloGroups({
} = useKibana().services;

const { dataView } = useCreateDataView({
indexPatternString: SLO_SUMMARY_DESTINATION_INDEX_PATTERN,
indexPatternString: SUMMARY_DESTINATION_INDEX_PATTERN,
});

const filters = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import { i18n } from '@kbn/i18n';
import { FindSLOResponse } from '@kbn/slo-schema';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { useMemo } from 'react';
import {
DEFAULT_SLO_PAGE_SIZE,
SLO_SUMMARY_DESTINATION_INDEX_PATTERN,
} from '../../common/constants';
import { DEFAULT_SLO_PAGE_SIZE, SUMMARY_DESTINATION_INDEX_PATTERN } from '../../common/constants';
import { SearchState } from '../pages/slos/hooks/use_url_search_state';
import { useKibana } from './use_kibana';
import { sloKeys } from './query_key_factory';
Expand Down Expand Up @@ -63,7 +60,7 @@ export function useFetchSloList({
const queryClient = useQueryClient();

const { dataView } = useCreateDataView({
indexPatternString: SLO_SUMMARY_DESTINATION_INDEX_PATTERN,
indexPatternString: SUMMARY_DESTINATION_INDEX_PATTERN,
});

const filters = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { SLO_SUMMARY_DESTINATION_INDEX_PATTERN } from '../../../../../../common/constants';
import { SUMMARY_DESTINATION_INDEX_PATTERN } from '../../../../../../common/constants';
import { GroupSummary } from '@kbn/slo-schema';
import { useGroupName } from './use_group_name';

Expand Down Expand Up @@ -57,18 +57,14 @@ describe('useGroupName', () => {
});

it('returns the group name for local index', () => {
const groupName = useGroupName(
'_index',
SLO_SUMMARY_DESTINATION_INDEX_PATTERN,
{} as GroupSummary
);
const groupName = useGroupName('_index', SUMMARY_DESTINATION_INDEX_PATTERN, {} as GroupSummary);
expect(groupName).toBe('Local Kibana');
});

it('returns the group name for remote index', () => {
const groupName = useGroupName(
'_index',
`my-remote-cluster:${SLO_SUMMARY_DESTINATION_INDEX_PATTERN}`,
`my-remote-cluster:${SUMMARY_DESTINATION_INDEX_PATTERN}`,
{} as GroupSummary
);
expect(groupName).toBe('Remote Cluster: my-remote-cluster');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { i18n } from '@kbn/i18n';
import { GetOverviewResponse } from '@kbn/slo-schema/src/rest_specs/routes/get_overview';
import { useQuery } from '@tanstack/react-query';
import { useMemo } from 'react';
import { SLO_SUMMARY_DESTINATION_INDEX_PATTERN } from '../../../../common/constants';
import { SUMMARY_DESTINATION_INDEX_PATTERN } from '../../../../common/constants';
import { sloKeys } from '../../../hooks/query_key_factory';
import { useCreateDataView } from '../../../hooks/use_create_data_view';
import { usePluginContext } from '../../../hooks/use_plugin_context';
Expand Down Expand Up @@ -45,7 +45,7 @@ export function useFetchSLOsOverview({
} = useKibana().services;

const { dataView } = useCreateDataView({
indexPatternString: SLO_SUMMARY_DESTINATION_INDEX_PATTERN,
indexPatternString: SUMMARY_DESTINATION_INDEX_PATTERN,
});

const filters = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
* 2.0.
*/
import type { ClusterPutComponentTemplateRequest } from '@elastic/elasticsearch/lib/api/types';
import { SLO_RESOURCES_VERSION } from '../../../common/constants';
import {
SLI_COMPONENT_TEMPLATE_MAPPINGS_NAME,
SLO_RESOURCES_VERSION,
} from '../../../common/constants';

export const getSLOMappingsTemplate = (name: string): ClusterPutComponentTemplateRequest => ({
name,
export const SLI_MAPPINGS_TEMPLATE: ClusterPutComponentTemplateRequest = {
name: SLI_COMPONENT_TEMPLATE_MAPPINGS_NAME,
template: {
mappings: {
properties: {
Expand Down Expand Up @@ -109,4 +112,4 @@ export const getSLOMappingsTemplate = (name: string): ClusterPutComponentTemplat
managed: true,
managed_by: 'observability',
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
* 2.0.
*/

import { SLO_RESOURCES_VERSION } from '../../../common/constants';
import {
SLI_COMPONENT_TEMPLATE_SETTINGS_NAME,
SLO_RESOURCES_VERSION,
} from '../../../common/constants';

export const getSLOSettingsTemplate = (name: string) => ({
name,
export const SLI_SETTINGS_TEMPLATE = {
name: SLI_COMPONENT_TEMPLATE_SETTINGS_NAME,
template: {
settings: {
auto_expand_replicas: '0-1',
Expand All @@ -21,4 +24,4 @@ export const getSLOSettingsTemplate = (name: string) => ({
managed: true,
managed_by: 'observability',
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
* 2.0.
*/
import type { ClusterPutComponentTemplateRequest } from '@elastic/elasticsearch/lib/api/types';
import { SLO_RESOURCES_VERSION } from '../../../common/constants';
import {
SLO_RESOURCES_VERSION,
SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME,
} from '../../../common/constants';

export const getSLOSummaryMappingsTemplate = (
name: string
): ClusterPutComponentTemplateRequest => ({
name,
export const SUMMARY_MAPPINGS_TEMPLATE: ClusterPutComponentTemplateRequest = {
name: SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME,
template: {
mappings: {
properties: {
Expand Down Expand Up @@ -240,4 +241,4 @@ export const getSLOSummaryMappingsTemplate = (
managed: true,
managed_by: 'observability',
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
* 2.0.
*/

import { SLO_RESOURCES_VERSION } from '../../../common/constants';
import {
SLO_RESOURCES_VERSION,
SUMMARY_COMPONENT_TEMPLATE_SETTINGS_NAME,
} from '../../../common/constants';

export const getSLOSummarySettingsTemplate = (name: string) => ({
name,
export const SUMMARY_SETTINGS_TEMPLATE = {
name: SUMMARY_COMPONENT_TEMPLATE_SETTINGS_NAME,
template: {
settings: {
auto_expand_replicas: '0-1',
Expand All @@ -21,4 +24,4 @@ export const getSLOSummarySettingsTemplate = (name: string) => ({
managed: true,
managed_by: 'observability',
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
* 2.0.
*/

import { SLO_RESOURCES_VERSION } from '../../../common/constants';
import {
SLI_COMPONENT_TEMPLATE_MAPPINGS_NAME,
SLI_COMPONENT_TEMPLATE_SETTINGS_NAME,
SLI_INDEX_TEMPLATE_NAME,
SLI_INDEX_TEMPLATE_PATTERN,
SLO_RESOURCES_VERSION,
} from '../../../common/constants';

export const getSLOIndexTemplate = (name: string, indexPattern: string, composedOf: string[]) => ({
name,
index_patterns: [indexPattern],
composed_of: composedOf,
export const SLI_INDEX_TEMPLATE = {
name: SLI_INDEX_TEMPLATE_NAME,
index_patterns: [SLI_INDEX_TEMPLATE_PATTERN],
composed_of: [SLI_COMPONENT_TEMPLATE_MAPPINGS_NAME, SLI_COMPONENT_TEMPLATE_SETTINGS_NAME],
priority: 500,
_meta: {
description: 'Template for SLO rollup data',
version: SLO_RESOURCES_VERSION,
managed: true,
managed_by: 'observability',
},
});
};

This file was deleted.

Loading

0 comments on commit d00d867

Please sign in to comment.