-
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.
[Infra] Add getMetricIndices to start contract (#131326)
* [Infra] Add getMetricIndices to start contract (#131246) * Remove temporary return variable, change variable name * Address review comments * Use Jest Promise mock shorthand Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
d2e96be
commit 71f2099
Showing
4 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
x-pack/plugins/infra/server/lib/metrics/make_get_metric_indices.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,30 @@ | ||
/* | ||
* 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 { savedObjectsClientMock } from '@kbn/core/server/mocks'; | ||
import { defaultSourceConfiguration, InfraSource } from '../sources'; | ||
import { createInfraSourcesMock } from '../sources/mocks'; | ||
import { makeGetMetricIndices } from './make_get_metric_indices'; | ||
|
||
describe('getMetricIndices', () => { | ||
it('should return the indices from a resolved configuration', async () => { | ||
const sourceConfiguration: InfraSource = { | ||
id: 'default', | ||
origin: 'stored', | ||
configuration: defaultSourceConfiguration, | ||
}; | ||
const infraSourcesMock = createInfraSourcesMock(); | ||
infraSourcesMock.getSourceConfiguration.mockResolvedValueOnce(sourceConfiguration); | ||
|
||
const getMetricIndices = makeGetMetricIndices(infraSourcesMock); | ||
|
||
const savedObjectsClient = savedObjectsClientMock.create(); | ||
const metricIndices = await getMetricIndices(savedObjectsClient); | ||
|
||
expect(metricIndices).toEqual(defaultSourceConfiguration.metricAlias); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
x-pack/plugins/infra/server/lib/metrics/make_get_metric_indices.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,16 @@ | ||
/* | ||
* 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 type { SavedObjectsClientContract } from '@kbn/core/server'; | ||
import type { IInfraSources } from '../sources'; | ||
|
||
export function makeGetMetricIndices(metricSources: IInfraSources) { | ||
return async (savedObjectsClient: SavedObjectsClientContract, sourceId: string = 'default') => { | ||
const source = await metricSources.getSourceConfiguration(savedObjectsClient, sourceId); | ||
return source.configuration.metricAlias; | ||
}; | ||
} |
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