Skip to content

Commit 4fac838

Browse files
authored
[9.2] [Infra] Fix legacy Infra search client to respect the frozen tier setting (#246438) (#246583)
# Backport This will backport the following commits from `main` to `9.2`: - [[Infra] Fix legacy Infra search client to respect the frozen tier setting (#246438)](#246438) <!--- Backport version: 10.2.0 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Carlos Crespo","email":"crespocarlos@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-12-16T15:25:48Z","message":"[Infra] Fix legacy Infra search client to respect the frozen tier setting (#246438)\n\n## Summary\n\nBasically what this #245224 does,\nbut focusing only on the Infra plugin changes\n\n`has_data` endpoint will run this when the setting is not set\n\n```json\n{\n \"index\": \"remote_cluster:metrics-*,remote_cluster:metricbeat-*\",\n \"allow_no_indices\": true,\n \"terminate_after\": 1,\n \"ignore_unavailable\": true,\n \"body\": {\n \"size\": 0,\n \"query\": {\n \"bool\": {}\n }\n }\n}\n```\n\nand this when the setting is set\n\n```json\nparams {\n \"index\": \"remote_cluster:metrics-*,remote_cluster:metricbeat-*\",\n \"allow_no_indices\": true,\n \"terminate_after\": 1,\n \"ignore_unavailable\": true,\n \"body\": {\n \"size\": 0,\n \"query\": {\n \"bool\": {\n \"filter\": [\n {\n \"bool\": {\n \"must_not\": [\n {\n \"terms\": {\n \"_tier\": [\n \"data_frozen\"\n ]\n }\n }\n ]\n }\n }\n ]\n }\n }\n }\n}\n```\n\nOther pages are affected by this change, but are not a source for the\nfrozen tier being hit because they don't run unbounded queries\n\n- Infra Inventory UI\n```json\nparams {\n \"allow_no_indices\": true,\n \"ignore_unavailable\": true,\n \"index\": \"remote_cluster:metrics-*,remote_cluster:metricbeat-*\",\n \"body\": {\n \"size\": 0,\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"bool\": {\n \"filter\": [\n {\n \"bool\": {\n \"filter\": [\n {\n \"bool\": {\n \"filter\": [\n {\n \"term\": {\n \"data_stream.dataset\": \"hostmetricsreceiver.otel\"\n }\n }\n ]\n }\n }\n ]\n }\n },\n {\n \"range\": {\n \"@timestamp\": {\n \"gte\": 1765824423511,\n \"lte\": 1765824723511,\n \"format\": \"epoch_millis\"\n }\n }\n },\n {\n \"exists\": {\n \"field\": \"host.name\"\n }\n }\n ]\n }\n }\n ],\n \"filter\": [\n {\n \"bool\": {\n \"must_not\": [\n {\n \"terms\": {\n \"_tier\": [\n \"data_frozen\"\n ]\n }\n }\n ]\n }\n }\n ]\n }\n },\n \"aggs\": {\n \"groupings\": {\n \"composite\": {\n \"size\": 2000,\n \"sources\": [\n {\n \"groupBy0\": {\n \"terms\": {\n \"field\": \"host.name\"\n }\n }\n }\n ]\n },\n \"aggs\": {\n \"histogram\": {\n \"date_histogram\": {\n \"field\": \"@timestamp\",\n \"fixed_interval\": \"60s\",\n \"offset\": \"-57511ms\",\n \"extended_bounds\": {\n \"min\": 1765824423511,\n \"max\": 1765824723511\n }\n },\n \"aggregations\": {\n \"cpu_idle\": {\n \"terms\": {\n \"field\": \"state\",\n \"include\": [\n \"idle\",\n \"wait\"\n ]\n },\n \"aggs\": {\n \"avg\": {\n \"avg\": {\n \"field\": \"system.cpu.utilization\"\n }\n }\n }\n },\n \"cpu_idle_total\": {\n \"sum_bucket\": {\n \"buckets_path\": \"cpu_idle.avg\"\n }\n },\n \"cpuV2\": {\n \"bucket_script\": {\n \"buckets_path\": {\n \"cpuIdleTotal\": \"cpu_idle_total\"\n },\n \"script\": \"1 - params.cpuIdleTotal\",\n \"gap_policy\": \"skip\"\n }\n },\n \"__metadata__\": {\n \"top_metrics\": {\n \"size\": 1,\n \"metrics\": [\n {\n \"field\": \"host.name\"\n },\n {\n \"field\": \"host.ip\"\n },\n {\n \"field\": \"host.os.name\"\n },\n {\n \"field\": \"cloud.provider\"\n }\n ],\n \"sort\": {\n \"@timestamp\": \"desc\"\n }\n }\n }\n }\n },\n \"metricsets\": {\n \"terms\": {\n \"field\": \"metricset.name\"\n }\n }\n }\n }\n }\n }\n}\n```\n- Metrics Explorer\n\n```json\n{\n \"allow_no_indices\": true,\n \"ignore_unavailable\": true,\n \"index\": \"remote_cluster:metrics-*,remote_cluster:metricbeat-*\",\n \"body\": {\n \"size\": 0,\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"bool\": {\n \"filter\": [\n null,\n {\n \"range\": {\n \"@timestamp\": {\n \"gte\": 1765821298325,\n \"lte\": 1765824898325,\n \"format\": \"epoch_millis\"\n }\n }\n }\n ]\n }\n }\n ],\n \"filter\": [\n {\n \"bool\": {\n \"must_not\": [\n {\n \"terms\": {\n \"_tier\": [\n \"data_frozen\"\n ]\n }\n }\n ]\n }\n }\n ]\n }\n },\n \"aggs\": {\n \"histogram\": {\n \"date_histogram\": {\n \"field\": \"@timestamp\",\n \"fixed_interval\": \"30s\",\n \"offset\": \"0s\",\n \"extended_bounds\": {\n \"min\": 1765821298325,\n \"max\": 1765824898325\n }\n },\n \"aggregations\": {\n \"metric_0\": {\n \"avg\": {\n \"field\": \"system.cpu.total.norm.pct\"\n }\n },\n \"metric_1\": {\n \"avg\": {\n \"field\": \"kubernetes.pod.cpu.usage.node.pct\"\n }\n },\n \"metric_2\": {\n \"avg\": {\n \"field\": \"docker.cpu.total.pct\"\n }\n }\n }\n },\n \"metricsets\": {\n \"terms\": {\n \"field\": \"metricset.name\"\n }\n }\n }\n }\n}\n```\n\n---------\n\nCo-authored-by: Nathan L Smith <nathan.smith@elastic.co>\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by: Caue Marcondes <caue.marcondes@elastic.co>\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>\nCo-authored-by: Coen Warmer <coen.warmer@gmail.com>","sha":"aedfb94b2118c1e925e5678c585ab2093b04ed12","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","v9.1.0","v8.19.0","v9.2.0","v9.3.0","ci:beta-faster-pr-build","Team:obs-presentation","v9.1.9"],"title":"[Infra] Fix legacy Infra search client to respect the frozen tier setting","number":246438,"url":"https://github.com/elastic/kibana/pull/246438","mergeCommit":{"message":"[Infra] Fix legacy Infra search client to respect the frozen tier setting (#246438)\n\n## Summary\n\nBasically what this #245224 does,\nbut focusing only on the Infra plugin changes\n\n`has_data` endpoint will run this when the setting is not set\n\n```json\n{\n \"index\": \"remote_cluster:metrics-*,remote_cluster:metricbeat-*\",\n \"allow_no_indices\": true,\n \"terminate_after\": 1,\n \"ignore_unavailable\": true,\n \"body\": {\n \"size\": 0,\n \"query\": {\n \"bool\": {}\n }\n }\n}\n```\n\nand this when the setting is set\n\n```json\nparams {\n \"index\": \"remote_cluster:metrics-*,remote_cluster:metricbeat-*\",\n \"allow_no_indices\": true,\n \"terminate_after\": 1,\n \"ignore_unavailable\": true,\n \"body\": {\n \"size\": 0,\n \"query\": {\n \"bool\": {\n \"filter\": [\n {\n \"bool\": {\n \"must_not\": [\n {\n \"terms\": {\n \"_tier\": [\n \"data_frozen\"\n ]\n }\n }\n ]\n }\n }\n ]\n }\n }\n }\n}\n```\n\nOther pages are affected by this change, but are not a source for the\nfrozen tier being hit because they don't run unbounded queries\n\n- Infra Inventory UI\n```json\nparams {\n \"allow_no_indices\": true,\n \"ignore_unavailable\": true,\n \"index\": \"remote_cluster:metrics-*,remote_cluster:metricbeat-*\",\n \"body\": {\n \"size\": 0,\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"bool\": {\n \"filter\": [\n {\n \"bool\": {\n \"filter\": [\n {\n \"bool\": {\n \"filter\": [\n {\n \"term\": {\n \"data_stream.dataset\": \"hostmetricsreceiver.otel\"\n }\n }\n ]\n }\n }\n ]\n }\n },\n {\n \"range\": {\n \"@timestamp\": {\n \"gte\": 1765824423511,\n \"lte\": 1765824723511,\n \"format\": \"epoch_millis\"\n }\n }\n },\n {\n \"exists\": {\n \"field\": \"host.name\"\n }\n }\n ]\n }\n }\n ],\n \"filter\": [\n {\n \"bool\": {\n \"must_not\": [\n {\n \"terms\": {\n \"_tier\": [\n \"data_frozen\"\n ]\n }\n }\n ]\n }\n }\n ]\n }\n },\n \"aggs\": {\n \"groupings\": {\n \"composite\": {\n \"size\": 2000,\n \"sources\": [\n {\n \"groupBy0\": {\n \"terms\": {\n \"field\": \"host.name\"\n }\n }\n }\n ]\n },\n \"aggs\": {\n \"histogram\": {\n \"date_histogram\": {\n \"field\": \"@timestamp\",\n \"fixed_interval\": \"60s\",\n \"offset\": \"-57511ms\",\n \"extended_bounds\": {\n \"min\": 1765824423511,\n \"max\": 1765824723511\n }\n },\n \"aggregations\": {\n \"cpu_idle\": {\n \"terms\": {\n \"field\": \"state\",\n \"include\": [\n \"idle\",\n \"wait\"\n ]\n },\n \"aggs\": {\n \"avg\": {\n \"avg\": {\n \"field\": \"system.cpu.utilization\"\n }\n }\n }\n },\n \"cpu_idle_total\": {\n \"sum_bucket\": {\n \"buckets_path\": \"cpu_idle.avg\"\n }\n },\n \"cpuV2\": {\n \"bucket_script\": {\n \"buckets_path\": {\n \"cpuIdleTotal\": \"cpu_idle_total\"\n },\n \"script\": \"1 - params.cpuIdleTotal\",\n \"gap_policy\": \"skip\"\n }\n },\n \"__metadata__\": {\n \"top_metrics\": {\n \"size\": 1,\n \"metrics\": [\n {\n \"field\": \"host.name\"\n },\n {\n \"field\": \"host.ip\"\n },\n {\n \"field\": \"host.os.name\"\n },\n {\n \"field\": \"cloud.provider\"\n }\n ],\n \"sort\": {\n \"@timestamp\": \"desc\"\n }\n }\n }\n }\n },\n \"metricsets\": {\n \"terms\": {\n \"field\": \"metricset.name\"\n }\n }\n }\n }\n }\n }\n}\n```\n- Metrics Explorer\n\n```json\n{\n \"allow_no_indices\": true,\n \"ignore_unavailable\": true,\n \"index\": \"remote_cluster:metrics-*,remote_cluster:metricbeat-*\",\n \"body\": {\n \"size\": 0,\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"bool\": {\n \"filter\": [\n null,\n {\n \"range\": {\n \"@timestamp\": {\n \"gte\": 1765821298325,\n \"lte\": 1765824898325,\n \"format\": \"epoch_millis\"\n }\n }\n }\n ]\n }\n }\n ],\n \"filter\": [\n {\n \"bool\": {\n \"must_not\": [\n {\n \"terms\": {\n \"_tier\": [\n \"data_frozen\"\n ]\n }\n }\n ]\n }\n }\n ]\n }\n },\n \"aggs\": {\n \"histogram\": {\n \"date_histogram\": {\n \"field\": \"@timestamp\",\n \"fixed_interval\": \"30s\",\n \"offset\": \"0s\",\n \"extended_bounds\": {\n \"min\": 1765821298325,\n \"max\": 1765824898325\n }\n },\n \"aggregations\": {\n \"metric_0\": {\n \"avg\": {\n \"field\": \"system.cpu.total.norm.pct\"\n }\n },\n \"metric_1\": {\n \"avg\": {\n \"field\": \"kubernetes.pod.cpu.usage.node.pct\"\n }\n },\n \"metric_2\": {\n \"avg\": {\n \"field\": \"docker.cpu.total.pct\"\n }\n }\n }\n },\n \"metricsets\": {\n \"terms\": {\n \"field\": \"metricset.name\"\n }\n }\n }\n }\n}\n```\n\n---------\n\nCo-authored-by: Nathan L Smith <nathan.smith@elastic.co>\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by: Caue Marcondes <caue.marcondes@elastic.co>\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>\nCo-authored-by: Coen Warmer <coen.warmer@gmail.com>","sha":"aedfb94b2118c1e925e5678c585ab2093b04ed12"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19","9.2"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.2","label":"v9.2.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/246438","number":246438,"mergeCommit":{"message":"[Infra] Fix legacy Infra search client to respect the frozen tier setting (#246438)\n\n## Summary\n\nBasically what this #245224 does,\nbut focusing only on the Infra plugin changes\n\n`has_data` endpoint will run this when the setting is not set\n\n```json\n{\n \"index\": \"remote_cluster:metrics-*,remote_cluster:metricbeat-*\",\n \"allow_no_indices\": true,\n \"terminate_after\": 1,\n \"ignore_unavailable\": true,\n \"body\": {\n \"size\": 0,\n \"query\": {\n \"bool\": {}\n }\n }\n}\n```\n\nand this when the setting is set\n\n```json\nparams {\n \"index\": \"remote_cluster:metrics-*,remote_cluster:metricbeat-*\",\n \"allow_no_indices\": true,\n \"terminate_after\": 1,\n \"ignore_unavailable\": true,\n \"body\": {\n \"size\": 0,\n \"query\": {\n \"bool\": {\n \"filter\": [\n {\n \"bool\": {\n \"must_not\": [\n {\n \"terms\": {\n \"_tier\": [\n \"data_frozen\"\n ]\n }\n }\n ]\n }\n }\n ]\n }\n }\n }\n}\n```\n\nOther pages are affected by this change, but are not a source for the\nfrozen tier being hit because they don't run unbounded queries\n\n- Infra Inventory UI\n```json\nparams {\n \"allow_no_indices\": true,\n \"ignore_unavailable\": true,\n \"index\": \"remote_cluster:metrics-*,remote_cluster:metricbeat-*\",\n \"body\": {\n \"size\": 0,\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"bool\": {\n \"filter\": [\n {\n \"bool\": {\n \"filter\": [\n {\n \"bool\": {\n \"filter\": [\n {\n \"term\": {\n \"data_stream.dataset\": \"hostmetricsreceiver.otel\"\n }\n }\n ]\n }\n }\n ]\n }\n },\n {\n \"range\": {\n \"@timestamp\": {\n \"gte\": 1765824423511,\n \"lte\": 1765824723511,\n \"format\": \"epoch_millis\"\n }\n }\n },\n {\n \"exists\": {\n \"field\": \"host.name\"\n }\n }\n ]\n }\n }\n ],\n \"filter\": [\n {\n \"bool\": {\n \"must_not\": [\n {\n \"terms\": {\n \"_tier\": [\n \"data_frozen\"\n ]\n }\n }\n ]\n }\n }\n ]\n }\n },\n \"aggs\": {\n \"groupings\": {\n \"composite\": {\n \"size\": 2000,\n \"sources\": [\n {\n \"groupBy0\": {\n \"terms\": {\n \"field\": \"host.name\"\n }\n }\n }\n ]\n },\n \"aggs\": {\n \"histogram\": {\n \"date_histogram\": {\n \"field\": \"@timestamp\",\n \"fixed_interval\": \"60s\",\n \"offset\": \"-57511ms\",\n \"extended_bounds\": {\n \"min\": 1765824423511,\n \"max\": 1765824723511\n }\n },\n \"aggregations\": {\n \"cpu_idle\": {\n \"terms\": {\n \"field\": \"state\",\n \"include\": [\n \"idle\",\n \"wait\"\n ]\n },\n \"aggs\": {\n \"avg\": {\n \"avg\": {\n \"field\": \"system.cpu.utilization\"\n }\n }\n }\n },\n \"cpu_idle_total\": {\n \"sum_bucket\": {\n \"buckets_path\": \"cpu_idle.avg\"\n }\n },\n \"cpuV2\": {\n \"bucket_script\": {\n \"buckets_path\": {\n \"cpuIdleTotal\": \"cpu_idle_total\"\n },\n \"script\": \"1 - params.cpuIdleTotal\",\n \"gap_policy\": \"skip\"\n }\n },\n \"__metadata__\": {\n \"top_metrics\": {\n \"size\": 1,\n \"metrics\": [\n {\n \"field\": \"host.name\"\n },\n {\n \"field\": \"host.ip\"\n },\n {\n \"field\": \"host.os.name\"\n },\n {\n \"field\": \"cloud.provider\"\n }\n ],\n \"sort\": {\n \"@timestamp\": \"desc\"\n }\n }\n }\n }\n },\n \"metricsets\": {\n \"terms\": {\n \"field\": \"metricset.name\"\n }\n }\n }\n }\n }\n }\n}\n```\n- Metrics Explorer\n\n```json\n{\n \"allow_no_indices\": true,\n \"ignore_unavailable\": true,\n \"index\": \"remote_cluster:metrics-*,remote_cluster:metricbeat-*\",\n \"body\": {\n \"size\": 0,\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"bool\": {\n \"filter\": [\n null,\n {\n \"range\": {\n \"@timestamp\": {\n \"gte\": 1765821298325,\n \"lte\": 1765824898325,\n \"format\": \"epoch_millis\"\n }\n }\n }\n ]\n }\n }\n ],\n \"filter\": [\n {\n \"bool\": {\n \"must_not\": [\n {\n \"terms\": {\n \"_tier\": [\n \"data_frozen\"\n ]\n }\n }\n ]\n }\n }\n ]\n }\n },\n \"aggs\": {\n \"histogram\": {\n \"date_histogram\": {\n \"field\": \"@timestamp\",\n \"fixed_interval\": \"30s\",\n \"offset\": \"0s\",\n \"extended_bounds\": {\n \"min\": 1765821298325,\n \"max\": 1765824898325\n }\n },\n \"aggregations\": {\n \"metric_0\": {\n \"avg\": {\n \"field\": \"system.cpu.total.norm.pct\"\n }\n },\n \"metric_1\": {\n \"avg\": {\n \"field\": \"kubernetes.pod.cpu.usage.node.pct\"\n }\n },\n \"metric_2\": {\n \"avg\": {\n \"field\": \"docker.cpu.total.pct\"\n }\n }\n }\n },\n \"metricsets\": {\n \"terms\": {\n \"field\": \"metricset.name\"\n }\n }\n }\n }\n}\n```\n\n---------\n\nCo-authored-by: Nathan L Smith <nathan.smith@elastic.co>\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by: Caue Marcondes <caue.marcondes@elastic.co>\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>\nCo-authored-by: Coen Warmer <coen.warmer@gmail.com>","sha":"aedfb94b2118c1e925e5678c585ab2093b04ed12"}}]}] BACKPORT-->
1 parent c7f1d07 commit 4fac838

File tree

11 files changed

+134
-28
lines changed

11 files changed

+134
-28
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import type { estypes } from '@elastic/elasticsearch';
9+
10+
export function excludeTiersQuery(
11+
excludedDataTiers: Array<'data_frozen' | 'data_cold' | 'data_warm' | 'data_hot'>
12+
): estypes.QueryDslQueryContainer[] {
13+
return [
14+
{
15+
bool: {
16+
must_not: [
17+
{
18+
terms: {
19+
_tier: excludedDataTiers,
20+
},
21+
},
22+
],
23+
},
24+
},
25+
];
26+
}

x-pack/platform/plugins/shared/logs_shared/public/services/log_views/log_views_client.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import * as rt from 'io-ts';
9-
import type { HttpStart } from '@kbn/core/public';
9+
import type { HttpStart, IUiSettingsClient } from '@kbn/core/public';
1010
import type { ISearchGeneric } from '@kbn/search-types';
1111
import type { DataViewsContract } from '@kbn/data-views-plugin/public';
1212
import type { DataView, DataViewLazy } from '@kbn/data-views-plugin/common';
@@ -31,6 +31,7 @@ import {
3131
} from '../../../common/log_views';
3232
import { decodeOrThrow } from '../../../common/runtime_types';
3333
import type { ILogViewsClient } from './types';
34+
import { excludeTiersQuery } from './exclude_tiers_query';
3435

3536
export class LogViewsClient implements ILogViewsClient {
3637
constructor(
@@ -86,8 +87,14 @@ export class LogViewsClient implements ILogViewsClient {
8687
}
8788

8889
public async getResolvedLogViewStatus(
89-
resolvedLogView: ResolvedLogView<DataView>
90+
resolvedLogView: ResolvedLogView<DataView>,
91+
uiSettings?: IUiSettingsClient
9092
): Promise<LogViewStatus> {
93+
const excludedDataTiers = uiSettings?.get('observability:searchExcludedDataTiers') ?? [];
94+
const excludedQuery = excludedDataTiers.length
95+
? excludeTiersQuery(excludedDataTiers)
96+
: undefined;
97+
9198
const indexStatus = await lastValueFrom(
9299
this.search({
93100
params: {
@@ -97,6 +104,7 @@ export class LogViewsClient implements ILogViewsClient {
97104
size: 0,
98105
terminate_after: 1,
99106
track_total_hits: 1,
107+
query: excludedQuery ? { bool: { filter: excludedQuery } } : undefined,
100108
},
101109
})
102110
).then(

x-pack/platform/plugins/shared/logs_shared/public/services/log_views/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { ISearchStart } from '@kbn/data-plugin/public';
1010
import type { DataViewsContract } from '@kbn/data-views-plugin/public';
1111
import type { LogSourcesService } from '@kbn/logs-data-access-plugin/common/types';
1212
import type { DataView, DataViewLazy } from '@kbn/data-views-plugin/common';
13+
import type { IUiSettingsClient } from '@kbn/core/public';
1314
import type {
1415
LogView,
1516
LogViewAttributes,
@@ -36,7 +37,10 @@ export interface LogViewsServiceStartDeps {
3637

3738
export interface ILogViewsClient {
3839
getLogView(logViewReference: LogViewReference): Promise<LogView>;
39-
getResolvedLogViewStatus(resolvedLogView: ResolvedLogView<DataView>): Promise<LogViewStatus>;
40+
getResolvedLogViewStatus(
41+
resolvedLogView: ResolvedLogView<DataView>,
42+
uiSettings?: IUiSettingsClient
43+
): Promise<LogViewStatus>;
4044
getResolvedLogView(logViewReference: LogViewReference): Promise<ResolvedLogView<DataView>>;
4145
putLogView(
4246
logViewReference: LogViewReference,

x-pack/solutions/observability/plugins/infra/public/utils/logs_overview_fetchers.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import type {
1313
} from '@kbn/observability-plugin/public';
1414
import { DEFAULT_LOG_VIEW, getLogsLocatorFromUrlService } from '@kbn/logs-shared-plugin/common';
1515
import moment from 'moment';
16+
import type { IUiSettingsClient } from '@kbn/core/public';
17+
import type { DataTier } from '@kbn/observability-shared-plugin/common';
1618
import { TIMESTAMP_FIELD } from '../../common/constants';
1719
import type { InfraClientStartDeps, InfraClientStartServicesAccessor } from '../types';
1820

@@ -38,10 +40,11 @@ type StatsAndSeries = Pick<LogsFetchDataResponse, 'stats' | 'series'>;
3840

3941
export function getLogsHasDataFetcher(getStartServices: InfraClientStartServicesAccessor) {
4042
return async () => {
41-
const [, { logsShared }] = await getStartServices();
43+
const [coreStart, { logsShared }] = await getStartServices();
4244
const resolvedLogView = await logsShared.logViews.client.getResolvedLogView(DEFAULT_LOG_VIEW);
4345
const logViewStatus = await logsShared.logViews.client.getResolvedLogViewStatus(
44-
resolvedLogView
46+
resolvedLogView,
47+
coreStart.uiSettings
4548
);
4649

4750
const hasData = logViewStatus.index === 'available';
@@ -58,15 +61,16 @@ export function getLogsOverviewDataFetcher(
5861
getStartServices: InfraClientStartServicesAccessor
5962
): FetchData<LogsFetchDataResponse> {
6063
return async (params) => {
61-
const [, { data, logsShared, share }] = await getStartServices();
64+
const [coreStart, { data, logsShared, share }] = await getStartServices();
6265
const resolvedLogView = await logsShared.logViews.client.getResolvedLogView(DEFAULT_LOG_VIEW);
6366

6467
const { stats, series } = await fetchLogsOverview(
6568
{
6669
index: resolvedLogView.indices,
6770
},
6871
params,
69-
data
72+
data,
73+
coreStart.uiSettings
7074
);
7175
const logsLocator = getLogsLocatorFromUrlService(share.url)!;
7276
const timeSpanInMinutes = (params.absoluteTime.end - params.absoluteTime.start) / (1000 * 60);
@@ -89,8 +93,12 @@ export function getLogsOverviewDataFetcher(
8993
async function fetchLogsOverview(
9094
logParams: LogParams,
9195
params: FetchDataParams,
92-
dataPlugin: InfraClientStartDeps['data']
96+
dataPlugin: InfraClientStartDeps['data'],
97+
uiSettings: IUiSettingsClient
9398
): Promise<StatsAndSeries> {
99+
const excludedDataTiers =
100+
uiSettings?.get<DataTier[]>('observability:searchExcludedDataTiers') ?? [];
101+
94102
return new Promise((resolve, reject) => {
95103
let esResponse: estypes.SearchResponse<any> | undefined;
96104

@@ -100,7 +108,7 @@ async function fetchLogsOverview(
100108
index: logParams.index,
101109
body: {
102110
size: 0,
103-
query: buildLogOverviewQuery(logParams, params),
111+
query: buildLogOverviewQuery(params, excludedDataTiers),
104112
aggs: buildLogOverviewAggregations(logParams, params),
105113
},
106114
},
@@ -119,14 +127,21 @@ async function fetchLogsOverview(
119127
});
120128
}
121129

122-
function buildLogOverviewQuery(logParams: LogParams, params: FetchDataParams) {
130+
function buildLogOverviewQuery(params: FetchDataParams, excludedDataTiers: DataTier[]) {
123131
return {
124-
range: {
125-
[TIMESTAMP_FIELD]: {
126-
gt: new Date(params.absoluteTime.start).toISOString(),
127-
lte: new Date(params.absoluteTime.end).toISOString(),
128-
format: 'strict_date_optional_time',
129-
},
132+
bool: {
133+
must: [
134+
{
135+
range: {
136+
[TIMESTAMP_FIELD]: {
137+
gt: new Date(params.absoluteTime.start).toISOString(),
138+
lte: new Date(params.absoluteTime.end).toISOString(),
139+
format: 'strict_date_optional_time',
140+
},
141+
},
142+
},
143+
],
144+
must_not: excludedDataTiers.length ? [{ terms: { _tier: excludedDataTiers } }] : undefined,
130145
},
131146
};
132147
}

x-pack/solutions/observability/plugins/infra/server/lib/create_search_client.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77

88
import type { KibanaRequest } from '@kbn/core/server';
9+
import { searchExcludedDataTiers } from '@kbn/observability-plugin/common/ui_settings_keys';
10+
import type { DataTier } from '@kbn/observability-shared-plugin/common';
11+
import { excludeTiersQuery } from '@kbn/observability-utils-common/es/queries/exclude_tiers_query';
912
import type { InfraPluginRequestHandlerContext } from '../types';
1013
import type { CallWithRequestParams, InfraDatabaseSearchResponse } from './adapters/framework';
1114
import type { KibanaFramework } from './adapters/framework/kibana_framework_adapter';
@@ -16,7 +19,32 @@ export const createSearchClient =
1619
framework: KibanaFramework,
1720
request?: KibanaRequest
1821
) =>
19-
<Hit = {}, Aggregation = undefined>(
22+
async <Hit = {}, Aggregation = undefined>(
2023
opts: CallWithRequestParams
21-
): Promise<InfraDatabaseSearchResponse<Hit, Aggregation>> =>
22-
framework.callWithRequest(requestContext, 'search', opts, request);
24+
): Promise<InfraDatabaseSearchResponse<Hit, Aggregation>> => {
25+
const { uiSettings } = await requestContext.core;
26+
27+
const excludedDataTiers = await uiSettings.client.get<DataTier[]>(searchExcludedDataTiers);
28+
29+
const excludedQuery = excludedDataTiers.length
30+
? excludeTiersQuery(excludedDataTiers)
31+
: undefined;
32+
33+
return framework.callWithRequest(
34+
requestContext,
35+
'search',
36+
{
37+
...opts,
38+
body: {
39+
...(opts.body ?? {}),
40+
query: {
41+
bool: {
42+
...(opts.body?.query ? { must: [opts.body?.query] } : {}),
43+
filter: excludedQuery,
44+
},
45+
},
46+
},
47+
},
48+
request
49+
);
50+
};

x-pack/solutions/observability/plugins/infra/server/routes/metrics_sources/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export const initMetricsSourceConfigurationRoutes = (libs: InfraBackendLibs) =>
198198
async (requestContext, request, response) => {
199199
const { sourceId } = request.params;
200200

201-
const client = createSearchClient(requestContext, framework);
201+
const client = await createSearchClient(requestContext, framework);
202202
const soClient = (await requestContext.core).savedObjects.client;
203203
const source = await libs.sources.getSourceConfiguration(soClient, sourceId);
204204

x-pack/solutions/observability/plugins/infra/server/routes/overview/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const initOverviewRoute = (libs: InfraBackendLibs) => {
2323
},
2424
async (requestContext, request, response) => {
2525
const options = request.body;
26-
const client = createSearchClient(requestContext, framework);
26+
const client = await createSearchClient(requestContext, framework);
2727
const soClient = (await requestContext.core).savedObjects.client;
2828
const source = await libs.sources.getSourceConfiguration(soClient, options.sourceId);
2929

x-pack/solutions/observability/plugins/infra/server/routes/snapshot/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const initSnapshotRoute = (libs: InfraBackendLibs) => {
5757
);
5858

5959
UsageCollector.countNode(snapshotRequest.nodeType);
60-
const client = createSearchClient(requestContext, framework, request);
60+
const client = await createSearchClient(requestContext, framework, request);
6161

6262
const snapshotResponse = await getNodes(
6363
client,

x-pack/solutions/observability/plugins/metrics_data_access/server/lib/create_search_client.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,36 @@
66
*/
77

88
import type { RequestHandlerContext } from '@kbn/core/server';
9-
import type { CallWithRequestParams, InfraDatabaseSearchResponse } from './adapters/framework';
9+
import type { DataTier } from '@kbn/observability-shared-plugin/common';
10+
import { excludeTiersQuery } from '@kbn/observability-utils-common/es/queries/exclude_tiers_query';
1011
import type { KibanaFramework } from './adapters/framework/kibana_framework_adapter';
12+
import type { CallWithRequestParams, InfraDatabaseSearchResponse } from './adapters/framework';
1113

1214
export const createSearchClient =
1315
(requestContext: RequestHandlerContext, framework: KibanaFramework) =>
14-
<Hit = {}, Aggregation = undefined>(
16+
async <Hit = {}, Aggregation = undefined>(
1517
opts: CallWithRequestParams
16-
): Promise<InfraDatabaseSearchResponse<Hit, Aggregation>> =>
17-
framework.callWithRequest(requestContext, 'search', opts);
18+
): Promise<InfraDatabaseSearchResponse<Hit, Aggregation>> => {
19+
const { uiSettings } = await requestContext.core;
20+
21+
const excludedDataTiers = await uiSettings.client.get<DataTier[]>(
22+
'observability:searchExcludedDataTiers'
23+
);
24+
25+
const excludedQuery = excludedDataTiers.length
26+
? excludeTiersQuery(excludedDataTiers)
27+
: undefined;
28+
29+
return framework.callWithRequest(requestContext, 'search', {
30+
...opts,
31+
body: {
32+
...(opts.body ?? {}),
33+
query: {
34+
bool: {
35+
...(opts.body?.query ? { must: [opts.body?.query] } : {}),
36+
filter: excludedQuery,
37+
},
38+
},
39+
},
40+
});
41+
};

x-pack/solutions/observability/plugins/metrics_data_access/server/routes/metrics_explorer/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const initMetricExplorerRoute = (framework: KibanaFramework) => {
4141
);
4242
}
4343

44-
const client = createSearchClient(requestContext, framework);
44+
const client = await createSearchClient(requestContext, framework);
4545
const interval = await findIntervalForMetrics(client, options);
4646

4747
const optionsWithInterval = options.forceInterval

0 commit comments

Comments
 (0)