Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infra server NP shim + config/routing API adoption #45299

Merged
merged 84 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
735f57e
Basic cleanup before refactoring for shim work
jasonrhodes Sep 6, 2019
d46a6ab
shim WIP
jasonrhodes Sep 10, 2019
6407924
Removes the configuration adapter
jasonrhodes Sep 11, 2019
51fc360
WIP more stuff
jasonrhodes Sep 17, 2019
dd83941
WIP refactoring of shimming work
jasonrhodes Sep 25, 2019
0ad3df3
WIP continues
jasonrhodes Oct 2, 2019
c5eb8cc
Logging UI now runs on top of new platform shim
jasonrhodes Oct 8, 2019
b9413b2
WIP continues
jasonrhodes Oct 23, 2019
cda2d41
Removes unused imports and variables
jasonrhodes Oct 23, 2019
49b0d7e
Basic infra NP server shim in place
jasonrhodes Oct 29, 2019
1ef3408
Reimplemented graphql http error handling for infra NP server shim
jasonrhodes Oct 29, 2019
9d01529
Adds new platform infra plugin to handle NP config for legacy server …
jasonrhodes Oct 30, 2019
daea0e6
Basic cleanup before refactoring for shim work
jasonrhodes Sep 6, 2019
3cacf78
shim WIP
jasonrhodes Sep 10, 2019
188e947
Removes the configuration adapter
jasonrhodes Sep 11, 2019
222d7e5
WIP more stuff
jasonrhodes Sep 17, 2019
f599939
WIP refactoring of shimming work
jasonrhodes Sep 25, 2019
b594898
WIP continues
jasonrhodes Oct 2, 2019
8502516
Logging UI now runs on top of new platform shim
jasonrhodes Oct 8, 2019
51b5e8f
WIP continues
jasonrhodes Oct 23, 2019
e12cbbd
Removes unused imports and variables
jasonrhodes Oct 23, 2019
b07fcf3
Basic infra NP server shim in place
jasonrhodes Oct 29, 2019
bdc1c31
Reimplemented graphql http error handling for infra NP server shim
jasonrhodes Oct 29, 2019
a73b778
Adds new platform infra plugin to handle NP config for legacy server …
jasonrhodes Oct 30, 2019
8e00bfd
Adds comment about duplicating full config for NP config
jasonrhodes Oct 30, 2019
42cf3e5
Use New Platform features plugin to registerFeature()
Kerry350 Oct 31, 2019
f3bd21d
Fixing merge conflicts from collaboration
jasonrhodes Oct 31, 2019
9982b9f
Re-arranging and relying on request context as uch as possible
jasonrhodes Nov 1, 2019
4b7a649
Refactors KibanaRequest for RequestHandlerContext
jasonrhodes Nov 1, 2019
645fa97
fixes types for callWithRequest
jasonrhodes Nov 4, 2019
208dadf
Moves callWithRequest method override types directly into class to ge…
jasonrhodes Nov 5, 2019
07ad280
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
jasonrhodes Nov 5, 2019
2cd167a
Fixes callWithRequest framework types
jasonrhodes Nov 6, 2019
f530de1
Removes a few NP_TODO comments
jasonrhodes Nov 7, 2019
c19a066
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
Kerry350 Nov 12, 2019
1f0e119
Fix broken imports
Kerry350 Nov 12, 2019
d9e6162
Ensure GraphQL resolvers are actually passed requestContext and not t…
Kerry350 Nov 12, 2019
de9610e
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
Kerry350 Nov 13, 2019
6319c1d
Remove the legacy traces of the savedObjects plugin
Kerry350 Nov 13, 2019
4979eab
Fixes TSVB access with NP raw requests and requestContext
Kerry350 Nov 15, 2019
dbcc3aa
Remove unused getUiSettingsService (moved to requestContext)
Kerry350 Nov 15, 2019
3ebba32
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
Kerry350 Nov 15, 2019
dce7b93
Migrate to new Spaces plugin
Kerry350 Nov 15, 2019
96d8940
Fix calculateMetricInterval after merged changes
Kerry350 Nov 15, 2019
c18b71d
Reinstate and migrate the infrastructure metadata route
Kerry350 Nov 15, 2019
01fb737
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
Kerry350 Nov 18, 2019
eb1d0a2
Fix various type check errors
Kerry350 Nov 18, 2019
b9565ed
Amend InfraSources lib unit tests
Kerry350 Nov 18, 2019
fa8ddba
Amend MetricsExplorer API response
Kerry350 Nov 18, 2019
4ffa82d
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
Kerry350 Nov 19, 2019
d3f23b7
Remove GraphQLI references from feature controls tests
Kerry350 Nov 19, 2019
410fd43
Remove other GraphiQL references
Kerry350 Nov 19, 2019
5d76435
Fix security / access issue
Kerry350 Nov 19, 2019
5ca1e3b
Add a framework level registerRoute method which always adds access t…
Kerry350 Nov 19, 2019
1805b06
*Temp* disable test
Kerry350 Nov 19, 2019
476734e
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
Kerry350 Nov 20, 2019
f76b126
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
Kerry350 Nov 25, 2019
f8723b4
Merge branch 'master' into logs-ui-server-np-shim
elasticmachine Nov 25, 2019
9267618
Merge branch 'logs-ui-server-np-shim' of github.com:jasonrhodes/kiban…
Kerry350 Nov 26, 2019
67d6083
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
Kerry350 Nov 26, 2019
32588c9
Migrate the log rate validation endpoint to the new platform
Kerry350 Nov 26, 2019
ec8bc6d
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
Kerry350 Nov 27, 2019
7028227
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
jasonrhodes Nov 27, 2019
2d2df6d
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
Kerry350 Nov 28, 2019
733e62a
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
Kerry350 Dec 2, 2019
e0c8c1d
Amend types
Kerry350 Dec 2, 2019
eab1272
Merge branch 'logs-ui-server-np-shim' of github.com:jasonrhodes/kiban…
jasonrhodes Dec 2, 2019
17c6990
Example of how to expose APM get indices method in NP
jasonrhodes Dec 3, 2019
521d245
Fix calls to TSVB bug caused by object mutation
Kerry350 Dec 3, 2019
294ffef
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
Kerry350 Dec 3, 2019
3a41dd8
Converts getApmIndices function to accept saved object client, implem…
jasonrhodes Dec 3, 2019
21a6cee
Merge branch 'logs-ui-server-np-shim' of github.com:jasonrhodes/kiban…
jasonrhodes Dec 3, 2019
a384c5e
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
Kerry350 Dec 4, 2019
79051b0
Merge branch 'logs-ui-server-np-shim' of github.com:jasonrhodes/kiban…
Kerry350 Dec 4, 2019
85fae62
Fix APM setup_request tests
Kerry350 Dec 4, 2019
5e0cd63
Fixes some unused references for linting
jasonrhodes Dec 4, 2019
7271327
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
Kerry350 Dec 5, 2019
6373386
Migrate all work from #50730 to NP
Kerry350 Dec 5, 2019
46591d0
Remove duplicate declaration files for rison_node and add a single so…
Kerry350 Dec 5, 2019
c122f94
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
jasonrhodes Dec 6, 2019
caba63f
Merge remote-tracking branch 'upstream/master' into logs-ui-server-np…
Kerry350 Dec 6, 2019
e03770f
Moved type file back into infra plugin to bypass strange break
jasonrhodes Dec 6, 2019
78150b4
Merge branch 'logs-ui-server-np-shim' of github.com:jasonrhodes/kiban…
jasonrhodes Dec 6, 2019
6f37fec
Updates apm indices method signature per feedback from @elastic/apm-ui
jasonrhodes Dec 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion x-pack/legacy/plugins/apm/server/lib/helpers/es_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ async function getParamsForSearchRequest(
) {
const { uiSettings } = context.core;
const [indices, includeFrozen] = await Promise.all([
getApmIndices(context),
getApmIndices({
savedObjectsClient: context.core.savedObjects.client,
config: context.config
}),
uiSettings.client.get('search:includeFrozen')
]);

Expand Down
10 changes: 10 additions & 0 deletions x-pack/legacy/plugins/apm/server/lib/helpers/setup_request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ function getMockRequest() {
client: {
get: jest.fn().mockResolvedValue(false)
}
},
savedObjects: {
client: {
get: jest.fn()
}
}
}
} as unknown) as APMRequestHandlerContext & {
Expand All @@ -65,6 +70,11 @@ function getMockRequest() {
get: jest.Mock<any, any>;
};
};
savedObjects: {
client: {
get: jest.Mock<any, any>;
};
};
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ export async function setupRequest<TParams extends SetupRequestParams>(
const { config } = context;
const { query } = context.params;

const indices = await getApmIndices(context);
const indices = await getApmIndices({
savedObjectsClient: context.core.savedObjects.client,
config
});

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

export async function getApmIndices(context: APMRequestHandlerContext) {
// export async function getApmIndices(context: APMRequestHandlerContext) {
// return _getApmIndices(context.core, context.config);
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll clean this up on the followup branch we have 👍


export async function getApmIndices({
config,
savedObjectsClient
}: {
config: APMConfig;
savedObjectsClient: SavedObjectsClientContract;
}) {
try {
const apmIndicesSavedObject = await getApmIndicesSavedObject(
context.core.savedObjects.client
savedObjectsClient
);
const apmIndicesConfig = getApmIndicesConfig(context.config);
const apmIndicesConfig = getApmIndicesConfig(config);
return merge({}, apmIndicesConfig, apmIndicesSavedObject);
} catch (error) {
return getApmIndicesConfig(context.config);
return getApmIndicesConfig(config);
}
}

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);
return await getApmIndices({
savedObjectsClient: context.core.savedObjects.client,
config: context.config
});
}
}));

Expand Down
4 changes: 1 addition & 3 deletions x-pack/legacy/plugins/infra/common/http_api/metadata_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

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

export const InfraMetadataNodeTypeRT = rt.keyof({
host: null,
Expand Down Expand Up @@ -67,6 +66,7 @@ export const InfraMetadataInfoRT = rt.partial({
});

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

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

export type InfraMetadataWrappedRequest = InfraWrappableRequest<InfraMetadataRequest>;

export type InfraMetadataFeature = rt.TypeOf<typeof InfraMetadataFeatureRT>;

export type InfraMetadataInfo = rt.TypeOf<typeof InfraMetadataInfoRT>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import * as rt from 'io-ts';
import { InventoryMetricRT, ItemTypeRT } from '../inventory_models/types';
import { InfraWrappableRequest } from '../../server/lib/adapters/framework';
import { InfraTimerangeInputRT } from './snapshot_api';

const NodeDetailsDataPointRT = rt.intersection([
Expand Down Expand Up @@ -53,6 +52,4 @@ export const NodeDetailsRequestRT = rt.intersection([
// export type NodeDetailsRequest = InfraWrappableRequest<NodesArgs & SourceArgs>;

export type NodeDetailsRequest = rt.TypeOf<typeof NodeDetailsRequestRT>;
export type NodeDetailsWrappedRequest = InfraWrappableRequest<NodeDetailsRequest>;

export type NodeDetailsMetricDataResponse = rt.TypeOf<typeof NodeDetailsMetricDataResponseRT>;
2 changes: 0 additions & 2 deletions x-pack/legacy/plugins/infra/common/http_api/snapshot_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import * as rt from 'io-ts';
import { InfraWrappableRequest } from '../../server/lib/adapters/framework';
import { SnapshotMetricTypeRT, ItemTypeRT } from '../inventory_models/types';

export const SnapshotNodePathRT = rt.intersection([
Expand Down Expand Up @@ -64,6 +63,5 @@ export const SnapshotRequestRT = rt.intersection([
]);

export type SnapshotRequest = rt.TypeOf<typeof SnapshotRequestRT>;
export type SnapshotWrappedRequest = InfraWrappableRequest<SnapshotRequest>;
export type SnapshotNode = rt.TypeOf<typeof SnapshotNodeRT>;
export type SnapshotNodeResponse = rt.TypeOf<typeof SnapshotNodeResponseRT>;
58 changes: 53 additions & 5 deletions x-pack/legacy/plugins/infra/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
import { i18n } from '@kbn/i18n';
import JoiNamespace from 'joi';
import { resolve } from 'path';

import { getConfigSchema, initServerWithKibana } from './server/kibana.index';
import { PluginInitializerContext } 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 { APMPluginContract } from '../../../plugins/apm/server/plugin';

const APP_ID = 'infra';
const logsSampleDataLinkLabel = i18n.translate('xpack.infra.sampleDataLinkLabel', {
Expand Down Expand Up @@ -70,9 +75,52 @@ export function infra(kibana: any) {
config(Joi: typeof JoiNamespace) {
return getConfigSchema(Joi);
},
init(server: any) {
initServerWithKibana(server);
server.addAppLinksToSampleDataset('logs', [
init(legacyServer: any) {
const { newPlatform } = legacyServer as KbnServer;
const { core, plugins } = newPlatform.setup;

const infraSetup = (plugins.infra as unknown) as InfraSetup; // chef's kiss

const initContext = ({
config: infraSetup.__legacy.config,
} as unknown) as PluginInitializerContext;
// NP_TODO: Use real types from the other plugins as they are migrated
const pluginDeps: InfraServerPluginDeps = {
usageCollection: plugins.usageCollection as UsageCollectionSetup,
indexPatterns: {
indexPatternsServiceFactory: legacyServer.indexPatternsServiceFactory,
},
metrics: legacyServer.plugins.metrics,
spaces: plugins.spaces,
features: plugins.features,
// NP_NOTE: [TSVB_GROUP] Huge hack to make TSVB (getVisData()) work with raw requests that
// originate from the New Platform router (and are very different to the old request object).
// Once TSVB has migrated over to NP, and can work with the new raw requests, or ideally just
// the requestContext, this can be removed.
___legacy: {
tsvb: {
elasticsearch: legacyServer.plugins.elasticsearch,
__internals: legacyServer.newPlatform.__internals,
},
},
apm: plugins.apm as APMPluginContract,
};

const infraPluginInstance = plugin(initContext);
infraPluginInstance.setup(core, pluginDeps);

// NP_TODO: EVERYTHING BELOW HERE IS LEGACY

const libs = infraPluginInstance.getLibs();

// NP_TODO how do we replace this? Answer: return from setup function.
legacyServer.expose(
'defineInternalSourceConfiguration',
libs.sources.defineInternalSourceConfiguration.bind(libs.sources)
);

// NP_TODO: How do we move this to new platform?
legacyServer.addAppLinksToSampleDataset('logs', [
{
path: `/app/${APP_ID}#/logs`,
label: logsSampleDataLinkLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
const ROOT_ELEMENT_ID = 'react-infra-root';
const BREADCRUMBS_ELEMENT_ID = 'react-infra-breadcrumbs';

export class InfraKibanaFrameworkAdapter implements InfraFrameworkAdapter {
export class KibanaFramework implements InfraFrameworkAdapter {
public appState: object;
public kbnVersion?: string;
public timezone?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { HttpLink } from 'apollo-link-http';
import { withClientState } from 'apollo-link-state';
import { InfraFrontendLibs } from '../lib';
import introspectionQueryResultData from '../../graphql/introspection.json';
import { InfraKibanaFrameworkAdapter } from '../adapters/framework/kibana_framework_adapter';
import { KibanaFramework } from '../adapters/framework/kibana_framework_adapter';
import { InfraKibanaObservableApiAdapter } from '../adapters/observable_api/kibana_observable_api';

export function compose(): InfraFrontendLibs {
Expand Down Expand Up @@ -57,7 +57,7 @@ export function compose(): InfraFrontendLibs {

const infraModule = uiModules.get('app/infa');

const framework = new InfraKibanaFrameworkAdapter(infraModule, uiRoutes, timezoneProvider);
const framework = new KibanaFramework(infraModule, uiRoutes, timezoneProvider);

const libs: InfraFrontendLibs = {
apolloClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { InMemoryCache } from 'apollo-cache-inmemory';
import ApolloClient from 'apollo-client';
import { SchemaLink } from 'apollo-link-schema';
import { addMockFunctionsToSchema, makeExecutableSchema } from 'graphql-tools';
import { InfraKibanaFrameworkAdapter } from '../adapters/framework/kibana_framework_adapter';
import { KibanaFramework } from '../adapters/framework/kibana_framework_adapter';
import { InfraKibanaObservableApiAdapter } from '../adapters/observable_api/kibana_observable_api';
import { InfraFrontendLibs } from '../lib';

Expand All @@ -27,7 +27,7 @@ export function compose(): InfraFrontendLibs {
basePath: chrome.getBasePath(),
xsrfToken: chrome.getXsrfToken(),
});
const framework = new InfraKibanaFrameworkAdapter(infraModule, uiRoutes, timezoneProvider);
const framework = new KibanaFramework(infraModule, uiRoutes, timezoneProvider);
const typeDefs = `
Query {}
`;
Expand Down
65 changes: 65 additions & 0 deletions x-pack/legacy/plugins/infra/server/features.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { i18n } from '@kbn/i18n';

export const METRICS_FEATURE = {
id: 'infrastructure',
name: i18n.translate('xpack.infra.featureRegistry.linkInfrastructureTitle', {
defaultMessage: 'Infrastructure',
}),
icon: 'infraApp',
navLinkId: 'infra:home',
app: ['infra', 'kibana'],
catalogue: ['infraops'],
privileges: {
all: {
api: ['infra'],
savedObject: {
all: ['infrastructure-ui-source'],
read: ['index-pattern'],
},
ui: ['show', 'configureSource', 'save'],
},
read: {
api: ['infra'],
savedObject: {
all: [],
read: ['infrastructure-ui-source', 'index-pattern'],
},
ui: ['show'],
},
},
};

export const LOGS_FEATURE = {
id: 'logs',
name: i18n.translate('xpack.infra.featureRegistry.linkLogsTitle', {
defaultMessage: 'Logs',
}),
icon: 'loggingApp',
navLinkId: 'infra:logs',
app: ['infra', 'kibana'],
catalogue: ['infralogging'],
privileges: {
all: {
api: ['infra'],
savedObject: {
all: ['infrastructure-ui-source'],
read: [],
},
ui: ['show', 'configureSource', 'save'],
},
read: {
api: ['infra'],
savedObject: {
all: [],
read: ['infrastructure-ui-source'],
},
ui: ['show'],
},
},
};
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/infra/server/infra_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const initInfraServer = (libs: InfraBackendLibs) => {
typeDefs: schemas,
});

libs.framework.registerGraphQLEndpoint('/api/infra/graphql', schema);
libs.framework.registerGraphQLEndpoint('/graphql', schema);

initIpToHostName(libs);
initLogAnalysisGetLogEntryRateRoute(libs);
Expand Down
Loading