Skip to content

Commit 104e375

Browse files
committed
fix(slo): use wildcard remote when useAllRemoteClusters is true
1 parent b3cdeaa commit 104e375

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

x-pack/solutions/observability/plugins/slo/common/get_slo_summary_indices.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { getSLOSummaryIndices } from './get_slo_summary_indices';
99
import { DEFAULT_STALE_SLO_THRESHOLD_HOURS, SUMMARY_DESTINATION_INDEX_PATTERN } from './constants';
1010

1111
describe('getSLOSummaryIndices', () => {
12-
it('should return default local index if disabled', function () {
12+
it('returns the local index if disabled', function () {
1313
const settings = {
1414
useAllRemoteClusters: false,
1515
selectedRemoteClusters: [],
@@ -19,7 +19,7 @@ describe('getSLOSummaryIndices', () => {
1919
expect(result).toStrictEqual([SUMMARY_DESTINATION_INDEX_PATTERN]);
2020
});
2121

22-
it('should return all remote clusters when enabled', function () {
22+
it('returns a wildcard remote and the local index when useAllRemoteClusters is true', function () {
2323
const settings = {
2424
useAllRemoteClusters: true,
2525
selectedRemoteClusters: [],
@@ -32,20 +32,20 @@ describe('getSLOSummaryIndices', () => {
3232
const result = getSLOSummaryIndices(settings, clustersByName);
3333
expect(result).toStrictEqual([
3434
SUMMARY_DESTINATION_INDEX_PATTERN,
35-
`cluster1:${SUMMARY_DESTINATION_INDEX_PATTERN}`,
36-
`cluster2:${SUMMARY_DESTINATION_INDEX_PATTERN}`,
35+
`*:${SUMMARY_DESTINATION_INDEX_PATTERN}`,
3736
]);
3837
});
3938

40-
it('should return selected when enabled', function () {
39+
it('returns only the connected clusters from the selected list when useAllRemoteClusters is false', function () {
4140
const settings = {
4241
useAllRemoteClusters: false,
43-
selectedRemoteClusters: ['cluster1'],
42+
selectedRemoteClusters: ['cluster1', 'cluster3'],
4443
staleThresholdInHours: DEFAULT_STALE_SLO_THRESHOLD_HOURS,
4544
};
4645
const clustersByName = [
4746
{ name: 'cluster1', isConnected: true },
4847
{ name: 'cluster2', isConnected: true },
48+
{ name: 'cluster3', isConnected: false },
4949
];
5050
const result = getSLOSummaryIndices(settings, clustersByName);
5151
expect(result).toStrictEqual([

x-pack/solutions/observability/plugins/slo/common/get_slo_summary_indices.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,28 @@
88
import { GetSLOSettingsResponse } from '@kbn/slo-schema';
99
import { SUMMARY_DESTINATION_INDEX_PATTERN } from './constants';
1010

11+
/**
12+
* @returns the local SLO summary index or the remote cluster indices based on the settings.
13+
* If `useAllRemoteClusters` is false and no remote clusters are selected it returns only the local index.
14+
* If `useAllRemoteClusters` is true, it returns both the local index and a wildcard remote index.
15+
* If `useAllRemoteClusters` is false, it returns the local index and only the indices of the selected remote clusters that are connected.
16+
*/
1117
export const getSLOSummaryIndices = (
1218
settings: GetSLOSettingsResponse,
13-
remoteClusters: Array<{ name: string; isConnected: boolean }>
19+
remoteClusters: Array<{ name: string; isConnected: boolean }> = []
1420
): string[] => {
1521
const { useAllRemoteClusters, selectedRemoteClusters } = settings;
1622
if (!useAllRemoteClusters && selectedRemoteClusters.length === 0) {
1723
return [SUMMARY_DESTINATION_INDEX_PATTERN];
1824
}
1925

26+
if (useAllRemoteClusters) {
27+
return [SUMMARY_DESTINATION_INDEX_PATTERN, `*:${SUMMARY_DESTINATION_INDEX_PATTERN}`];
28+
}
29+
2030
return remoteClusters.reduce(
2131
(acc, { name, isConnected }) => {
22-
if (isConnected && (useAllRemoteClusters || selectedRemoteClusters.includes(name))) {
32+
if (isConnected && selectedRemoteClusters.includes(name)) {
2333
acc.push(`${name}:${SUMMARY_DESTINATION_INDEX_PATTERN}`);
2434
}
2535
return acc;

x-pack/solutions/observability/plugins/slo/server/services/slo_settings.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
99
import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
1010
import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-server';
1111
import { PutSLOSettingsParams, sloSettingsSchema } from '@kbn/slo-schema';
12-
import {
13-
DEFAULT_STALE_SLO_THRESHOLD_HOURS,
14-
SUMMARY_DESTINATION_INDEX_PATTERN,
15-
} from '../../common/constants';
12+
import { DEFAULT_STALE_SLO_THRESHOLD_HOURS } from '../../common/constants';
1613
import { getSLOSummaryIndices } from '../../common/get_slo_summary_indices';
1714
import { SLOSettings, StoredSLOSettings } from '../domain/models';
1815
import { SO_SLO_SETTINGS_TYPE, sloSettingsObjectId } from '../saved_objects/slo_settings';
@@ -61,8 +58,11 @@ export const getSummaryIndices = async (
6158
settings: StoredSLOSettings
6259
): Promise<{ indices: string[] }> => {
6360
const { useAllRemoteClusters, selectedRemoteClusters } = settings;
64-
if (!useAllRemoteClusters && selectedRemoteClusters.length === 0) {
65-
return { indices: [SUMMARY_DESTINATION_INDEX_PATTERN] };
61+
// If remote clusters are not used, we don't need to fetch the remote cluster info
62+
if (useAllRemoteClusters || (!useAllRemoteClusters && selectedRemoteClusters.length === 0)) {
63+
return {
64+
indices: getSLOSummaryIndices(settings),
65+
};
6666
}
6767

6868
const clustersByName = await esClient.cluster.remoteInfo();

0 commit comments

Comments
 (0)