-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.16] [Infra] Exclude frozen/cold data tiers from source queries (#2…
…01804) (#202924) # Backport This will backport the following commits from `main` to `8.16`: - [[Infra] Exclude frozen/cold data tiers from source queries (#201804)](#201804) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Gonçalo Rica Pais da Silva","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-03T18:23:13Z","message":"[Infra] Exclude frozen/cold data tiers from source queries (#201804)\n\nCloses #201568 \r\n\r\n## Summary\r\n\r\nAdds the exclude data tiers settings to the\r\n`/api/metrics/source/hasData` and `/api/metrics/source/{sourceId}`\r\nrequests. Also applies it to the `getIndexStatus` API call.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine <[email protected]>\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"ac3b60ee907436aeee35fc59df7c30bcb9d66bc8","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-infra_services","Team:obs-ux-management","v8.16.0"],"number":201804,"url":"https://github.com/elastic/kibana/pull/201804","mergeCommit":{"message":"[Infra] Exclude frozen/cold data tiers from source queries (#201804)\n\nCloses #201568 \r\n\r\n## Summary\r\n\r\nAdds the exclude data tiers settings to the\r\n`/api/metrics/source/hasData` and `/api/metrics/source/{sourceId}`\r\nrequests. Also applies it to the `getIndexStatus` API call.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine <[email protected]>\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"ac3b60ee907436aeee35fc59df7c30bcb9d66bc8"}},"sourceBranch":"main","suggestedTargetBranches":["8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201804","number":201804,"mergeCommit":{"message":"[Infra] Exclude frozen/cold data tiers from source queries (#201804)\n\nCloses #201568 \r\n\r\n## Summary\r\n\r\nAdds the exclude data tiers settings to the\r\n`/api/metrics/source/hasData` and `/api/metrics/source/{sourceId}`\r\nrequests. Also applies it to the `getIndexStatus` API call.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine <[email protected]>\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"ac3b60ee907436aeee35fc59df7c30bcb9d66bc8"}},{"branch":"8.16","label":"v8.16.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"url":"https://github.com/elastic/kibana/pull/202788","number":202788,"branch":"8.17","state":"OPEN"},{"url":"https://github.com/elastic/kibana/pull/202789","number":202789,"branch":"8.x","state":"OPEN"}]}] BACKPORT--> --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: jennypavlova <[email protected]>
- Loading branch information
1 parent
f01cacc
commit 2dcd9bc
Showing
7 changed files
with
198 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
.../plugins/observability_solution/infra/server/lib/helpers/get_infra_metrics_client.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* 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 { KibanaRequest } from '@kbn/core-http-server'; | ||
import { DataTier } from '@kbn/observability-shared-plugin/common'; | ||
import { InfraBackendLibs } from '../infra_types'; | ||
import { getInfraMetricsClient } from './get_infra_metrics_client'; | ||
import { InfraPluginRequestHandlerContext } from '../../types'; | ||
import { QueryDslQueryContainer } from '@kbn/data-views-plugin/common/types'; | ||
|
||
const withExcludedDataTiers = (tiers: DataTier[]) => ({ | ||
uiSettings: { | ||
client: { | ||
get: () => Promise.resolve(tiers), | ||
}, | ||
}, | ||
}); | ||
|
||
const mockedInfra = { getMetricsIndices: () => Promise.resolve(['*.indices']) }; | ||
|
||
const infraMetricsTestHarness = | ||
(tiers: DataTier[], input: QueryDslQueryContainer | undefined, output: QueryDslQueryContainer) => | ||
async () => { | ||
const callWithRequest = jest.fn(); | ||
|
||
const mockedCore = withExcludedDataTiers(tiers); | ||
|
||
const context = { | ||
infra: Promise.resolve(mockedInfra), | ||
core: Promise.resolve(mockedCore), | ||
} as unknown as InfraPluginRequestHandlerContext; | ||
|
||
const client = await getInfraMetricsClient({ | ||
libs: { framework: { callWithRequest } } as unknown as InfraBackendLibs, | ||
context, | ||
request: {} as unknown as KibanaRequest, | ||
}); | ||
|
||
await client.search({ | ||
body: { | ||
query: input, | ||
size: 1, | ||
track_total_hits: false, | ||
}, | ||
}); | ||
|
||
expect(callWithRequest).toBeCalledWith( | ||
context, | ||
'search', | ||
{ | ||
body: { | ||
query: output, | ||
size: 1, | ||
track_total_hits: false, | ||
}, | ||
ignore_unavailable: true, | ||
index: ['*.indices'], | ||
}, | ||
{} | ||
); | ||
}; | ||
|
||
describe('getInfraMetricsClient', () => { | ||
it( | ||
'defines an empty must_not query if given no data tiers to filter by', | ||
infraMetricsTestHarness([], undefined, { bool: { must_not: [] } }) | ||
); | ||
|
||
it( | ||
'includes excluded data tiers in the request filter by default', | ||
infraMetricsTestHarness(['data_frozen'], undefined, { | ||
bool: { | ||
must_not: [ | ||
{ | ||
terms: { | ||
_tier: ['data_frozen'], | ||
}, | ||
}, | ||
], | ||
}, | ||
}) | ||
); | ||
|
||
it( | ||
'merges provided filters with the excluded data tier filter', | ||
infraMetricsTestHarness( | ||
['data_frozen'], | ||
{ | ||
bool: { | ||
must_not: { | ||
exists: { | ||
field: 'a-field', | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
bool: { | ||
must_not: [ | ||
{ | ||
exists: { | ||
field: 'a-field', | ||
}, | ||
}, | ||
{ | ||
terms: { | ||
_tier: ['data_frozen'], | ||
}, | ||
}, | ||
], | ||
}, | ||
} | ||
) | ||
); | ||
|
||
it( | ||
'merges other query params with the excluded data tiers filter', | ||
infraMetricsTestHarness( | ||
['data_frozen'], | ||
{ | ||
bool: { | ||
must: { | ||
exists: { | ||
field: 'a-field', | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
bool: { | ||
must: { | ||
exists: { | ||
field: 'a-field', | ||
}, | ||
}, | ||
must_not: [ | ||
{ | ||
terms: { | ||
_tier: ['data_frozen'], | ||
}, | ||
}, | ||
], | ||
}, | ||
} | ||
) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters