Skip to content

Commit

Permalink
Merge branch 'logs-ui-server-np-shim' of github.com:jasonrhodes/kiban…
Browse files Browse the repository at this point in the history
…a into logs-ui-server-np-shim
  • Loading branch information
Kerry350 committed Dec 4, 2019
2 parents a384c5e + 21a6cee commit 79051b0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/apm/server/lib/helpers/setup_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ export async function setupRequest<TParams extends SetupRequestParams>(
context: APMRequestHandlerContext<TParams>,
request: KibanaRequest
): Promise<InferSetup<TParams>> {
const { config } = context;
const { config, core } = context;
const { query } = context.params;

const indices = await getApmIndices(context.core, context.config);
const indices = await getApmIndices(core.savedObjects.client, config);

const dynamicIndexPattern = await getDynamicIndexPattern({
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ export function getApmIndicesConfig(config: APMConfig): ApmIndicesConfig {
// }

export async function getApmIndices(
core: APMRequestHandlerContext['core'],
savedObjectsClient: SavedObjectsClientContract,
config: APMRequestHandlerContext['config']
) {
try {
const apmIndicesSavedObject = await getApmIndicesSavedObject(
core.savedObjects.client
savedObjectsClient
);
const apmIndicesConfig = getApmIndicesConfig(config);
return merge({}, apmIndicesConfig, apmIndicesSavedObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export const apmIndicesRoute = createRoute(() => ({
method: 'GET',
path: '/api/apm/settings/apm-indices',
handler: async ({ context }) => {
return await getApmIndices(context.core, context.config);
return await getApmIndices(
context.core.savedObjects.client,
context.config
);
}
}));

Expand Down
11 changes: 3 additions & 8 deletions x-pack/legacy/plugins/infra/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import { i18n } from '@kbn/i18n';
import JoiNamespace from 'joi';
import { resolve } from 'path';
import { PluginInitializerContext } from 'src/core/server';
import { PluginInitializerContext, SavedObjectsClientContract } from 'src/core/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import KbnServer from 'src/legacy/server/kbn_server';
import { getConfigSchema } from './server/kibana.index';
import { savedObjectMappings } from './server/saved_objects';
import { plugin, InfraServerPluginDeps } from './server/new_platform_index';
import { InfraSetup } from '../../../plugins/infra/server';
import { getApmIndices } from '../apm/server/lib/settings/apm_indices/get_apm_indices';
import { APMPluginContract } from '../../../plugins/apm/server/plugin';

const APP_ID = 'infra';
const logsSampleDataLinkLabel = i18n.translate('xpack.infra.sampleDataLinkLabel', {
Expand Down Expand Up @@ -103,12 +103,7 @@ export function infra(kibana: any) {
__internals: legacyServer.newPlatform.__internals,
},
},
apm: {
// NP_NOTE: This needs migrating once APM's getApmIndices() has been ported to NP.
// On our side we're using the NP savedObjectsClient, but legacyServer.config() needs to go.
getIndices: savedObjectsClient =>
getApmIndices({ savedObjectsClient, config: legacyServer.config() }),
},
apm: plugins.apm as APMPluginContract,
};

const infraPluginInstance = plugin(initContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Lifecycle } from 'hapi';
import { ObjectType } from '@kbn/config-schema';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { RouteMethod, RouteConfig } from '../../../../../../../../src/core/server';
import { APMPluginContract } from '../../../../../../../plugins/apm/server/plugin';

interface ApmIndices {
'apm_oss.transactionIndices': string | undefined;
Expand All @@ -25,9 +26,7 @@ export interface InfraServerPluginDeps {
indexPatternsServiceFactory: any;
};
features: any;
apm: {
getIndices: (savedObjectsClient: any) => Promise<ApmIndices>;
};
apm: APMPluginContract;
___legacy: any;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const hasAPMData = async (
nodeId: string,
nodeType: 'host' | 'pod' | 'container'
) => {
const apmIndices = await framework.plugins.apm.getIndices(
const apmIndices = await framework.plugins.apm.getApmIndices(
requestContext.core.savedObjects.client
);
const apmIndex = apmIndices['apm_oss.transactionIndices'] || 'apm-*';
Expand Down
11 changes: 8 additions & 3 deletions x-pack/plugins/apm/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Plugin,
CoreSetup,
RequestHandlerContext,
SavedObjectsClientContract,
} from 'src/core/server';
import { Observable, combineLatest, AsyncSubject } from 'rxjs';
import { map } from 'rxjs/operators';
Expand All @@ -26,14 +27,18 @@ export interface LegacySetup {
export interface APMPluginContract {
config$: Observable<APMConfig>;
registerLegacyAPI: (__LEGACY: LegacySetup) => void;
getApmIndices: (
savedObjectsClient: SavedObjectsClientContract
) => ReturnType<typeof getApmIndices>;
}

export class APMPlugin implements Plugin<APMPluginContract> {
legacySetup$: AsyncSubject<LegacySetup>;
currentConfig?: APMConfig;
currentConfig: APMConfig;
constructor(private readonly initContext: PluginInitializerContext) {
this.initContext = initContext;
this.legacySetup$ = new AsyncSubject();
this.currentConfig = {} as APMConfig;
}

public async setup(
Expand Down Expand Up @@ -72,8 +77,8 @@ export class APMPlugin implements Plugin<APMPluginContract> {
this.legacySetup$.next(__LEGACY);
this.legacySetup$.complete();
}),
getApmIndices: async (requestContext: RequestHandlerContext) => {
return getApmIndices(requestContext.core, this.currentConfig as APMConfig);
getApmIndices: async (savedObjectsClient: SavedObjectsClientContract) => {
return getApmIndices(savedObjectsClient, this.currentConfig);
},
};
}
Expand Down

0 comments on commit 79051b0

Please sign in to comment.