Skip to content

Commit c41705e

Browse files
committed
Infra server NP shim + config/routing API adoption (#45299)
* Basic cleanup before refactoring for shim work * shim WIP * Removes the configuration adapter * WIP more stuff * WIP refactoring of shimming work * WIP continues * Logging UI now runs on top of new platform shim * WIP continues * Removes unused imports and variables * Basic infra NP server shim in place * Reimplemented graphql http error handling for infra NP server shim * Adds new platform infra plugin to handle NP config for legacy server shim * Basic cleanup before refactoring for shim work * shim WIP * Removes the configuration adapter * WIP more stuff * WIP refactoring of shimming work * WIP continues * Logging UI now runs on top of new platform shim * WIP continues * Removes unused imports and variables * Basic infra NP server shim in place * Reimplemented graphql http error handling for infra NP server shim * Adds new platform infra plugin to handle NP config for legacy server shim * Adds comment about duplicating full config for NP config * Use New Platform features plugin to registerFeature() * Re-arranging and relying on request context as uch as possible * Refactors KibanaRequest for RequestHandlerContext * fixes types for callWithRequest * Moves callWithRequest method override types directly into class to get them working, need to fix this when we understand it better * Fixes callWithRequest framework types * Removes a few NP_TODO comments * Fix broken imports * Ensure GraphQL resolvers are actually passed requestContext and not the raw request, and switch to the savedObjects client via requestContext * Remove the legacy traces of the savedObjects plugin * Fixes TSVB access with NP raw requests and requestContext * Remove unused getUiSettingsService (moved to requestContext) * Migrate to new Spaces plugin * Fix calculateMetricInterval after merged changes * Reinstate and migrate the infrastructure metadata route * Fix various type check errors * Amend InfraSources lib unit tests Mock the savedObjects client differently * Amend MetricsExplorer API response Renaming of variable inadvertently broke the response * Remove GraphQLI references from feature controls tests * Remove other GraphiQL references * Fix security / access issue * Add a framework level registerRoute method which always adds access tags by default * *Temp* disable test * Migrate the log rate validation endpoint to the new platform Fully migrates the [Logs UI] log rate setup index validation #50008 PR to New Platform routing etc * Amend types * Example of how to expose APM get indices method in NP * Fix calls to TSVB bug caused by object mutation This is a temp fix as the TSVB NP migration will supercede this * Converts getApmIndices function to accept saved object client, implements usage in infra * Fix APM setup_request tests * Fixes some unused references for linting * Migrate all work from #50730 to NP * Remove duplicate declaration files for rison_node and add a single source of truth at x-pack/typings/rison_node.d.ts for x-pack uses * Moved type file back into infra plugin to bypass strange break * Updates apm indices method signature per feedback from @elastic/apm-ui
1 parent 1ab8be1 commit c41705e

File tree

65 files changed

+1623
-1219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1623
-1219
lines changed

x-pack/legacy/plugins/apm/server/lib/helpers/es_client.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ async function getParamsForSearchRequest(
7878
) {
7979
const { uiSettings } = context.core;
8080
const [indices, includeFrozen] = await Promise.all([
81-
getApmIndices(context),
81+
getApmIndices({
82+
savedObjectsClient: context.core.savedObjects.client,
83+
config: context.config
84+
}),
8285
uiSettings.client.get('search:includeFrozen')
8386
]);
8487

x-pack/legacy/plugins/apm/server/lib/helpers/setup_request.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ function getMockRequest() {
5050
client: {
5151
get: jest.fn().mockResolvedValue(false)
5252
}
53+
},
54+
savedObjects: {
55+
client: {
56+
get: jest.fn()
57+
}
5358
}
5459
}
5560
} as unknown) as APMRequestHandlerContext & {
@@ -65,6 +70,11 @@ function getMockRequest() {
6570
get: jest.Mock<any, any>;
6671
};
6772
};
73+
savedObjects: {
74+
client: {
75+
get: jest.Mock<any, any>;
76+
};
77+
};
6878
};
6979
};
7080

x-pack/legacy/plugins/apm/server/lib/helpers/setup_request.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ export async function setupRequest<TParams extends SetupRequestParams>(
7373
const { config } = context;
7474
const { query } = context.params;
7575

76-
const indices = await getApmIndices(context);
76+
const indices = await getApmIndices({
77+
savedObjectsClient: context.core.savedObjects.client,
78+
config
79+
});
7780

7881
const dynamicIndexPattern = await getDynamicIndexPattern({
7982
context,

x-pack/legacy/plugins/apm/server/lib/settings/apm_indices/get_apm_indices.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,25 @@ export function getApmIndicesConfig(config: APMConfig): ApmIndicesConfig {
5454
};
5555
}
5656

57-
export async function getApmIndices(context: APMRequestHandlerContext) {
57+
// export async function getApmIndices(context: APMRequestHandlerContext) {
58+
// return _getApmIndices(context.core, context.config);
59+
// }
60+
61+
export async function getApmIndices({
62+
config,
63+
savedObjectsClient
64+
}: {
65+
config: APMConfig;
66+
savedObjectsClient: SavedObjectsClientContract;
67+
}) {
5868
try {
5969
const apmIndicesSavedObject = await getApmIndicesSavedObject(
60-
context.core.savedObjects.client
70+
savedObjectsClient
6171
);
62-
const apmIndicesConfig = getApmIndicesConfig(context.config);
72+
const apmIndicesConfig = getApmIndicesConfig(config);
6373
return merge({}, apmIndicesConfig, apmIndicesSavedObject);
6474
} catch (error) {
65-
return getApmIndicesConfig(context.config);
75+
return getApmIndicesConfig(config);
6676
}
6777
}
6878

x-pack/legacy/plugins/apm/server/routes/settings/apm_indices.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ export const apmIndicesRoute = createRoute(() => ({
2626
method: 'GET',
2727
path: '/api/apm/settings/apm-indices',
2828
handler: async ({ context }) => {
29-
return await getApmIndices(context);
29+
return await getApmIndices({
30+
savedObjectsClient: context.core.savedObjects.client,
31+
config: context.config
32+
});
3033
}
3134
}));
3235

x-pack/legacy/plugins/infra/common/http_api/metadata_api.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import * as rt from 'io-ts';
8-
import { InfraWrappableRequest } from '../../server/lib/adapters/framework';
98

109
export const InfraMetadataNodeTypeRT = rt.keyof({
1110
host: null,
@@ -67,6 +66,7 @@ export const InfraMetadataInfoRT = rt.partial({
6766
});
6867

6968
const InfraMetadataRequiredRT = rt.type({
69+
id: rt.string,
7070
name: rt.string,
7171
features: rt.array(InfraMetadataFeatureRT),
7272
});
@@ -81,8 +81,6 @@ export type InfraMetadata = rt.TypeOf<typeof InfraMetadataRT>;
8181

8282
export type InfraMetadataRequest = rt.TypeOf<typeof InfraMetadataRequestRT>;
8383

84-
export type InfraMetadataWrappedRequest = InfraWrappableRequest<InfraMetadataRequest>;
85-
8684
export type InfraMetadataFeature = rt.TypeOf<typeof InfraMetadataFeatureRT>;
8785

8886
export type InfraMetadataInfo = rt.TypeOf<typeof InfraMetadataInfoRT>;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import * as rt from 'io-ts';
8+
import { InventoryMetricRT, ItemTypeRT } from '../inventory_models/types';
9+
import { InfraTimerangeInputRT } from './snapshot_api';
10+
11+
const NodeDetailsDataPointRT = rt.intersection([
12+
rt.type({
13+
timestamp: rt.number,
14+
}),
15+
rt.partial({
16+
value: rt.union([rt.number, rt.null]),
17+
}),
18+
]);
19+
20+
const NodeDetailsDataSeries = rt.type({
21+
id: rt.string,
22+
label: rt.string,
23+
data: rt.array(NodeDetailsDataPointRT),
24+
});
25+
26+
export const NodeDetailsMetricDataRT = rt.intersection([
27+
rt.partial({
28+
id: rt.union([InventoryMetricRT, rt.null]),
29+
}),
30+
rt.type({
31+
series: rt.array(NodeDetailsDataSeries),
32+
}),
33+
]);
34+
35+
export const NodeDetailsMetricDataResponseRT = rt.type({
36+
metrics: rt.array(NodeDetailsMetricDataRT),
37+
});
38+
39+
export const NodeDetailsRequestRT = rt.intersection([
40+
rt.type({
41+
nodeType: ItemTypeRT,
42+
nodeId: rt.string,
43+
metrics: rt.array(InventoryMetricRT),
44+
timerange: InfraTimerangeInputRT,
45+
sourceId: rt.string,
46+
}),
47+
rt.partial({
48+
cloudId: rt.union([rt.string, rt.null]),
49+
}),
50+
]);
51+
52+
// export type NodeDetailsRequest = InfraWrappableRequest<NodesArgs & SourceArgs>;
53+
54+
export type NodeDetailsRequest = rt.TypeOf<typeof NodeDetailsRequestRT>;
55+
export type NodeDetailsMetricDataResponse = rt.TypeOf<typeof NodeDetailsMetricDataResponseRT>;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import * as rt from 'io-ts';
8+
import { SnapshotMetricTypeRT, ItemTypeRT } from '../inventory_models/types';
9+
10+
export const SnapshotNodePathRT = rt.intersection([
11+
rt.type({
12+
value: rt.string,
13+
label: rt.string,
14+
}),
15+
rt.partial({
16+
ip: rt.union([rt.string, rt.null]),
17+
}),
18+
]);
19+
20+
const SnapshotNodeMetricOptionalRT = rt.partial({
21+
value: rt.union([rt.number, rt.null]),
22+
average: rt.union([rt.number, rt.null]),
23+
max: rt.union([rt.number, rt.null]),
24+
});
25+
26+
const SnapshotNodeMetricRequiredRT = rt.type({
27+
name: SnapshotMetricTypeRT,
28+
});
29+
30+
export const SnapshotNodeRT = rt.type({
31+
metric: rt.intersection([SnapshotNodeMetricRequiredRT, SnapshotNodeMetricOptionalRT]),
32+
path: rt.array(SnapshotNodePathRT),
33+
});
34+
35+
export const SnapshotNodeResponseRT = rt.type({
36+
nodes: rt.array(SnapshotNodeRT),
37+
});
38+
39+
export const InfraTimerangeInputRT = rt.type({
40+
interval: rt.string,
41+
to: rt.number,
42+
from: rt.number,
43+
});
44+
45+
export const SnapshotRequestRT = rt.intersection([
46+
rt.type({
47+
timerange: InfraTimerangeInputRT,
48+
metric: rt.type({
49+
type: SnapshotMetricTypeRT,
50+
}),
51+
groupBy: rt.array(
52+
rt.partial({
53+
label: rt.union([rt.string, rt.null]),
54+
field: rt.union([rt.string, rt.null]),
55+
})
56+
),
57+
nodeType: ItemTypeRT,
58+
sourceId: rt.string,
59+
}),
60+
rt.partial({
61+
filterQuery: rt.union([rt.string, rt.null]),
62+
}),
63+
]);
64+
65+
export type SnapshotRequest = rt.TypeOf<typeof SnapshotRequestRT>;
66+
export type SnapshotNode = rt.TypeOf<typeof SnapshotNodeRT>;
67+
export type SnapshotNodeResponse = rt.TypeOf<typeof SnapshotNodeResponseRT>;

x-pack/legacy/plugins/infra/index.ts

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
import { i18n } from '@kbn/i18n';
88
import JoiNamespace from 'joi';
99
import { resolve } from 'path';
10-
11-
import { getConfigSchema, initServerWithKibana } from './server/kibana.index';
10+
import { PluginInitializerContext } from 'src/core/server';
11+
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
12+
import KbnServer from 'src/legacy/server/kbn_server';
13+
import { getConfigSchema } from './server/kibana.index';
1214
import { savedObjectMappings } from './server/saved_objects';
15+
import { plugin, InfraServerPluginDeps } from './server/new_platform_index';
16+
import { InfraSetup } from '../../../plugins/infra/server';
17+
import { APMPluginContract } from '../../../plugins/apm/server/plugin';
1318

1419
const APP_ID = 'infra';
1520
const logsSampleDataLinkLabel = i18n.translate('xpack.infra.sampleDataLinkLabel', {
@@ -70,9 +75,52 @@ export function infra(kibana: any) {
7075
config(Joi: typeof JoiNamespace) {
7176
return getConfigSchema(Joi);
7277
},
73-
init(server: any) {
74-
initServerWithKibana(server);
75-
server.addAppLinksToSampleDataset('logs', [
78+
init(legacyServer: any) {
79+
const { newPlatform } = legacyServer as KbnServer;
80+
const { core, plugins } = newPlatform.setup;
81+
82+
const infraSetup = (plugins.infra as unknown) as InfraSetup; // chef's kiss
83+
84+
const initContext = ({
85+
config: infraSetup.__legacy.config,
86+
} as unknown) as PluginInitializerContext;
87+
// NP_TODO: Use real types from the other plugins as they are migrated
88+
const pluginDeps: InfraServerPluginDeps = {
89+
usageCollection: plugins.usageCollection as UsageCollectionSetup,
90+
indexPatterns: {
91+
indexPatternsServiceFactory: legacyServer.indexPatternsServiceFactory,
92+
},
93+
metrics: legacyServer.plugins.metrics,
94+
spaces: plugins.spaces,
95+
features: plugins.features,
96+
// NP_NOTE: [TSVB_GROUP] Huge hack to make TSVB (getVisData()) work with raw requests that
97+
// originate from the New Platform router (and are very different to the old request object).
98+
// Once TSVB has migrated over to NP, and can work with the new raw requests, or ideally just
99+
// the requestContext, this can be removed.
100+
___legacy: {
101+
tsvb: {
102+
elasticsearch: legacyServer.plugins.elasticsearch,
103+
__internals: legacyServer.newPlatform.__internals,
104+
},
105+
},
106+
apm: plugins.apm as APMPluginContract,
107+
};
108+
109+
const infraPluginInstance = plugin(initContext);
110+
infraPluginInstance.setup(core, pluginDeps);
111+
112+
// NP_TODO: EVERYTHING BELOW HERE IS LEGACY
113+
114+
const libs = infraPluginInstance.getLibs();
115+
116+
// NP_TODO how do we replace this? Answer: return from setup function.
117+
legacyServer.expose(
118+
'defineInternalSourceConfiguration',
119+
libs.sources.defineInternalSourceConfiguration.bind(libs.sources)
120+
);
121+
122+
// NP_TODO: How do we move this to new platform?
123+
legacyServer.addAppLinksToSampleDataset('logs', [
76124
{
77125
path: `/app/${APP_ID}#/logs`,
78126
label: logsSampleDataLinkLabel,

x-pack/legacy/plugins/infra/public/lib/adapters/framework/kibana_framework_adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
const ROOT_ELEMENT_ID = 'react-infra-root';
2525
const BREADCRUMBS_ELEMENT_ID = 'react-infra-breadcrumbs';
2626

27-
export class InfraKibanaFrameworkAdapter implements InfraFrameworkAdapter {
27+
export class KibanaFramework implements InfraFrameworkAdapter {
2828
public appState: object;
2929
public kbnVersion?: string;
3030
public timezone?: string;

0 commit comments

Comments
 (0)