From d00d867382893afc324d6539bc143fa912e14b2f Mon Sep 17 00:00:00 2001 From: Kevin Delemme Date: Mon, 27 Jan 2025 14:48:04 -0500 Subject: [PATCH] chore(slo): rename resource constants and simplify resource installation process' (#208264) --- .../plugins/slo/common/constants.ts | 40 ++- .../slo/common/summary_indices.test.ts | 11 +- .../plugins/slo/common/summary_indices.ts | 8 +- .../error_rate_chart/use_lens_definition.ts | 6 +- .../overview/group_view/slo_group_filters.tsx | 4 +- .../slo/public/hooks/use_fetch_slo_groups.ts | 4 +- .../slo/public/hooks/use_fetch_slo_list.ts | 7 +- .../grouped_slos/hooks/use_group_name.test.ts | 10 +- .../slos/hooks/use_fetch_slos_overview.ts | 4 +- ...s_template.ts => slI_mappings_template.ts} | 11 +- ...s_template.ts => slI_settings_template.ts} | 11 +- ...mplate.ts => summary_mappings_template.ts} | 13 +- ...mplate.ts => summary_settings_template.ts} | 11 +- ...dex_templates.ts => sli_index_template.ts} | 18 +- .../slo_summary_index_templates.ts | 25 -- .../index_templates/summary_index_template.ts | 27 ++ ...e_template.ts => sli_pipeline_template.ts} | 6 +- ...mplate.ts => summary_pipeline_template.ts} | 2 +- .../slo/server/lib/collectors/fetcher.ts | 4 +- .../lib/rules/slo_burn_rate/lib/evaluate.ts | 4 +- .../slo_burn_rate/lib/summary_repository.ts | 4 +- .../plugins/slo/server/plugin.ts | 5 +- .../slo/server/services/burn_rates_client.ts | 6 +- .../plugins/slo/server/services/create_slo.ts | 18 +- .../plugins/slo/server/services/delete_slo.ts | 8 +- .../server/services/delete_slo_instances.ts | 8 +- .../slo/server/services/get_slo_groupings.ts | 6 +- .../slo/server/services/get_slo_health.ts | 4 +- .../services/historical_summary_client.ts | 6 +- .../plugins/slo/server/services/index.ts | 1 - .../plugins/slo/server/services/reset_slo.ts | 20 +- .../services/resource_installer.test.ts | 78 +++-- .../slo/server/services/resource_installer.ts | 86 +++--- .../server/services/slo_definition_client.ts | 4 +- .../slo/server/services/slo_installer.test.ts | 28 -- .../slo/server/services/slo_installer.ts | 38 --- .../server/services/slo_repository.test.ts | 274 ------------------ .../slo/server/services/slo_settings.ts | 4 +- .../server/services/summary_client.test.ts | 10 +- .../slo/server/services/summary_client.ts | 6 +- .../summary_search_client.ts | 4 +- .../generators/occurrences.ts | 8 +- .../generators/timeslices_calendar_aligned.ts | 8 +- .../generators/timeslices_rolling.ts | 8 +- .../tasks/orphan_summary_cleanup_task.test.ts | 16 +- .../tasks/orphan_summary_cleanup_task.ts | 6 +- .../apm_transaction_duration.ts | 4 +- .../apm_transaction_error_rate.ts | 4 +- .../transform_generators/histogram.ts | 4 +- .../transform_generators/kql_custom.ts | 4 +- .../transform_generators/metric_custom.ts | 4 +- .../synthetics_availability.ts | 4 +- .../transform_generators/timeslice_metric.ts | 4 +- .../slo/server/services/update_slo.test.ts | 8 +- .../plugins/slo/server/services/update_slo.ts | 22 +- .../api_integration/apis/slos/helper/es.ts | 8 +- .../apis/observability/slo/delete_slo.ts | 8 +- x-pack/test/api_integration/services/slo.ts | 4 +- 58 files changed, 324 insertions(+), 644 deletions(-) rename x-pack/solutions/observability/plugins/slo/server/assets/component_templates/{slo_mappings_template.ts => slI_mappings_template.ts} (91%) rename x-pack/solutions/observability/plugins/slo/server/assets/component_templates/{slo_settings_template.ts => slI_settings_template.ts} (71%) rename x-pack/solutions/observability/plugins/slo/server/assets/component_templates/{slo_summary_mappings_template.ts => summary_mappings_template.ts} (95%) rename x-pack/solutions/observability/plugins/slo/server/assets/component_templates/{slo_summary_settings_template.ts => summary_settings_template.ts} (70%) rename x-pack/solutions/observability/plugins/slo/server/assets/index_templates/{slo_index_templates.ts => sli_index_template.ts} (50%) delete mode 100644 x-pack/solutions/observability/plugins/slo/server/assets/index_templates/slo_summary_index_templates.ts create mode 100644 x-pack/solutions/observability/plugins/slo/server/assets/index_templates/summary_index_template.ts rename x-pack/solutions/observability/plugins/slo/server/assets/ingest_templates/{slo_pipeline_template.ts => sli_pipeline_template.ts} (92%) rename x-pack/solutions/observability/plugins/slo/server/assets/ingest_templates/{slo_summary_pipeline_template.ts => summary_pipeline_template.ts} (99%) delete mode 100644 x-pack/solutions/observability/plugins/slo/server/services/slo_installer.test.ts delete mode 100644 x-pack/solutions/observability/plugins/slo/server/services/slo_installer.ts delete mode 100644 x-pack/solutions/observability/plugins/slo/server/services/slo_repository.test.ts diff --git a/x-pack/solutions/observability/plugins/slo/common/constants.ts b/x-pack/solutions/observability/plugins/slo/common/constants.ts index b47fecdbd3144..5599cd16a3f39 100644 --- a/x-pack/solutions/observability/plugins/slo/common/constants.ts +++ b/x-pack/solutions/observability/plugins/slo/common/constants.ts @@ -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}`; @@ -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; diff --git a/x-pack/solutions/observability/plugins/slo/common/summary_indices.test.ts b/x-pack/solutions/observability/plugins/slo/common/summary_indices.test.ts index 64f9ad0d44540..a2b921f94435d 100644 --- a/x-pack/solutions/observability/plugins/slo/common/summary_indices.test.ts +++ b/x-pack/solutions/observability/plugins/slo/common/summary_indices.test.ts @@ -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 () { @@ -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 () { @@ -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}` ); }); @@ -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}` ); }); }); diff --git a/x-pack/solutions/observability/plugins/slo/common/summary_indices.ts b/x-pack/solutions/observability/plugins/slo/common/summary_indices.ts index c9a9d47bfdf1a..216f351496cd8 100644 --- a/x-pack/solutions/observability/plugins/slo/common/summary_indices.ts +++ b/x-pack/solutions/observability/plugins/slo/common/summary_indices.ts @@ -6,7 +6,7 @@ */ 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, @@ -14,13 +14,13 @@ export const getListOfSloSummaryIndices = ( ) => { 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}`); } }); diff --git a/x-pack/solutions/observability/plugins/slo/public/components/slo/error_rate_chart/use_lens_definition.ts b/x-pack/solutions/observability/plugins/slo/public/components/slo/error_rate_chart/use_lens_definition.ts index db7eb43f71188..5e555c10c2e4b 100644 --- a/x-pack/solutions/observability/plugins/slo/public/components/slo/error_rate_chart/use_lens_definition.ts +++ b/x-pack/solutions/observability/plugins/slo/public/components/slo/error_rate_chart/use_lens_definition.ts @@ -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 { @@ -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: {}, diff --git a/x-pack/solutions/observability/plugins/slo/public/embeddable/slo/overview/group_view/slo_group_filters.tsx b/x-pack/solutions/observability/plugins/slo/public/embeddable/slo/overview/group_view/slo_group_filters.tsx index d9995adfc412c..0adf7200d1629 100644 --- a/x-pack/solutions/observability/plugins/slo/public/embeddable/slo/overview/group_view/slo_group_filters.tsx +++ b/x-pack/solutions/observability/plugins/slo/public/embeddable/slo/overview/group_view/slo_group_filters.tsx @@ -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'; @@ -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(selectedFilters.groupBy) ?? 'status'; diff --git a/x-pack/solutions/observability/plugins/slo/public/hooks/use_fetch_slo_groups.ts b/x-pack/solutions/observability/plugins/slo/public/hooks/use_fetch_slo_groups.ts index da9b93e0eb209..f6a8cb598466b 100644 --- a/x-pack/solutions/observability/plugins/slo/public/hooks/use_fetch_slo_groups.ts +++ b/x-pack/solutions/observability/plugins/slo/public/hooks/use_fetch_slo_groups.ts @@ -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'; @@ -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(() => { diff --git a/x-pack/solutions/observability/plugins/slo/public/hooks/use_fetch_slo_list.ts b/x-pack/solutions/observability/plugins/slo/public/hooks/use_fetch_slo_list.ts index 2ed986fd1ffc8..9651588d1e418 100644 --- a/x-pack/solutions/observability/plugins/slo/public/hooks/use_fetch_slo_list.ts +++ b/x-pack/solutions/observability/plugins/slo/public/hooks/use_fetch_slo_list.ts @@ -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'; @@ -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(() => { diff --git a/x-pack/solutions/observability/plugins/slo/public/pages/slos/components/grouped_slos/hooks/use_group_name.test.ts b/x-pack/solutions/observability/plugins/slo/public/pages/slos/components/grouped_slos/hooks/use_group_name.test.ts index fa2b5192665ea..46e1bfc6d2993 100644 --- a/x-pack/solutions/observability/plugins/slo/public/pages/slos/components/grouped_slos/hooks/use_group_name.test.ts +++ b/x-pack/solutions/observability/plugins/slo/public/pages/slos/components/grouped_slos/hooks/use_group_name.test.ts @@ -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'; @@ -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'); diff --git a/x-pack/solutions/observability/plugins/slo/public/pages/slos/hooks/use_fetch_slos_overview.ts b/x-pack/solutions/observability/plugins/slo/public/pages/slos/hooks/use_fetch_slos_overview.ts index 1e9246d97f795..4308b30571621 100644 --- a/x-pack/solutions/observability/plugins/slo/public/pages/slos/hooks/use_fetch_slos_overview.ts +++ b/x-pack/solutions/observability/plugins/slo/public/pages/slos/hooks/use_fetch_slos_overview.ts @@ -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'; @@ -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(() => { diff --git a/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slo_mappings_template.ts b/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slI_mappings_template.ts similarity index 91% rename from x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slo_mappings_template.ts rename to x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slI_mappings_template.ts index 38227916a486d..4b0cfbb366ca4 100644 --- a/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slo_mappings_template.ts +++ b/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slI_mappings_template.ts @@ -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: { @@ -109,4 +112,4 @@ export const getSLOMappingsTemplate = (name: string): ClusterPutComponentTemplat managed: true, managed_by: 'observability', }, -}); +}; diff --git a/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slo_settings_template.ts b/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slI_settings_template.ts similarity index 71% rename from x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slo_settings_template.ts rename to x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slI_settings_template.ts index 5e8845a050688..3b06438eb010d 100644 --- a/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slo_settings_template.ts +++ b/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slI_settings_template.ts @@ -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', @@ -21,4 +24,4 @@ export const getSLOSettingsTemplate = (name: string) => ({ managed: true, managed_by: 'observability', }, -}); +}; diff --git a/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slo_summary_mappings_template.ts b/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/summary_mappings_template.ts similarity index 95% rename from x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slo_summary_mappings_template.ts rename to x-pack/solutions/observability/plugins/slo/server/assets/component_templates/summary_mappings_template.ts index a130e45ade735..da4e3f4910f9f 100644 --- a/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slo_summary_mappings_template.ts +++ b/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/summary_mappings_template.ts @@ -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: { @@ -240,4 +241,4 @@ export const getSLOSummaryMappingsTemplate = ( managed: true, managed_by: 'observability', }, -}); +}; diff --git a/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slo_summary_settings_template.ts b/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/summary_settings_template.ts similarity index 70% rename from x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slo_summary_settings_template.ts rename to x-pack/solutions/observability/plugins/slo/server/assets/component_templates/summary_settings_template.ts index f9b18c7f62555..6424bb342a31e 100644 --- a/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/slo_summary_settings_template.ts +++ b/x-pack/solutions/observability/plugins/slo/server/assets/component_templates/summary_settings_template.ts @@ -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', @@ -21,4 +24,4 @@ export const getSLOSummarySettingsTemplate = (name: string) => ({ managed: true, managed_by: 'observability', }, -}); +}; diff --git a/x-pack/solutions/observability/plugins/slo/server/assets/index_templates/slo_index_templates.ts b/x-pack/solutions/observability/plugins/slo/server/assets/index_templates/sli_index_template.ts similarity index 50% rename from x-pack/solutions/observability/plugins/slo/server/assets/index_templates/slo_index_templates.ts rename to x-pack/solutions/observability/plugins/slo/server/assets/index_templates/sli_index_template.ts index 6524d6e7d49cf..6b3447a72c8d4 100644 --- a/x-pack/solutions/observability/plugins/slo/server/assets/index_templates/slo_index_templates.ts +++ b/x-pack/solutions/observability/plugins/slo/server/assets/index_templates/sli_index_template.ts @@ -5,12 +5,18 @@ * 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', @@ -18,4 +24,4 @@ export const getSLOIndexTemplate = (name: string, indexPattern: string, composed managed: true, managed_by: 'observability', }, -}); +}; diff --git a/x-pack/solutions/observability/plugins/slo/server/assets/index_templates/slo_summary_index_templates.ts b/x-pack/solutions/observability/plugins/slo/server/assets/index_templates/slo_summary_index_templates.ts deleted file mode 100644 index 3986273ca99ce..0000000000000 --- a/x-pack/solutions/observability/plugins/slo/server/assets/index_templates/slo_summary_index_templates.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 { SLO_RESOURCES_VERSION } from '../../../common/constants'; - -export const getSLOSummaryIndexTemplate = ( - name: string, - indexPattern: string, - composedOf: string[] -) => ({ - name, - index_patterns: [indexPattern], - composed_of: composedOf, - priority: 500, - _meta: { - description: 'SLO summary index template', - version: SLO_RESOURCES_VERSION, - managed: true, - managed_by: 'observability', - }, -}); diff --git a/x-pack/solutions/observability/plugins/slo/server/assets/index_templates/summary_index_template.ts b/x-pack/solutions/observability/plugins/slo/server/assets/index_templates/summary_index_template.ts new file mode 100644 index 0000000000000..fd70d9909d799 --- /dev/null +++ b/x-pack/solutions/observability/plugins/slo/server/assets/index_templates/summary_index_template.ts @@ -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 { + SLO_RESOURCES_VERSION, + SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME, + SUMMARY_COMPONENT_TEMPLATE_SETTINGS_NAME, + SUMMARY_INDEX_TEMPLATE_NAME, + SUMMARY_INDEX_TEMPLATE_PATTERN, +} from '../../../common/constants'; + +export const SUMMARY_INDEX_TEMPLATE = { + name: SUMMARY_INDEX_TEMPLATE_NAME, + index_patterns: [SUMMARY_INDEX_TEMPLATE_PATTERN], + composed_of: [SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME, SUMMARY_COMPONENT_TEMPLATE_SETTINGS_NAME], + priority: 500, + _meta: { + description: 'SLO summary index template', + version: SLO_RESOURCES_VERSION, + managed: true, + managed_by: 'observability', + }, +}; diff --git a/x-pack/solutions/observability/plugins/slo/server/assets/ingest_templates/slo_pipeline_template.ts b/x-pack/solutions/observability/plugins/slo/server/assets/ingest_templates/sli_pipeline_template.ts similarity index 92% rename from x-pack/solutions/observability/plugins/slo/server/assets/ingest_templates/slo_pipeline_template.ts rename to x-pack/solutions/observability/plugins/slo/server/assets/ingest_templates/sli_pipeline_template.ts index dc078f351eb3e..605e733d444e6 100644 --- a/x-pack/solutions/observability/plugins/slo/server/assets/ingest_templates/slo_pipeline_template.ts +++ b/x-pack/solutions/observability/plugins/slo/server/assets/ingest_templates/sli_pipeline_template.ts @@ -8,12 +8,12 @@ import { ALL_VALUE } from '@kbn/slo-schema'; import { getSLOPipelineId, - SLO_INGEST_PIPELINE_INDEX_NAME_PREFIX, + SLI_INGEST_PIPELINE_INDEX_NAME_PREFIX, SLO_RESOURCES_VERSION, } from '../../../common/constants'; import { SLODefinition } from '../../domain/models'; -export const getSLOPipelineTemplate = (slo: SLODefinition) => ({ +export const getSLIPipelineTemplate = (slo: SLODefinition) => ({ id: getSLOPipelineId(slo.id, slo.revision), description: `Ingest pipeline for SLO rollup data [id: ${slo.id}, revision: ${slo.revision}]`, processors: [ @@ -44,7 +44,7 @@ export const getSLOPipelineTemplate = (slo: SLODefinition) => ({ { date_index_name: { field: '@timestamp', - index_name_prefix: SLO_INGEST_PIPELINE_INDEX_NAME_PREFIX, + index_name_prefix: SLI_INGEST_PIPELINE_INDEX_NAME_PREFIX, date_rounding: 'M', date_formats: ['UNIX_MS', 'ISO8601', "yyyy-MM-dd'T'HH:mm:ss.SSSXX"], }, diff --git a/x-pack/solutions/observability/plugins/slo/server/assets/ingest_templates/slo_summary_pipeline_template.ts b/x-pack/solutions/observability/plugins/slo/server/assets/ingest_templates/summary_pipeline_template.ts similarity index 99% rename from x-pack/solutions/observability/plugins/slo/server/assets/ingest_templates/slo_summary_pipeline_template.ts rename to x-pack/solutions/observability/plugins/slo/server/assets/ingest_templates/summary_pipeline_template.ts index d269bdf1d6de9..d662ab9ca2e0c 100644 --- a/x-pack/solutions/observability/plugins/slo/server/assets/ingest_templates/slo_summary_pipeline_template.ts +++ b/x-pack/solutions/observability/plugins/slo/server/assets/ingest_templates/summary_pipeline_template.ts @@ -11,7 +11,7 @@ import { IBasePath } from '@kbn/core-http-server'; import { getSLOSummaryPipelineId, SLO_RESOURCES_VERSION } from '../../../common/constants'; import { SLODefinition } from '../../domain/models'; -export const getSLOSummaryPipelineTemplate = ( +export const getSummaryPipelineTemplate = ( slo: SLODefinition, spaceId: string, basePath: IBasePath diff --git a/x-pack/solutions/observability/plugins/slo/server/lib/collectors/fetcher.ts b/x-pack/solutions/observability/plugins/slo/server/lib/collectors/fetcher.ts index dfd47986ba38b..9eeaf385a3486 100644 --- a/x-pack/solutions/observability/plugins/slo/server/lib/collectors/fetcher.ts +++ b/x-pack/solutions/observability/plugins/slo/server/lib/collectors/fetcher.ts @@ -10,7 +10,7 @@ import { CollectorFetchContext } from '@kbn/usage-collection-plugin/server'; import { StoredSLODefinition } from '../../domain/models'; import { SO_SLO_TYPE } from '../../saved_objects'; import { Usage } from './type'; -import { SLO_SUMMARY_DESTINATION_INDEX_PATTERN } from '../../../common/constants'; +import { SUMMARY_DESTINATION_INDEX_PATTERN } from '../../../common/constants'; export const fetcher = async (context: CollectorFetchContext) => { const finder = context.soClient.createPointInTimeFinder({ @@ -19,7 +19,7 @@ export const fetcher = async (context: CollectorFetchContext) => { }); const totalInstances = await context.esClient.count({ - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, query: { bool: { filter: [ diff --git a/x-pack/solutions/observability/plugins/slo/server/lib/rules/slo_burn_rate/lib/evaluate.ts b/x-pack/solutions/observability/plugins/slo/server/lib/rules/slo_burn_rate/lib/evaluate.ts index aa0979d34ba3b..957157cecda29 100644 --- a/x-pack/solutions/observability/plugins/slo/server/lib/rules/slo_burn_rate/lib/evaluate.ts +++ b/x-pack/solutions/observability/plugins/slo/server/lib/rules/slo_burn_rate/lib/evaluate.ts @@ -9,7 +9,7 @@ import { ElasticsearchClient } from '@kbn/core/server'; import { get } from 'lodash'; import { Duration, SLODefinition, toDurationUnit } from '../../../../domain/models'; import { BurnRateRuleParams } from '../types'; -import { SLO_DESTINATION_INDEX_PATTERN } from '../../../../../common/constants'; +import { SLI_DESTINATION_INDEX_PATTERN } from '../../../../../common/constants'; import { buildQuery, EvaluationAfterKey, @@ -72,7 +72,7 @@ async function queryAllResults( ): Promise { const queryAndAggs = buildQuery(startedAt, slo, params, lastAfterKey); const results = await esClient.search({ - index: SLO_DESTINATION_INDEX_PATTERN, + index: SLI_DESTINATION_INDEX_PATTERN, ...queryAndAggs, }); diff --git a/x-pack/solutions/observability/plugins/slo/server/lib/rules/slo_burn_rate/lib/summary_repository.ts b/x-pack/solutions/observability/plugins/slo/server/lib/rules/slo_burn_rate/lib/summary_repository.ts index 361b3c1376c6e..67c4deedbe332 100644 --- a/x-pack/solutions/observability/plugins/slo/server/lib/rules/slo_burn_rate/lib/summary_repository.ts +++ b/x-pack/solutions/observability/plugins/slo/server/lib/rules/slo_burn_rate/lib/summary_repository.ts @@ -7,7 +7,7 @@ import { ElasticsearchClient } from '@kbn/core/server'; import { SLODefinition } from '../../../../domain/models'; -import { SLO_SUMMARY_DESTINATION_INDEX_PATTERN } from '../../../../../common/constants'; +import { SUMMARY_DESTINATION_INDEX_PATTERN } from '../../../../../common/constants'; import { EsSummaryDocument } from '../../../../services/summary_transform_generator/helpers/create_temp_summary'; export async function getSloSummary( @@ -17,7 +17,7 @@ export async function getSloSummary( ) { try { const res = await esClient.search({ - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, body: { query: { bool: { diff --git a/x-pack/solutions/observability/plugins/slo/server/plugin.ts b/x-pack/solutions/observability/plugins/slo/server/plugin.ts index c7a5a1dda3280..e9df927f33b19 100644 --- a/x-pack/solutions/observability/plugins/slo/server/plugin.ts +++ b/x-pack/solutions/observability/plugins/slo/server/plugin.ts @@ -28,7 +28,7 @@ import { registerServerRoutes } from './routes/register_routes'; import { SLORoutesDependencies } from './routes/types'; import { SO_SLO_TYPE, slo } from './saved_objects'; import { SO_SLO_SETTINGS_TYPE, sloSettings } from './saved_objects/slo_settings'; -import { DefaultResourceInstaller, DefaultSLOInstaller } from './services'; +import { DefaultResourceInstaller } from './services'; import { SloOrphanSummaryCleanupTask } from './services/tasks/orphan_summary_cleanup_task'; import type { SLOConfig, @@ -157,8 +157,7 @@ export class SLOPlugin .then(async ([coreStart, pluginStart]) => { const esInternalClient = coreStart.elasticsearch.client.asInternalUser; const sloResourceInstaller = new DefaultResourceInstaller(esInternalClient, this.logger); - const sloInstaller = new DefaultSLOInstaller(sloResourceInstaller, this.logger); - await sloInstaller.install(); + await sloResourceInstaller.ensureCommonResourcesInstalled(); }) .catch(() => { // noop - error already logged from the installer diff --git a/x-pack/solutions/observability/plugins/slo/server/services/burn_rates_client.ts b/x-pack/solutions/observability/plugins/slo/server/services/burn_rates_client.ts index eb7e130e448f3..0897afbe9bcc1 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/burn_rates_client.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/burn_rates_client.ts @@ -19,7 +19,7 @@ import { occurrencesBudgetingMethodSchema, timeslicesBudgetingMethodSchema, } from '@kbn/slo-schema'; -import { SLO_DESTINATION_INDEX_PATTERN } from '../../common/constants'; +import { SLI_DESTINATION_INDEX_PATTERN } from '../../common/constants'; import { DateRange, Duration, SLODefinition } from '../domain/models'; import { computeBurnRate, computeSLI } from '../domain/services'; import { getDelayInSecondsFromSLO } from '../domain/services/get_delay_in_seconds_from_slo'; @@ -65,8 +65,8 @@ export class DefaultBurnRatesClient implements BurnRatesClient { ); const index = remoteName - ? `${remoteName}:${SLO_DESTINATION_INDEX_PATTERN}` - : SLO_DESTINATION_INDEX_PATTERN; + ? `${remoteName}:${SLI_DESTINATION_INDEX_PATTERN}` + : SLI_DESTINATION_INDEX_PATTERN; const result = await this.esClient.search({ ...commonQuery(slo, instanceId, longestDateRange), diff --git a/x-pack/solutions/observability/plugins/slo/server/services/create_slo.ts b/x-pack/solutions/observability/plugins/slo/server/services/create_slo.ts index 8d596d2d27c44..0bc5500b2782c 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/create_slo.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/create_slo.ts @@ -13,14 +13,14 @@ import { merge } from 'lodash'; import { v4 as uuidv4 } from 'uuid'; import { SLO_MODEL_VERSION, - SLO_SUMMARY_TEMP_INDEX_NAME, + SUMMARY_TEMP_INDEX_NAME, getSLOPipelineId, getSLOSummaryPipelineId, getSLOSummaryTransformId, getSLOTransformId, } from '../../common/constants'; -import { getSLOPipelineTemplate } from '../assets/ingest_templates/slo_pipeline_template'; -import { getSLOSummaryPipelineTemplate } from '../assets/ingest_templates/slo_summary_pipeline_template'; +import { getSLIPipelineTemplate } from '../assets/ingest_templates/sli_pipeline_template'; +import { getSummaryPipelineTemplate } from '../assets/ingest_templates/summary_pipeline_template'; import { Duration, DurationUnit, SLODefinition } from '../domain/models'; import { validateSLO } from '../domain/services'; import { SLOIdConflict, SecurityException } from '../errors'; @@ -60,14 +60,14 @@ export class CreateSLO { const rollupTransformId = getSLOTransformId(slo.id, slo.revision); const summaryTransformId = getSLOSummaryTransformId(slo.id, slo.revision); try { - const sloPipelinePromise = this.createPipeline(getSLOPipelineTemplate(slo)); + const sloPipelinePromise = this.createPipeline(getSLIPipelineTemplate(slo)); rollbackOperations.push(() => this.deletePipeline(getSLOPipelineId(slo.id, slo.revision))); const rollupTransformPromise = this.transformManager.install(slo); rollbackOperations.push(() => this.transformManager.uninstall(rollupTransformId)); const summaryPipelinePromise = this.createPipeline( - getSLOSummaryPipelineTemplate(slo, this.spaceId, this.basePath) + getSummaryPipelineTemplate(slo, this.spaceId, this.basePath) ); rollbackOperations.push(() => @@ -132,7 +132,7 @@ export class CreateSLO { return await retryTransientEsErrors( () => this.esClient.index({ - index: SLO_SUMMARY_TEMP_INDEX_NAME, + index: SUMMARY_TEMP_INDEX_NAME, id: `slo-${slo.id}`, document: createTempSummaryDocument(slo, this.spaceId, this.basePath), refresh: true, @@ -145,7 +145,7 @@ export class CreateSLO { return await retryTransientEsErrors( () => this.esClient.delete({ - index: SLO_SUMMARY_TEMP_INDEX_NAME, + index: SUMMARY_TEMP_INDEX_NAME, id: `slo-${slo.id}`, refresh: true, }), @@ -181,8 +181,8 @@ export class CreateSLO { validateSLO(slo); const rollUpTransform = await this.transformManager.inspect(slo); - const rollUpPipeline = getSLOPipelineTemplate(slo); - const summaryPipeline = getSLOSummaryPipelineTemplate(slo, this.spaceId, this.basePath); + const rollUpPipeline = getSLIPipelineTemplate(slo); + const summaryPipeline = getSummaryPipelineTemplate(slo, this.spaceId, this.basePath); const summaryTransform = await this.summaryTransformManager.inspect(slo); const temporaryDoc = createTempSummaryDocument(slo, this.spaceId, this.basePath); diff --git a/x-pack/solutions/observability/plugins/slo/server/services/delete_slo.ts b/x-pack/solutions/observability/plugins/slo/server/services/delete_slo.ts index e86fab0a1620d..d98c85f618a17 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/delete_slo.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/delete_slo.ts @@ -12,8 +12,8 @@ import { getSLOSummaryPipelineId, getSLOSummaryTransformId, getSLOTransformId, - SLO_DESTINATION_INDEX_PATTERN, - SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + SLI_DESTINATION_INDEX_PATTERN, + SUMMARY_DESTINATION_INDEX_PATTERN, } from '../../common/constants'; import { retryTransientEsErrors } from '../utils/retry'; import { SLORepository } from './slo_repository'; @@ -62,7 +62,7 @@ export class DeleteSLO { private async deleteRollupData(sloId: string): Promise { await this.esClient.deleteByQuery({ - index: SLO_DESTINATION_INDEX_PATTERN, + index: SLI_DESTINATION_INDEX_PATTERN, wait_for_completion: false, query: { match: { @@ -74,7 +74,7 @@ export class DeleteSLO { private async deleteSummaryData(sloId: string): Promise { await this.esClient.deleteByQuery({ - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, refresh: true, query: { match: { diff --git a/x-pack/solutions/observability/plugins/slo/server/services/delete_slo_instances.ts b/x-pack/solutions/observability/plugins/slo/server/services/delete_slo_instances.ts index fb423dc37f930..fb2fc60fa29b5 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/delete_slo_instances.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/delete_slo_instances.ts @@ -8,8 +8,8 @@ import { ElasticsearchClient } from '@kbn/core/server'; import { ALL_VALUE, DeleteSLOInstancesParams } from '@kbn/slo-schema'; import { - SLO_DESTINATION_INDEX_PATTERN, - SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + SLI_DESTINATION_INDEX_PATTERN, + SUMMARY_DESTINATION_INDEX_PATTERN, } from '../../common/constants'; import { IllegalArgumentError } from '../errors'; @@ -31,7 +31,7 @@ export class DeleteSLOInstances { // Delete rollup data when excluding rollup data is not explicitly requested private async deleteRollupData(list: List): Promise { await this.esClient.deleteByQuery({ - index: SLO_DESTINATION_INDEX_PATTERN, + index: SLI_DESTINATION_INDEX_PATTERN, wait_for_completion: false, query: { bool: { @@ -52,7 +52,7 @@ export class DeleteSLOInstances { private async deleteSummaryData(list: List): Promise { await this.esClient.deleteByQuery({ - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, refresh: true, query: { bool: { diff --git a/x-pack/solutions/observability/plugins/slo/server/services/get_slo_groupings.ts b/x-pack/solutions/observability/plugins/slo/server/services/get_slo_groupings.ts index 81ed1c0c7518f..2191b690df2d7 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/get_slo_groupings.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/get_slo_groupings.ts @@ -8,7 +8,7 @@ import { AggregationsCompositeAggregation } from '@elastic/elasticsearch/lib/api/types'; import { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; import { ALL_VALUE, GetSLOGroupingsParams, GetSLOGroupingsResponse } from '@kbn/slo-schema'; -import { SLO_SUMMARY_DESTINATION_INDEX_NAME } from '../../common/constants'; +import { SUMMARY_DESTINATION_INDEX_NAME } from '../../common/constants'; import { SLODefinition, SLOSettings } from '../domain/models'; import { SloDefinitionClient } from './slo_definition_client'; @@ -52,8 +52,8 @@ export class GetSLOGroupings { } >({ index: params.remoteName - ? `${params.remoteName}:${SLO_SUMMARY_DESTINATION_INDEX_NAME}` - : SLO_SUMMARY_DESTINATION_INDEX_NAME, + ? `${params.remoteName}:${SUMMARY_DESTINATION_INDEX_NAME}` + : SUMMARY_DESTINATION_INDEX_NAME, ...generateQuery(slo, params, this.sloSettings), }); diff --git a/x-pack/solutions/observability/plugins/slo/server/services/get_slo_health.ts b/x-pack/solutions/observability/plugins/slo/server/services/get_slo_health.ts index 585bf7ef5d4e2..4d75025a7429e 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/get_slo_health.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/get_slo_health.ts @@ -17,7 +17,7 @@ import moment from 'moment'; import { getSLOSummaryTransformId, getSLOTransformId, - SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + SUMMARY_DESTINATION_INDEX_PATTERN, } from '../../common/constants'; import { SLODefinition } from '../domain/models'; import { HealthStatus, State } from '../domain/models/health'; @@ -70,7 +70,7 @@ export class GetSLOHealth { filteredList: Array<{ sloId: string; sloInstanceId: string; sloRevision: number }> ) { const summaryDocs = await this.esClient.search({ - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, query: { bool: { should: filteredList.map((item) => ({ diff --git a/x-pack/solutions/observability/plugins/slo/server/services/historical_summary_client.ts b/x-pack/solutions/observability/plugins/slo/server/services/historical_summary_client.ts index d4e3cdcbf6004..16d94ddb55574 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/historical_summary_client.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/historical_summary_client.ts @@ -22,7 +22,7 @@ import { import { assertNever } from '@kbn/std'; import * as t from 'io-ts'; import moment from 'moment'; -import { SLO_DESTINATION_INDEX_PATTERN } from '../../common/constants'; +import { SLI_DESTINATION_INDEX_PATTERN } from '../../common/constants'; import { DateRange, GroupBy, @@ -74,8 +74,8 @@ export class DefaultHistoricalSummaryClient implements HistoricalSummaryClient { ({ sloId, revision, budgetingMethod, instanceId, groupBy, timeWindow, remoteName }) => [ { index: remoteName - ? `${remoteName}:${SLO_DESTINATION_INDEX_PATTERN}` - : SLO_DESTINATION_INDEX_PATTERN, + ? `${remoteName}:${SLI_DESTINATION_INDEX_PATTERN}` + : SLI_DESTINATION_INDEX_PATTERN, }, generateSearchQuery({ groupBy, diff --git a/x-pack/solutions/observability/plugins/slo/server/services/index.ts b/x-pack/solutions/observability/plugins/slo/server/services/index.ts index c229226a290d2..b56a74baf7c38 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/index.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/index.ts @@ -12,7 +12,6 @@ export * from './find_slo'; export * from './get_slo'; export * from './historical_summary_client'; export * from './resource_installer'; -export * from './slo_installer'; export * from './burn_rates_client'; export * from './slo_repository'; export * from './transform_manager'; diff --git a/x-pack/solutions/observability/plugins/slo/server/services/reset_slo.ts b/x-pack/solutions/observability/plugins/slo/server/services/reset_slo.ts index e91e720b4fd8d..24aa6a705741c 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/reset_slo.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/reset_slo.ts @@ -8,17 +8,17 @@ import { ElasticsearchClient, IBasePath, IScopedClusterClient, Logger } from '@kbn/core/server'; import { resetSLOResponseSchema } from '@kbn/slo-schema'; import { - SLO_DESTINATION_INDEX_PATTERN, + SLI_DESTINATION_INDEX_PATTERN, SLO_MODEL_VERSION, - SLO_SUMMARY_DESTINATION_INDEX_PATTERN, - SLO_SUMMARY_TEMP_INDEX_NAME, + SUMMARY_DESTINATION_INDEX_PATTERN, + SUMMARY_TEMP_INDEX_NAME, getSLOPipelineId, getSLOSummaryPipelineId, getSLOSummaryTransformId, getSLOTransformId, } from '../../common/constants'; -import { getSLOPipelineTemplate } from '../assets/ingest_templates/slo_pipeline_template'; -import { getSLOSummaryPipelineTemplate } from '../assets/ingest_templates/slo_summary_pipeline_template'; +import { getSLIPipelineTemplate } from '../assets/ingest_templates/sli_pipeline_template'; +import { getSummaryPipelineTemplate } from '../assets/ingest_templates/summary_pipeline_template'; import { retryTransientEsErrors } from '../utils/retry'; import { SLORepository } from './slo_repository'; import { createTempSummaryDocument } from './summary_transform_generator/helpers/create_temp_summary'; @@ -56,7 +56,7 @@ export class ResetSLO { await retryTransientEsErrors( () => this.scopedClusterClient.asSecondaryAuthUser.ingest.putPipeline( - getSLOPipelineTemplate(slo) + getSLIPipelineTemplate(slo) ), { logger: this.logger } ); @@ -67,7 +67,7 @@ export class ResetSLO { await retryTransientEsErrors( () => this.scopedClusterClient.asSecondaryAuthUser.ingest.putPipeline( - getSLOSummaryPipelineTemplate(slo, this.spaceId, this.basePath) + getSummaryPipelineTemplate(slo, this.spaceId, this.basePath) ), { logger: this.logger } ); @@ -78,7 +78,7 @@ export class ResetSLO { await retryTransientEsErrors( () => this.esClient.index({ - index: SLO_SUMMARY_TEMP_INDEX_NAME, + index: SUMMARY_TEMP_INDEX_NAME, id: `slo-${slo.id}`, document: createTempSummaryDocument(slo, this.spaceId, this.basePath), refresh: true, @@ -124,7 +124,7 @@ export class ResetSLO { */ private async deleteRollupData(sloId: string): Promise { await this.esClient.deleteByQuery({ - index: SLO_DESTINATION_INDEX_PATTERN, + index: SLI_DESTINATION_INDEX_PATTERN, refresh: true, query: { bool: { @@ -142,7 +142,7 @@ export class ResetSLO { */ private async deleteSummaryData(sloId: string): Promise { await this.esClient.deleteByQuery({ - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, refresh: true, query: { bool: { diff --git a/x-pack/solutions/observability/plugins/slo/server/services/resource_installer.test.ts b/x-pack/solutions/observability/plugins/slo/server/services/resource_installer.test.ts index 3f72ace983d20..7e2f40663f409 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/resource_installer.test.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/resource_installer.test.ts @@ -8,13 +8,13 @@ import { elasticsearchServiceMock } from '@kbn/core/server/mocks'; import { loggerMock } from '@kbn/logging-mocks'; import { - SLO_COMPONENT_TEMPLATE_MAPPINGS_NAME, - SLO_COMPONENT_TEMPLATE_SETTINGS_NAME, - SLO_INDEX_TEMPLATE_NAME, + SLI_COMPONENT_TEMPLATE_MAPPINGS_NAME, + SLI_COMPONENT_TEMPLATE_SETTINGS_NAME, + SLI_INDEX_TEMPLATE_NAME, SLO_RESOURCES_VERSION, - SLO_SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME, - SLO_SUMMARY_COMPONENT_TEMPLATE_SETTINGS_NAME, - SLO_SUMMARY_INDEX_TEMPLATE_NAME, + SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME, + SUMMARY_COMPONENT_TEMPLATE_SETTINGS_NAME, + SUMMARY_INDEX_TEMPLATE_NAME, } from '../../common/constants'; import { DefaultResourceInstaller } from './resource_installer'; @@ -24,7 +24,7 @@ describe('resourceInstaller', () => { mockClusterClient.cluster.getComponentTemplate.mockResponse({ component_templates: [ { - name: SLO_INDEX_TEMPLATE_NAME, + name: SLI_INDEX_TEMPLATE_NAME, component_template: { _meta: { version: 2, @@ -39,10 +39,10 @@ describe('resourceInstaller', () => { mockClusterClient.indices.getIndexTemplate.mockResponse({ index_templates: [ { - name: SLO_INDEX_TEMPLATE_NAME, + name: SLI_INDEX_TEMPLATE_NAME, index_template: { - index_patterns: SLO_INDEX_TEMPLATE_NAME, - composed_of: [SLO_SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME], + index_patterns: SLI_INDEX_TEMPLATE_NAME, + composed_of: [SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME], _meta: { version: 2, }, @@ -58,28 +58,28 @@ describe('resourceInstaller', () => { expect(mockClusterClient.cluster.putComponentTemplate).toHaveBeenCalledTimes(4); expect(mockClusterClient.cluster.putComponentTemplate).toHaveBeenNthCalledWith( 1, - expect.objectContaining({ name: SLO_COMPONENT_TEMPLATE_MAPPINGS_NAME }) + expect.objectContaining({ name: SLI_COMPONENT_TEMPLATE_MAPPINGS_NAME }) ); expect(mockClusterClient.cluster.putComponentTemplate).toHaveBeenNthCalledWith( 2, - expect.objectContaining({ name: SLO_COMPONENT_TEMPLATE_SETTINGS_NAME }) + expect.objectContaining({ name: SLI_COMPONENT_TEMPLATE_SETTINGS_NAME }) ); expect(mockClusterClient.cluster.putComponentTemplate).toHaveBeenNthCalledWith( 3, - expect.objectContaining({ name: SLO_SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME }) + expect.objectContaining({ name: SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME }) ); expect(mockClusterClient.cluster.putComponentTemplate).toHaveBeenNthCalledWith( 4, - expect.objectContaining({ name: SLO_SUMMARY_COMPONENT_TEMPLATE_SETTINGS_NAME }) + expect.objectContaining({ name: SUMMARY_COMPONENT_TEMPLATE_SETTINGS_NAME }) ); expect(mockClusterClient.indices.putIndexTemplate).toHaveBeenCalledTimes(2); expect(mockClusterClient.indices.putIndexTemplate).toHaveBeenNthCalledWith( 1, - expect.objectContaining({ name: SLO_INDEX_TEMPLATE_NAME }) + expect.objectContaining({ name: SLI_INDEX_TEMPLATE_NAME }) ); expect(mockClusterClient.indices.putIndexTemplate).toHaveBeenNthCalledWith( 2, - expect.objectContaining({ name: SLO_SUMMARY_INDEX_TEMPLATE_NAME }) + expect.objectContaining({ name: SUMMARY_INDEX_TEMPLATE_NAME }) ); }); @@ -88,7 +88,7 @@ describe('resourceInstaller', () => { mockClusterClient.cluster.getComponentTemplate.mockResponse({ component_templates: [ { - name: SLO_INDEX_TEMPLATE_NAME, + name: SLI_INDEX_TEMPLATE_NAME, component_template: { _meta: { version: SLO_RESOURCES_VERSION, @@ -103,10 +103,10 @@ describe('resourceInstaller', () => { mockClusterClient.indices.getIndexTemplate.mockResponse({ index_templates: [ { - name: SLO_INDEX_TEMPLATE_NAME, + name: SLI_INDEX_TEMPLATE_NAME, index_template: { - index_patterns: SLO_INDEX_TEMPLATE_NAME, - composed_of: [SLO_SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME], + index_patterns: SLI_INDEX_TEMPLATE_NAME, + composed_of: [SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME], _meta: { version: SLO_RESOURCES_VERSION, }, @@ -122,4 +122,42 @@ describe('resourceInstaller', () => { expect(mockClusterClient.cluster.putComponentTemplate).not.toHaveBeenCalled(); expect(mockClusterClient.indices.putIndexTemplate).not.toHaveBeenCalled(); }); + + it('runs the installation only once at a time', async () => { + const mockClusterClient = elasticsearchServiceMock.createElasticsearchClient(); + mockClusterClient.cluster.getComponentTemplate.mockImplementation( + () => + new Promise((resolve) => + setTimeout( + () => + resolve({ + component_templates: [ + { + name: SLI_INDEX_TEMPLATE_NAME, + component_template: { + _meta: { + version: SLO_RESOURCES_VERSION - 1, + }, + template: { + settings: {}, + }, + }, + }, + ], + }), + 1000 + ) + ) + ); + + const installer = new DefaultResourceInstaller(mockClusterClient, loggerMock.create()); + + await Promise.all([ + installer.ensureCommonResourcesInstalled(), + installer.ensureCommonResourcesInstalled(), + ]); + + // Ensure that the installation was only run once, e.g. 4 calls to the put component template API, and not 2x 4 calls + expect(mockClusterClient.cluster.putComponentTemplate).toHaveBeenCalledTimes(4); + }); }); diff --git a/x-pack/solutions/observability/plugins/slo/server/services/resource_installer.ts b/x-pack/solutions/observability/plugins/slo/server/services/resource_installer.ts index d6544d352f90f..e69d37262b69f 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/resource_installer.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/resource_installer.ts @@ -10,26 +10,17 @@ import type { IndicesPutIndexTemplateRequest, } from '@elastic/elasticsearch/lib/api/types'; import type { ElasticsearchClient, Logger } from '@kbn/core/server'; -import { getSLOMappingsTemplate } from '../assets/component_templates/slo_mappings_template'; -import { getSLOSettingsTemplate } from '../assets/component_templates/slo_settings_template'; -import { getSLOSummaryMappingsTemplate } from '../assets/component_templates/slo_summary_mappings_template'; -import { getSLOSummarySettingsTemplate } from '../assets/component_templates/slo_summary_settings_template'; import { - SLO_COMPONENT_TEMPLATE_MAPPINGS_NAME, - SLO_COMPONENT_TEMPLATE_SETTINGS_NAME, - SLO_DESTINATION_INDEX_NAME, - SLO_INDEX_TEMPLATE_NAME, - SLO_INDEX_TEMPLATE_PATTERN, - SLO_SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME, - SLO_SUMMARY_COMPONENT_TEMPLATE_SETTINGS_NAME, - SLO_SUMMARY_DESTINATION_INDEX_NAME, - SLO_SUMMARY_INDEX_TEMPLATE_NAME, - SLO_SUMMARY_INDEX_TEMPLATE_PATTERN, - SLO_SUMMARY_TEMP_INDEX_NAME, + SLI_DESTINATION_INDEX_NAME, + SUMMARY_DESTINATION_INDEX_NAME, + SUMMARY_TEMP_INDEX_NAME, } from '../../common/constants'; -import { getSLOIndexTemplate } from '../assets/index_templates/slo_index_templates'; -import { getSLOSummaryIndexTemplate } from '../assets/index_templates/slo_summary_index_templates'; - +import { SLI_MAPPINGS_TEMPLATE } from '../assets/component_templates/slI_mappings_template'; +import { SLI_SETTINGS_TEMPLATE } from '../assets/component_templates/slI_settings_template'; +import { SUMMARY_MAPPINGS_TEMPLATE } from '../assets/component_templates/summary_mappings_template'; +import { SUMMARY_SETTINGS_TEMPLATE } from '../assets/component_templates/summary_settings_template'; +import { SLI_INDEX_TEMPLATE } from '../assets/index_templates/sli_index_template'; +import { SUMMARY_INDEX_TEMPLATE } from '../assets/index_templates/summary_index_template'; import { retryTransientEsErrors } from '../utils/retry'; export interface ResourceInstaller { @@ -37,50 +28,39 @@ export interface ResourceInstaller { } export class DefaultResourceInstaller implements ResourceInstaller { + private isInstalling: boolean = false; + constructor(private esClient: ElasticsearchClient, private logger: Logger) {} - public async ensureCommonResourcesInstalled(): Promise { + public async ensureCommonResourcesInstalled() { + if (this.isInstalling) { + return; + } + this.isInstalling = true; + + let installTimeout; try { + installTimeout = setTimeout(() => (this.isInstalling = false), 60000); + this.logger.info('Installing SLO shared resources'); await Promise.all([ - this.createOrUpdateComponentTemplate( - getSLOMappingsTemplate(SLO_COMPONENT_TEMPLATE_MAPPINGS_NAME) - ), - this.createOrUpdateComponentTemplate( - getSLOSettingsTemplate(SLO_COMPONENT_TEMPLATE_SETTINGS_NAME) - ), - this.createOrUpdateComponentTemplate( - getSLOSummaryMappingsTemplate(SLO_SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME) - ), - this.createOrUpdateComponentTemplate( - getSLOSummarySettingsTemplate(SLO_SUMMARY_COMPONENT_TEMPLATE_SETTINGS_NAME) - ), + this.createOrUpdateComponentTemplate(SLI_MAPPINGS_TEMPLATE), + this.createOrUpdateComponentTemplate(SLI_SETTINGS_TEMPLATE), + this.createOrUpdateComponentTemplate(SUMMARY_MAPPINGS_TEMPLATE), + this.createOrUpdateComponentTemplate(SUMMARY_SETTINGS_TEMPLATE), ]); - await this.createOrUpdateIndexTemplate( - getSLOIndexTemplate(SLO_INDEX_TEMPLATE_NAME, SLO_INDEX_TEMPLATE_PATTERN, [ - SLO_COMPONENT_TEMPLATE_MAPPINGS_NAME, - SLO_COMPONENT_TEMPLATE_SETTINGS_NAME, - ]) - ); - - await this.createOrUpdateIndexTemplate( - getSLOSummaryIndexTemplate( - SLO_SUMMARY_INDEX_TEMPLATE_NAME, - SLO_SUMMARY_INDEX_TEMPLATE_PATTERN, - [ - SLO_SUMMARY_COMPONENT_TEMPLATE_MAPPINGS_NAME, - SLO_SUMMARY_COMPONENT_TEMPLATE_SETTINGS_NAME, - ] - ) - ); - - await this.createIndex(SLO_DESTINATION_INDEX_NAME); - await this.createIndex(SLO_SUMMARY_DESTINATION_INDEX_NAME); - await this.createIndex(SLO_SUMMARY_TEMP_INDEX_NAME); + await this.createOrUpdateIndexTemplate(SLI_INDEX_TEMPLATE); + await this.createOrUpdateIndexTemplate(SUMMARY_INDEX_TEMPLATE); + + await this.createIndex(SLI_DESTINATION_INDEX_NAME); + await this.createIndex(SUMMARY_DESTINATION_INDEX_NAME); + await this.createIndex(SUMMARY_TEMP_INDEX_NAME); } catch (err) { this.logger.error(`Error while installing SLO shared resources: ${err}`); - throw err; + } finally { + this.isInstalling = false; + clearTimeout(installTimeout); } } diff --git a/x-pack/solutions/observability/plugins/slo/server/services/slo_definition_client.ts b/x-pack/solutions/observability/plugins/slo/server/services/slo_definition_client.ts index 39e3d3f446e39..26daeb833c3b0 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/slo_definition_client.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/slo_definition_client.ts @@ -6,7 +6,7 @@ */ import { ElasticsearchClient, Logger } from '@kbn/core/server'; -import { SLO_SUMMARY_DESTINATION_INDEX_PATTERN } from '../../common/constants'; +import { SUMMARY_DESTINATION_INDEX_PATTERN } from '../../common/constants'; import { SLODefinition } from '../domain/models'; import { SLORepository } from './slo_repository'; import { EsSummaryDocument } from './summary_transform_generator/helpers/create_temp_summary'; @@ -34,7 +34,7 @@ export class SloDefinitionClient { ): Promise { if (remoteName) { const summarySearch = await this.esClient.search({ - index: `${remoteName}:${SLO_SUMMARY_DESTINATION_INDEX_PATTERN}`, + index: `${remoteName}:${SUMMARY_DESTINATION_INDEX_PATTERN}`, query: { bool: { filter: [{ term: { spaceId } }, { term: { 'slo.id': sloId } }], diff --git a/x-pack/solutions/observability/plugins/slo/server/services/slo_installer.test.ts b/x-pack/solutions/observability/plugins/slo/server/services/slo_installer.test.ts deleted file mode 100644 index 92d0865ec5c9f..0000000000000 --- a/x-pack/solutions/observability/plugins/slo/server/services/slo_installer.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 { loggingSystemMock } from '@kbn/core/server/mocks'; -import { MockedLogger } from '@kbn/logging-mocks'; -import { createResourceInstallerMock } from './mocks'; -import { DefaultSLOInstaller } from './slo_installer'; - -describe('SLO Installer', () => { - let loggerMock: jest.Mocked; - - beforeEach(() => { - loggerMock = loggingSystemMock.createLogger(); - }); - - it.skip('handles concurrent installation', async () => { - const resourceInstaller = createResourceInstallerMock(); - const service = new DefaultSLOInstaller(resourceInstaller, loggerMock); - - await Promise.all([service.install(), service.install()]); - - expect(resourceInstaller.ensureCommonResourcesInstalled).toHaveBeenCalledTimes(1); - }); -}); diff --git a/x-pack/solutions/observability/plugins/slo/server/services/slo_installer.ts b/x-pack/solutions/observability/plugins/slo/server/services/slo_installer.ts deleted file mode 100644 index eab4c266aae8e..0000000000000 --- a/x-pack/solutions/observability/plugins/slo/server/services/slo_installer.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 { Logger } from '@kbn/core/server'; -import { ResourceInstaller } from '.'; - -export interface SLOInstaller { - install(): Promise; -} - -export class DefaultSLOInstaller implements SLOInstaller { - private isInstalling: boolean = false; - - constructor(private sloResourceInstaller: ResourceInstaller, private logger: Logger) {} - - public async install() { - if (this.isInstalling) { - return; - } - this.isInstalling = true; - - let installTimeout; - try { - installTimeout = setTimeout(() => (this.isInstalling = false), 60000); - - await this.sloResourceInstaller.ensureCommonResourcesInstalled(); - } catch (error) { - this.logger.error(`Failed to install SLO common resources: ${error}`); - } finally { - this.isInstalling = false; - clearTimeout(installTimeout); - } - } -} diff --git a/x-pack/solutions/observability/plugins/slo/server/services/slo_repository.test.ts b/x-pack/solutions/observability/plugins/slo/server/services/slo_repository.test.ts deleted file mode 100644 index 633ee359ca53f..0000000000000 --- a/x-pack/solutions/observability/plugins/slo/server/services/slo_repository.test.ts +++ /dev/null @@ -1,274 +0,0 @@ -/* - * 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 { SavedObjectsClientContract, SavedObjectsFindResponse } from '@kbn/core/server'; -import { loggingSystemMock, savedObjectsClientMock } from '@kbn/core/server/mocks'; -import { MockedLogger } from '@kbn/logging-mocks'; -import { sloDefinitionSchema } from '@kbn/slo-schema'; -import { SLO_MODEL_VERSION } from '../../common/constants'; -import { SLODefinition, StoredSLODefinition } from '../domain/models'; -import { SLONotFound } from '../errors'; -import { SO_SLO_TYPE } from '../saved_objects'; -import { aStoredSLO, createAPMTransactionDurationIndicator, createSLO } from './fixtures/slo'; -import { KibanaSavedObjectsSLORepository } from './slo_repository'; - -const SOME_SLO = createSLO({ indicator: createAPMTransactionDurationIndicator() }); -const ANOTHER_SLO = createSLO(); -const INVALID_SLO_ID = 'invalid-slo-id'; - -function soFindResponse( - sloList: SLODefinition[], - includeInvalidStoredSLO: boolean = false -): SavedObjectsFindResponse { - return { - page: 1, - per_page: 25, - total: includeInvalidStoredSLO ? sloList.length + 1 : sloList.length, - // @ts-ignore invalid SLO is not following shape of StoredSLO - saved_objects: [ - ...sloList.map((slo) => ({ - id: slo.id, - attributes: sloDefinitionSchema.encode(slo), - type: SO_SLO_TYPE, - references: [], - score: 1, - })), - ...(includeInvalidStoredSLO - ? [ - { - id: 'invalid-so-id', - type: SO_SLO_TYPE, - references: [], - score: 1, - attributes: { id: INVALID_SLO_ID, name: 'invalid' }, - }, - ] - : []), - ], - }; -} - -describe('KibanaSavedObjectsSLORepository', () => { - let loggerMock: jest.Mocked; - let soClientMock: jest.Mocked; - - beforeEach(() => { - loggerMock = loggingSystemMock.createLogger(); - soClientMock = savedObjectsClientMock.create(); - }); - - describe('validation', () => { - it('findById throws when an SLO is not found', async () => { - soClientMock.find.mockResolvedValueOnce(soFindResponse([])); - const repository = new KibanaSavedObjectsSLORepository(soClientMock, loggerMock); - - await expect(repository.findById('inexistant-slo-id')).rejects.toThrowError( - new SLONotFound('SLO [inexistant-slo-id] not found') - ); - }); - - it('deleteById throws when an SLO is not found', async () => { - soClientMock.find.mockResolvedValueOnce(soFindResponse([])); - const repository = new KibanaSavedObjectsSLORepository(soClientMock, loggerMock); - - await expect(repository.deleteById('inexistant-slo-id')).rejects.toThrowError( - new SLONotFound('SLO [inexistant-slo-id] not found') - ); - }); - }); - - describe('saving an SLO', () => { - it('checking existing id for slo', async () => { - const slo = createSLO({ id: 'my-id' }); - soClientMock.find.mockResolvedValueOnce(soFindResponse([])); - soClientMock.create.mockResolvedValueOnce(aStoredSLO(slo)); - const repository = new KibanaSavedObjectsSLORepository(soClientMock, loggerMock); - - await repository.exists(slo.id); - - expect(soClientMock.find).toHaveBeenCalledWith({ - type: SO_SLO_TYPE, - perPage: 0, - filter: `slo.attributes.id:(${slo.id})`, - }); - }); - - it('saves the new SLO', async () => { - const slo = createSLO({ id: 'my-id' }); - soClientMock.find.mockResolvedValueOnce(soFindResponse([])); - soClientMock.create.mockResolvedValueOnce(aStoredSLO(slo)); - const repository = new KibanaSavedObjectsSLORepository(soClientMock, loggerMock); - - const savedSLO = await repository.create(slo); - - expect(savedSLO).toEqual(slo); - expect(soClientMock.create).toHaveBeenCalledWith( - SO_SLO_TYPE, - sloDefinitionSchema.encode(slo) - ); - }); - - it('checks when the SLO id already exists', async () => { - const slo = createSLO({ id: 'my-id' }); - soClientMock.find.mockResolvedValueOnce(soFindResponse([slo])); - const repository = new KibanaSavedObjectsSLORepository(soClientMock, loggerMock); - - await expect(await repository.exists(slo.id)).toEqual(true); - expect(soClientMock.find).toHaveBeenCalledWith({ - type: SO_SLO_TYPE, - perPage: 0, - filter: `slo.attributes.id:(${slo.id})`, - }); - }); - - it('updates the existing SLO', async () => { - const slo = createSLO({ id: 'my-id' }); - soClientMock.find.mockResolvedValueOnce(soFindResponse([slo])); - soClientMock.create.mockResolvedValueOnce(aStoredSLO(slo)); - const repository = new KibanaSavedObjectsSLORepository(soClientMock, loggerMock); - - const savedSLO = await repository.update(slo); - - expect(savedSLO).toEqual(slo); - - expect(soClientMock.create).toHaveBeenCalledWith( - SO_SLO_TYPE, - sloDefinitionSchema.encode(slo), - { - id: 'my-id', - overwrite: true, - } - ); - }); - }); - - describe('Find SLO', () => { - it('finds an existing SLO', async () => { - const repository = new KibanaSavedObjectsSLORepository(soClientMock, loggerMock); - soClientMock.find.mockResolvedValueOnce(soFindResponse([SOME_SLO])); - - const foundSLO = await repository.findById(SOME_SLO.id); - - expect(foundSLO).toEqual(SOME_SLO); - expect(soClientMock.find).toHaveBeenCalledWith({ - type: SO_SLO_TYPE, - page: 1, - perPage: 1, - filter: `slo.attributes.id:(${SOME_SLO.id})`, - }); - }); - - it('throws and logs error on invalid stored SLO', async () => { - const INCLUDE_INVALID_STORED_SLO = true; - const repository = new KibanaSavedObjectsSLORepository(soClientMock, loggerMock); - soClientMock.find.mockResolvedValueOnce(soFindResponse([], INCLUDE_INVALID_STORED_SLO)); - - await expect(repository.findById(INVALID_SLO_ID)).rejects.toThrowError( - new Error('Invalid stored SLO') - ); - - expect(loggerMock.error).toHaveBeenCalled(); - }); - }); - - describe('Find all SLO by ids', () => { - it('returns the SLOs', async () => { - const repository = new KibanaSavedObjectsSLORepository(soClientMock, loggerMock); - soClientMock.find.mockResolvedValueOnce(soFindResponse([SOME_SLO, ANOTHER_SLO])); - - const results = await repository.findAllByIds([SOME_SLO.id, ANOTHER_SLO.id]); - - expect(results).toEqual([SOME_SLO, ANOTHER_SLO]); - expect(soClientMock.find).toHaveBeenCalledWith({ - type: SO_SLO_TYPE, - page: 1, - perPage: 2, - filter: `slo.attributes.id:(${SOME_SLO.id} or ${ANOTHER_SLO.id})`, - }); - }); - - it('handles invalid stored SLO by logging error', async () => { - const INCLUDE_INVALID_STORED_SLO = true; - const repository = new KibanaSavedObjectsSLORepository(soClientMock, loggerMock); - soClientMock.find.mockResolvedValueOnce( - soFindResponse([SOME_SLO, ANOTHER_SLO], INCLUDE_INVALID_STORED_SLO) - ); - - const results = await repository.findAllByIds([SOME_SLO.id, INVALID_SLO_ID, ANOTHER_SLO.id]); - - expect(loggerMock.error).toHaveBeenCalled(); - expect(results).toEqual([SOME_SLO, ANOTHER_SLO]); - }); - }); - - it('deletes an SLO', async () => { - const repository = new KibanaSavedObjectsSLORepository(soClientMock, loggerMock); - soClientMock.find.mockResolvedValueOnce(soFindResponse([SOME_SLO])); - - await repository.deleteById(SOME_SLO.id); - - expect(soClientMock.find).toHaveBeenCalledWith({ - type: SO_SLO_TYPE, - page: 1, - perPage: 1, - filter: `slo.attributes.id:(${SOME_SLO.id})`, - }); - expect(soClientMock.delete).toHaveBeenCalledWith(SO_SLO_TYPE, SOME_SLO.id); - }); - - describe('search', () => { - it('searches by name', async () => { - const repository = new KibanaSavedObjectsSLORepository(soClientMock, loggerMock); - soClientMock.find.mockResolvedValueOnce(soFindResponse([SOME_SLO, ANOTHER_SLO])); - - const results = await repository.search(SOME_SLO.name, { page: 1, perPage: 100 }); - - expect(results.results).toEqual([SOME_SLO, ANOTHER_SLO]); - expect(soClientMock.find).toHaveBeenCalledWith({ - type: SO_SLO_TYPE, - page: 1, - perPage: 100, - search: SOME_SLO.name, - searchFields: ['name'], - }); - }); - - it('searches only the outdated ones', async () => { - const repository = new KibanaSavedObjectsSLORepository(soClientMock, loggerMock); - soClientMock.find.mockResolvedValueOnce(soFindResponse([SOME_SLO, ANOTHER_SLO])); - - const results = await repository.search( - SOME_SLO.name, - { page: 1, perPage: 100 }, - { includeOutdatedOnly: true } - ); - - expect(results.results).toEqual([SOME_SLO, ANOTHER_SLO]); - expect(soClientMock.find).toHaveBeenCalledWith({ - type: SO_SLO_TYPE, - page: 1, - perPage: 100, - search: SOME_SLO.name, - searchFields: ['name'], - filter: `slo.attributes.version < ${SLO_MODEL_VERSION}`, - }); - }); - - it('handles invalid stored SLO by logging error', async () => { - const INCLUDE_INVALID_STORED_SLO = true; - const repository = new KibanaSavedObjectsSLORepository(soClientMock, loggerMock); - soClientMock.find.mockResolvedValueOnce( - soFindResponse([SOME_SLO, ANOTHER_SLO], INCLUDE_INVALID_STORED_SLO) - ); - - const results = await repository.search('*', { page: 1, perPage: 100 }); - - expect(loggerMock.error).toHaveBeenCalled(); - expect(results.results).toEqual([SOME_SLO, ANOTHER_SLO]); - }); - }); -}); diff --git a/x-pack/solutions/observability/plugins/slo/server/services/slo_settings.ts b/x-pack/solutions/observability/plugins/slo/server/services/slo_settings.ts index 3874ab808dc34..d6ef76e4f2458 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/slo_settings.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/slo_settings.ts @@ -11,7 +11,7 @@ import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-server'; import { PutSLOSettingsParams, sloSettingsSchema } from '@kbn/slo-schema'; import { DEFAULT_STALE_SLO_THRESHOLD_HOURS, - SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + SUMMARY_DESTINATION_INDEX_PATTERN, } from '../../common/constants'; import { getListOfSloSummaryIndices } from '../../common/summary_indices'; import { SLOSettings, StoredSLOSettings } from '../domain/models'; @@ -62,7 +62,7 @@ export const getListOfSummaryIndices = async ( ) => { const { useAllRemoteClusters, selectedRemoteClusters } = settings; if (!useAllRemoteClusters && selectedRemoteClusters.length === 0) { - return { indices: [SLO_SUMMARY_DESTINATION_INDEX_PATTERN], settings }; + return { indices: [SUMMARY_DESTINATION_INDEX_PATTERN], settings }; } const clustersByName = await esClient.cluster.remoteInfo(); diff --git a/x-pack/solutions/observability/plugins/slo/server/services/summary_client.test.ts b/x-pack/solutions/observability/plugins/slo/server/services/summary_client.test.ts index 120285f374f4d..92433476c6515 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/summary_client.test.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/summary_client.test.ts @@ -7,7 +7,7 @@ import { ElasticsearchClientMock, elasticsearchServiceMock } from '@kbn/core/server/mocks'; import moment from 'moment'; -import { SLO_DESTINATION_INDEX_PATTERN } from '../../common/constants'; +import { SLI_DESTINATION_INDEX_PATTERN } from '../../common/constants'; import { Duration, DurationUnit } from '../domain/models'; import { BurnRatesClient } from './burn_rates_client'; import { createSLO } from './fixtures/slo'; @@ -59,7 +59,7 @@ describe('SummaryClient', () => { expect(result).toMatchSnapshot(); expect(esClientMock.search.mock.calls[0][0]).toEqual({ - index: SLO_DESTINATION_INDEX_PATTERN, + index: SLI_DESTINATION_INDEX_PATTERN, size: 0, query: { bool: { @@ -93,7 +93,7 @@ describe('SummaryClient', () => { await summaryClient.computeSummary({ slo }); expect(esClientMock.search.mock.calls[0][0]).toEqual({ - index: SLO_DESTINATION_INDEX_PATTERN, + index: SLI_DESTINATION_INDEX_PATTERN, size: 0, query: { bool: { @@ -137,7 +137,7 @@ describe('SummaryClient', () => { expect(result).toMatchSnapshot(); expect(esClientMock.search.mock.calls[0][0]).toEqual({ - index: SLO_DESTINATION_INDEX_PATTERN, + index: SLI_DESTINATION_INDEX_PATTERN, size: 0, query: { bool: { @@ -179,7 +179,7 @@ describe('SummaryClient', () => { expect(result).toMatchSnapshot(); expect(esClientMock.search.mock.calls[0][0]).toEqual({ - index: SLO_DESTINATION_INDEX_PATTERN, + index: SLI_DESTINATION_INDEX_PATTERN, size: 0, query: { bool: { diff --git a/x-pack/solutions/observability/plugins/slo/server/services/summary_client.ts b/x-pack/solutions/observability/plugins/slo/server/services/summary_client.ts index 23110db94cdde..bb98c4443f0f2 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/summary_client.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/summary_client.ts @@ -19,7 +19,7 @@ import { occurrencesBudgetingMethodSchema, timeslicesBudgetingMethodSchema, } from '@kbn/slo-schema'; -import { SLO_DESTINATION_INDEX_PATTERN } from '../../common/constants'; +import { SLI_DESTINATION_INDEX_PATTERN } from '../../common/constants'; import { DateRange, Groupings, Meta, SLODefinition, Summary } from '../domain/models'; import { computeSLI, computeSummaryStatus, toErrorBudget } from '../domain/services'; import { toDateRange } from '../domain/services/date_range'; @@ -69,8 +69,8 @@ export class DefaultSummaryClient implements SummaryClient { } >({ index: remoteName - ? `${remoteName}:${SLO_DESTINATION_INDEX_PATTERN}` - : SLO_DESTINATION_INDEX_PATTERN, + ? `${remoteName}:${SLI_DESTINATION_INDEX_PATTERN}` + : SLI_DESTINATION_INDEX_PATTERN, size: 0, query: { bool: { diff --git a/x-pack/solutions/observability/plugins/slo/server/services/summary_search_client/summary_search_client.ts b/x-pack/solutions/observability/plugins/slo/server/services/summary_search_client/summary_search_client.ts index 5c1c0e9e780cb..9ef20d333cc75 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/summary_search_client/summary_search_client.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/summary_search_client/summary_search_client.ts @@ -11,7 +11,7 @@ import { isCCSRemoteIndexName } from '@kbn/es-query'; import { ALL_VALUE } from '@kbn/slo-schema'; import { assertNever } from '@kbn/std'; import { partition } from 'lodash'; -import { SLO_SUMMARY_DESTINATION_INDEX_PATTERN } from '../../../common/constants'; +import { SUMMARY_DESTINATION_INDEX_PATTERN } from '../../../common/constants'; import { StoredSLOSettings } from '../../domain/models'; import { toHighPrecision } from '../../utils/number'; import { createEsParams, typedSearch } from '../../utils/queries'; @@ -170,7 +170,7 @@ export class DefaultSummarySearchClient implements SummarySearchClient { // The temp summary documents are _eventually_ removed as we get through the real summary documents await this.esClient.deleteByQuery({ - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, wait_for_completion: false, query: { bool: { diff --git a/x-pack/solutions/observability/plugins/slo/server/services/summary_transform_generator/generators/occurrences.ts b/x-pack/solutions/observability/plugins/slo/server/services/summary_transform_generator/generators/occurrences.ts index ab5377e38b12e..4615222dd7525 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/summary_transform_generator/generators/occurrences.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/summary_transform_generator/generators/occurrences.ts @@ -10,9 +10,9 @@ import { calendarAlignedTimeWindowSchema, DurationUnit } from '@kbn/slo-schema'; import { getSLOSummaryPipelineId, getSLOSummaryTransformId, - SLO_DESTINATION_INDEX_NAME, + SLI_DESTINATION_INDEX_NAME, SLO_RESOURCES_VERSION, - SLO_SUMMARY_DESTINATION_INDEX_NAME, + SUMMARY_DESTINATION_INDEX_NAME, } from '../../../../common/constants'; import { SLODefinition } from '../../../domain/models'; import { getGroupBy } from './common'; @@ -37,10 +37,10 @@ export function generateSummaryTransformForOccurrences( transform_id: getSLOSummaryTransformId(slo.id, slo.revision), dest: { pipeline: getSLOSummaryPipelineId(slo.id, slo.revision), - index: SLO_SUMMARY_DESTINATION_INDEX_NAME, + index: SUMMARY_DESTINATION_INDEX_NAME, }, source: { - index: `${SLO_DESTINATION_INDEX_NAME}*`, + index: `${SLI_DESTINATION_INDEX_NAME}*`, query: { bool: { filter: [ diff --git a/x-pack/solutions/observability/plugins/slo/server/services/summary_transform_generator/generators/timeslices_calendar_aligned.ts b/x-pack/solutions/observability/plugins/slo/server/services/summary_transform_generator/generators/timeslices_calendar_aligned.ts index f5db77467c94d..52949158ca951 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/summary_transform_generator/generators/timeslices_calendar_aligned.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/summary_transform_generator/generators/timeslices_calendar_aligned.ts @@ -9,9 +9,9 @@ import { TransformPutTransformRequest } from '@elastic/elasticsearch/lib/api/typ import { getSLOSummaryPipelineId, getSLOSummaryTransformId, - SLO_DESTINATION_INDEX_NAME, + SLI_DESTINATION_INDEX_NAME, SLO_RESOURCES_VERSION, - SLO_SUMMARY_DESTINATION_INDEX_NAME, + SUMMARY_DESTINATION_INDEX_NAME, } from '../../../../common/constants'; import { DurationUnit, SLODefinition } from '../../../domain/models'; import { getGroupBy } from './common'; @@ -27,10 +27,10 @@ export function generateSummaryTransformForTimeslicesAndCalendarAligned( transform_id: getSLOSummaryTransformId(slo.id, slo.revision), dest: { pipeline: getSLOSummaryPipelineId(slo.id, slo.revision), - index: SLO_SUMMARY_DESTINATION_INDEX_NAME, + index: SUMMARY_DESTINATION_INDEX_NAME, }, source: { - index: `${SLO_DESTINATION_INDEX_NAME}*`, + index: `${SLI_DESTINATION_INDEX_NAME}*`, query: { bool: { filter: [ diff --git a/x-pack/solutions/observability/plugins/slo/server/services/summary_transform_generator/generators/timeslices_rolling.ts b/x-pack/solutions/observability/plugins/slo/server/services/summary_transform_generator/generators/timeslices_rolling.ts index 05724cb9e43d6..c5f06b465d896 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/summary_transform_generator/generators/timeslices_rolling.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/summary_transform_generator/generators/timeslices_rolling.ts @@ -9,9 +9,9 @@ import { TransformPutTransformRequest } from '@elastic/elasticsearch/lib/api/typ import { getSLOSummaryPipelineId, getSLOSummaryTransformId, - SLO_DESTINATION_INDEX_NAME, + SLI_DESTINATION_INDEX_NAME, SLO_RESOURCES_VERSION, - SLO_SUMMARY_DESTINATION_INDEX_NAME, + SUMMARY_DESTINATION_INDEX_NAME, } from '../../../../common/constants'; import { SLODefinition } from '../../../domain/models'; import { getGroupBy } from './common'; @@ -28,10 +28,10 @@ export function generateSummaryTransformForTimeslicesAndRolling( transform_id: getSLOSummaryTransformId(slo.id, slo.revision), dest: { pipeline: getSLOSummaryPipelineId(slo.id, slo.revision), - index: SLO_SUMMARY_DESTINATION_INDEX_NAME, + index: SUMMARY_DESTINATION_INDEX_NAME, }, source: { - index: `${SLO_DESTINATION_INDEX_NAME}*`, + index: `${SLI_DESTINATION_INDEX_NAME}*`, query: { bool: { filter: [ diff --git a/x-pack/solutions/observability/plugins/slo/server/services/tasks/orphan_summary_cleanup_task.test.ts b/x-pack/solutions/observability/plugins/slo/server/services/tasks/orphan_summary_cleanup_task.test.ts index 31b74b3cf9ed4..dc714d8ee8dd4 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/tasks/orphan_summary_cleanup_task.test.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/tasks/orphan_summary_cleanup_task.test.ts @@ -10,7 +10,7 @@ import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks import { loggerMock } from '@kbn/logging-mocks'; import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks'; import { times } from 'lodash'; -import { SLO_SUMMARY_DESTINATION_INDEX_PATTERN } from '../../../common/constants'; +import { SUMMARY_DESTINATION_INDEX_PATTERN } from '../../../common/constants'; import { getDeleteQueryFilter, SloOrphanSummaryCleanupTask } from './orphan_summary_cleanup_task'; const taskManagerSetup = taskManagerMock.createSetup(); @@ -59,7 +59,7 @@ describe('SloSummaryCleanupTask', () => { expect(task.fetchSloSummariesIds).toHaveBeenCalled(); expect(esClient.deleteByQuery).toHaveBeenCalledWith({ - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, query: { bool: { should: [ @@ -100,7 +100,7 @@ describe('SloSummaryCleanupTask', () => { expect(esClient.deleteByQuery).toHaveBeenCalledTimes(1); expect(esClient.deleteByQuery).toHaveBeenNthCalledWith(1, { wait_for_completion: false, - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, query: { bool: { should: getDeleteQueryFilter([ @@ -158,7 +158,7 @@ describe('SloSummaryCleanupTask', () => { expect(esClient.deleteByQuery).toHaveBeenCalledTimes(2); expect(esClient.deleteByQuery).toHaveBeenNthCalledWith(1, { - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, query: { bool: { should: getDeleteQueryFilter([ @@ -174,7 +174,7 @@ describe('SloSummaryCleanupTask', () => { expect(esClient.deleteByQuery).toHaveBeenLastCalledWith({ wait_for_completion: false, - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, query: { bool: { should: getDeleteQueryFilter([ @@ -232,7 +232,7 @@ describe('SloSummaryCleanupTask', () => { expect(esClient.deleteByQuery).toHaveBeenCalledTimes(2); expect(esClient.deleteByQuery).toHaveBeenNthCalledWith(1, { wait_for_completion: false, - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, query: { bool: { should: getDeleteQueryFilter([ @@ -246,7 +246,7 @@ describe('SloSummaryCleanupTask', () => { }); expect(esClient.deleteByQuery).toHaveBeenLastCalledWith({ wait_for_completion: false, - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, query: { bool: { should: getDeleteQueryFilter([ @@ -300,7 +300,7 @@ describe('SloSummaryCleanupTask', () => { expect(esClient.deleteByQuery).toHaveBeenNthCalledWith(1, { wait_for_completion: false, - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, query: { bool: { should: getDeleteQueryFilter([ diff --git a/x-pack/solutions/observability/plugins/slo/server/services/tasks/orphan_summary_cleanup_task.ts b/x-pack/solutions/observability/plugins/slo/server/services/tasks/orphan_summary_cleanup_task.ts index 6d0aa1ee9c587..55316671ef05f 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/tasks/orphan_summary_cleanup_task.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/tasks/orphan_summary_cleanup_task.ts @@ -15,7 +15,7 @@ import { AggregationsCompositeAggregateKey } from '@elastic/elasticsearch/lib/ap import { ALL_SPACES_ID } from '@kbn/spaces-plugin/common/constants'; import { StoredSLODefinition } from '../../domain/models'; import { SO_SLO_TYPE } from '../../saved_objects'; -import { SLO_SUMMARY_DESTINATION_INDEX_PATTERN } from '../../../common/constants'; +import { SUMMARY_DESTINATION_INDEX_PATTERN } from '../../../common/constants'; import { SLOConfig } from '../../types'; export const TASK_TYPE = 'SLO:ORPHAN_SUMMARIES-CLEANUP-TASK'; @@ -106,7 +106,7 @@ export class SloOrphanSummaryCleanupTask { await this.esClient.deleteByQuery({ wait_for_completion: false, - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, query: { bool: { should: getDeleteQueryFilter(sloSummaryIdsToDelete.sort()), @@ -149,7 +149,7 @@ export class SloOrphanSummaryCleanupTask { } >({ size: 0, - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, aggs: { slos: { composite: { diff --git a/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/apm_transaction_duration.ts b/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/apm_transaction_duration.ts index 99361fa776789..71b14ac5c3477 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/apm_transaction_duration.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/apm_transaction_duration.ts @@ -16,7 +16,7 @@ import { } from '@kbn/slo-schema'; import { TransformGenerator, getElasticsearchQueryOrThrow } from '.'; import { - SLO_DESTINATION_INDEX_NAME, + SLI_DESTINATION_INDEX_NAME, getSLOPipelineId, getSLOTransformId, } from '../../../common/constants'; @@ -133,7 +133,7 @@ export class ApmTransactionDurationTransformGenerator extends TransformGenerator private buildDestination(slo: SLODefinition) { return { pipeline: getSLOPipelineId(slo.id, slo.revision), - index: SLO_DESTINATION_INDEX_NAME, + index: SLI_DESTINATION_INDEX_NAME, }; } diff --git a/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/apm_transaction_error_rate.ts b/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/apm_transaction_error_rate.ts index a65e4ae1d50dd..5e78b598cfd9c 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/apm_transaction_error_rate.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/apm_transaction_error_rate.ts @@ -15,7 +15,7 @@ import { } from '@kbn/slo-schema'; import { TransformGenerator, getElasticsearchQueryOrThrow } from '.'; import { - SLO_DESTINATION_INDEX_NAME, + SLI_DESTINATION_INDEX_NAME, getSLOPipelineId, getSLOTransformId, } from '../../../common/constants'; @@ -132,7 +132,7 @@ export class ApmTransactionErrorRateTransformGenerator extends TransformGenerato private buildDestination(slo: SLODefinition) { return { pipeline: getSLOPipelineId(slo.id, slo.revision), - index: SLO_DESTINATION_INDEX_NAME, + index: SLI_DESTINATION_INDEX_NAME, }; } diff --git a/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/histogram.ts b/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/histogram.ts index 805e18c9c31db..6a2b0cc5d7a85 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/histogram.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/histogram.ts @@ -14,7 +14,7 @@ import { } from '@kbn/slo-schema'; import { TransformGenerator, getElasticsearchQueryOrThrow, parseIndex } from '.'; import { - SLO_DESTINATION_INDEX_NAME, + SLI_DESTINATION_INDEX_NAME, getSLOPipelineId, getSLOTransformId, } from '../../../common/constants'; @@ -70,7 +70,7 @@ export class HistogramTransformGenerator extends TransformGenerator { private buildDestination(slo: SLODefinition) { return { pipeline: getSLOPipelineId(slo.id, slo.revision), - index: SLO_DESTINATION_INDEX_NAME, + index: SLI_DESTINATION_INDEX_NAME, }; } diff --git a/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/kql_custom.ts b/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/kql_custom.ts index 61238c82ab600..31ba600f04ede 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/kql_custom.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/kql_custom.ts @@ -10,7 +10,7 @@ import { DataViewsService } from '@kbn/data-views-plugin/common'; import { kqlCustomIndicatorSchema, timeslicesBudgetingMethodSchema } from '@kbn/slo-schema'; import { TransformGenerator, getElasticsearchQueryOrThrow, parseIndex } from '.'; import { - SLO_DESTINATION_INDEX_NAME, + SLI_DESTINATION_INDEX_NAME, getSLOPipelineId, getSLOTransformId, } from '../../../common/constants'; @@ -64,7 +64,7 @@ export class KQLCustomTransformGenerator extends TransformGenerator { private buildDestination(slo: SLODefinition) { return { pipeline: getSLOPipelineId(slo.id, slo.revision), - index: SLO_DESTINATION_INDEX_NAME, + index: SLI_DESTINATION_INDEX_NAME, }; } diff --git a/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/metric_custom.ts b/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/metric_custom.ts index f2259955bdfb0..eada58df14160 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/metric_custom.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/metric_custom.ts @@ -13,7 +13,7 @@ import { getElasticsearchQueryOrThrow, parseIndex, TransformGenerator } from '.' import { getSLOPipelineId, getSLOTransformId, - SLO_DESTINATION_INDEX_NAME, + SLI_DESTINATION_INDEX_NAME, } from '../../../common/constants'; import { getSLOTransformTemplate } from '../../assets/transform_templates/slo_transform_template'; import { MetricCustomIndicator, SLODefinition } from '../../domain/models'; @@ -68,7 +68,7 @@ export class MetricCustomTransformGenerator extends TransformGenerator { private buildDestination(slo: SLODefinition) { return { pipeline: getSLOPipelineId(slo.id, slo.revision), - index: SLO_DESTINATION_INDEX_NAME, + index: SLI_DESTINATION_INDEX_NAME, }; } diff --git a/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/synthetics_availability.ts b/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/synthetics_availability.ts index 65fda9c3fc222..479674a325b78 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/synthetics_availability.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/synthetics_availability.ts @@ -18,7 +18,7 @@ import { getElasticsearchQueryOrThrow, TransformGenerator } from '.'; import { getSLOPipelineId, getSLOTransformId, - SLO_DESTINATION_INDEX_NAME, + SLI_DESTINATION_INDEX_NAME, SYNTHETICS_DEFAULT_GROUPINGS, SYNTHETICS_INDEX_PATTERN, } from '../../../common/constants'; @@ -163,7 +163,7 @@ export class SyntheticsAvailabilityTransformGenerator extends TransformGenerator private buildDestination(slo: SLODefinition) { return { pipeline: getSLOPipelineId(slo.id, slo.revision), - index: SLO_DESTINATION_INDEX_NAME, + index: SLI_DESTINATION_INDEX_NAME, }; } diff --git a/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/timeslice_metric.ts b/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/timeslice_metric.ts index e2f305e68fee8..04cf94d489cc8 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/timeslice_metric.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/transform_generators/timeslice_metric.ts @@ -17,7 +17,7 @@ import { getElasticsearchQueryOrThrow, parseIndex, TransformGenerator } from '.' import { getSLOPipelineId, getSLOTransformId, - SLO_DESTINATION_INDEX_NAME, + SLI_DESTINATION_INDEX_NAME, } from '../../../common/constants'; import { getSLOTransformTemplate } from '../../assets/transform_templates/slo_transform_template'; import { SLODefinition } from '../../domain/models'; @@ -73,7 +73,7 @@ export class TimesliceMetricTransformGenerator extends TransformGenerator { private buildDestination(slo: SLODefinition) { return { pipeline: getSLOPipelineId(slo.id, slo.revision), - index: SLO_DESTINATION_INDEX_NAME, + index: SLI_DESTINATION_INDEX_NAME, }; } diff --git a/x-pack/solutions/observability/plugins/slo/server/services/update_slo.test.ts b/x-pack/solutions/observability/plugins/slo/server/services/update_slo.test.ts index 81084683d7978..2f4d9729bf977 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/update_slo.test.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/update_slo.test.ts @@ -20,9 +20,9 @@ import { SecurityHasPrivilegesResponse } from '@elastic/elasticsearch/lib/api/ty import { getSLOSummaryTransformId, getSLOTransformId, - SLO_DESTINATION_INDEX_PATTERN, + SLI_DESTINATION_INDEX_PATTERN, SLO_RESOURCES_VERSION, - SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + SUMMARY_DESTINATION_INDEX_PATTERN, } from '../../common/constants'; import { SLODefinition } from '../domain/models'; import { fiveMinute, oneMinute } from './fixtures/duration'; @@ -498,7 +498,7 @@ describe('UpdateSLO', () => { expect(mockEsClient.deleteByQuery).toHaveBeenNthCalledWith( 1, expect.objectContaining({ - index: SLO_DESTINATION_INDEX_PATTERN, + index: SLI_DESTINATION_INDEX_PATTERN, query: { bool: { filter: [ @@ -512,7 +512,7 @@ describe('UpdateSLO', () => { expect(mockEsClient.deleteByQuery).toHaveBeenNthCalledWith( 2, expect.objectContaining({ - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, query: { bool: { filter: [ diff --git a/x-pack/solutions/observability/plugins/slo/server/services/update_slo.ts b/x-pack/solutions/observability/plugins/slo/server/services/update_slo.ts index 05f518f0946a9..b526d4ff6fba9 100644 --- a/x-pack/solutions/observability/plugins/slo/server/services/update_slo.ts +++ b/x-pack/solutions/observability/plugins/slo/server/services/update_slo.ts @@ -10,17 +10,17 @@ import { UpdateSLOParams, UpdateSLOResponse, updateSLOResponseSchema } from '@kb import { asyncForEach } from '@kbn/std'; import { isEqual, pick } from 'lodash'; import { - SLO_DESTINATION_INDEX_PATTERN, + SLI_DESTINATION_INDEX_PATTERN, SLO_RESOURCES_VERSION, - SLO_SUMMARY_DESTINATION_INDEX_PATTERN, - SLO_SUMMARY_TEMP_INDEX_NAME, + SUMMARY_DESTINATION_INDEX_PATTERN, + SUMMARY_TEMP_INDEX_NAME, getSLOPipelineId, getSLOSummaryPipelineId, getSLOSummaryTransformId, getSLOTransformId, } from '../../common/constants'; -import { getSLOPipelineTemplate } from '../assets/ingest_templates/slo_pipeline_template'; -import { getSLOSummaryPipelineTemplate } from '../assets/ingest_templates/slo_summary_pipeline_template'; +import { getSLIPipelineTemplate } from '../assets/ingest_templates/sli_pipeline_template'; +import { getSummaryPipelineTemplate } from '../assets/ingest_templates/summary_pipeline_template'; import { SLODefinition } from '../domain/models'; import { validateSLO } from '../domain/services'; import { SecurityException } from '../errors'; @@ -77,7 +77,7 @@ export class UpdateSLO { await retryTransientEsErrors( () => this.scopedClusterClient.asSecondaryAuthUser.ingest.putPipeline( - getSLOSummaryPipelineTemplate(updatedSlo, this.spaceId, this.basePath) + getSummaryPipelineTemplate(updatedSlo, this.spaceId, this.basePath) ), { logger: this.logger } ); @@ -111,7 +111,7 @@ export class UpdateSLO { await retryTransientEsErrors( () => this.scopedClusterClient.asSecondaryAuthUser.ingest.putPipeline( - getSLOPipelineTemplate(updatedSlo) + getSLIPipelineTemplate(updatedSlo) ), { logger: this.logger } ); @@ -131,7 +131,7 @@ export class UpdateSLO { await retryTransientEsErrors( () => this.scopedClusterClient.asSecondaryAuthUser.ingest.putPipeline( - getSLOSummaryPipelineTemplate(updatedSlo, this.spaceId, this.basePath) + getSummaryPipelineTemplate(updatedSlo, this.spaceId, this.basePath) ), { logger: this.logger } ); @@ -153,7 +153,7 @@ export class UpdateSLO { await retryTransientEsErrors( () => this.esClient.index({ - index: SLO_SUMMARY_TEMP_INDEX_NAME, + index: SUMMARY_TEMP_INDEX_NAME, id: `slo-${updatedSlo.id}`, document: createTempSummaryDocument(updatedSlo, this.spaceId, this.basePath), refresh: true, @@ -238,7 +238,7 @@ export class UpdateSLO { private async deleteRollupData(sloId: string, sloRevision: number): Promise { await this.esClient.deleteByQuery({ - index: SLO_DESTINATION_INDEX_PATTERN, + index: SLI_DESTINATION_INDEX_PATTERN, wait_for_completion: false, query: { bool: { @@ -250,7 +250,7 @@ export class UpdateSLO { private async deleteSummaryData(sloId: string, sloRevision: number): Promise { await this.esClient.deleteByQuery({ - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, refresh: true, query: { bool: { diff --git a/x-pack/test/api_integration/apis/slos/helper/es.ts b/x-pack/test/api_integration/apis/slos/helper/es.ts index f5ac7a6e23c88..eed0df0430e07 100644 --- a/x-pack/test/api_integration/apis/slos/helper/es.ts +++ b/x-pack/test/api_integration/apis/slos/helper/es.ts @@ -6,8 +6,8 @@ */ import { Client } from '@elastic/elasticsearch'; import { - SLO_DESTINATION_INDEX_PATTERN, - SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + SLI_DESTINATION_INDEX_PATTERN, + SUMMARY_DESTINATION_INDEX_PATTERN, } from '@kbn/slo-plugin/common/constants'; export class SloEsClient { @@ -15,7 +15,7 @@ export class SloEsClient { public async getSLOSummaryDataById(id: string) { return await this.esClient.search({ - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, body: { query: { bool: { @@ -35,7 +35,7 @@ export class SloEsClient { public async getSLORollupDataById(id: string) { return await this.esClient.search({ - index: SLO_DESTINATION_INDEX_PATTERN, + index: SLI_DESTINATION_INDEX_PATTERN, body: { query: { bool: { diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/slo/delete_slo.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/slo/delete_slo.ts index 733d2b6250c29..d1e3fe6e53b68 100644 --- a/x-pack/test/api_integration/deployment_agnostic/apis/observability/slo/delete_slo.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/slo/delete_slo.ts @@ -9,8 +9,8 @@ import { cleanup, generate } from '@kbn/data-forge'; import expect from '@kbn/expect'; import { RoleCredentials } from '@kbn/ftr-common-functional-services'; import { - SLO_DESTINATION_INDEX_PATTERN, - SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + SLI_DESTINATION_INDEX_PATTERN, + SUMMARY_DESTINATION_INDEX_PATTERN, getSLOSummaryTransformId, getSLOTransformId, } from '@kbn/slo-plugin/common/constants'; @@ -73,7 +73,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { // expect summary and rollup documents to be deleted await retry.waitForWithTimeout('SLO summary data is deleted', 60 * 1000, async () => { const sloSummaryResponseAfterDeletion = await esClient.search({ - index: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, + index: SUMMARY_DESTINATION_INDEX_PATTERN, body: { query: { bool: { @@ -97,7 +97,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { await retry.waitForWithTimeout('SLO rollup data is deleted', 60 * 1000, async () => { const sloRollupResponseAfterDeletion = await esClient.search({ - index: SLO_DESTINATION_INDEX_PATTERN, + index: SLI_DESTINATION_INDEX_PATTERN, body: { query: { bool: { diff --git a/x-pack/test/api_integration/services/slo.ts b/x-pack/test/api_integration/services/slo.ts index d0d6cdc190e0e..9244ad7ee00d7 100644 --- a/x-pack/test/api_integration/services/slo.ts +++ b/x-pack/test/api_integration/services/slo.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { SLO_SUMMARY_DESTINATION_INDEX_NAME } from '@kbn/slo-plugin/common/constants'; +import { SUMMARY_DESTINATION_INDEX_NAME } from '@kbn/slo-plugin/common/constants'; import { TOTAL_INDEX_PRIVILEGE_SET_EDITOR } from '@kbn/slo-plugin/server/services/get_diagnosis'; import { CreateSLOInput, @@ -110,7 +110,7 @@ export function SloApiProvider({ getService }: FtrProviderContext) { .send() .expect(204); } - await waitForIndexToBeEmpty({ esClient, indexName: SLO_SUMMARY_DESTINATION_INDEX_NAME }); + await waitForIndexToBeEmpty({ esClient, indexName: SUMMARY_DESTINATION_INDEX_NAME }); }, async fetchHistoricalSummary( params: FetchHistoricalSummaryParams