mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[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 <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
d2e96be65a
commit
71f2099d25
4 changed files with 59 additions and 3 deletions
|
@ -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);
|
||||
});
|
||||
});
|
|
@ -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;
|
||||
};
|
||||
}
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
import { Server } from '@hapi/hapi';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { Logger } from '@kbn/logging';
|
||||
import {
|
||||
CoreStart,
|
||||
Plugin,
|
||||
|
@ -16,6 +14,8 @@ import {
|
|||
PluginInitializerContext,
|
||||
} from '@kbn/core/server';
|
||||
import { handleEsError } from '@kbn/es-ui-shared-plugin/server';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { Logger } from '@kbn/logging';
|
||||
import { LOGS_FEATURE_ID, METRICS_FEATURE_ID } from '../common/constants';
|
||||
import { defaultLogViewsStaticConfig } from '../common/log_views';
|
||||
import { publicConfigKeys } from '../common/plugin_config_types';
|
||||
|
@ -35,6 +35,7 @@ import { InfraFieldsDomain } from './lib/domains/fields_domain';
|
|||
import { InfraLogEntriesDomain } from './lib/domains/log_entries_domain';
|
||||
import { InfraMetricsDomain } from './lib/domains/metrics_domain';
|
||||
import { InfraBackendLibs, InfraDomainLibs } from './lib/infra_types';
|
||||
import { makeGetMetricIndices } from './lib/metrics/make_get_metric_indices';
|
||||
import { infraSourceConfigurationSavedObjectType, InfraSources } from './lib/sources';
|
||||
import { InfraSourceStatus } from './lib/source_status';
|
||||
import { logViewSavedObjectType } from './saved_objects';
|
||||
|
@ -236,6 +237,7 @@ export class InfraServerPlugin
|
|||
|
||||
return {
|
||||
logViews,
|
||||
getMetricIndices: makeGetMetricIndices(this.libs.sources),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,11 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { CoreSetup, CustomRequestHandlerContext } from '@kbn/core/server';
|
||||
import type {
|
||||
CoreSetup,
|
||||
CustomRequestHandlerContext,
|
||||
SavedObjectsClientContract,
|
||||
} from '@kbn/core/server';
|
||||
import type { SearchRequestHandlerContext } from '@kbn/data-plugin/server';
|
||||
import type { MlPluginSetup } from '@kbn/ml-plugin/server';
|
||||
import type { InfraStaticSourceConfiguration } from '../common/source_configuration/source_configuration';
|
||||
|
@ -27,6 +31,10 @@ export interface InfraPluginSetup {
|
|||
|
||||
export interface InfraPluginStart {
|
||||
logViews: LogViewsServiceStart;
|
||||
getMetricIndices: (
|
||||
savedObjectsClient: SavedObjectsClientContract,
|
||||
sourceId?: string
|
||||
) => Promise<string>;
|
||||
}
|
||||
|
||||
export type MlSystem = ReturnType<MlPluginSetup['mlSystemProvider']>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue