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 Migration #53955

Closed
  •  
  •  
  •  
58 changes: 13 additions & 45 deletions x-pack/legacy/plugins/infra/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@
import { i18n } from '@kbn/i18n';
import JoiNamespace from 'joi';
import { resolve } from 'path';
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 { PluginSetupContract as FeaturesPluginSetup } from '../../../plugins/features/server';
import { SpacesPluginSetup } from '../../../plugins/spaces/server';
import { VisTypeTimeseriesSetup } from '../../../../src/plugins/vis_type_timeseries/server';
import { APMPluginContract } from '../../../plugins/apm/server';

export const APP_ID = 'infra';

Expand Down Expand Up @@ -70,45 +59,24 @@ export function infra(kibana: any) {
url: `/app/${APP_ID}#/logs`,
},
],
mappings: savedObjectMappings,
// mappings: savedObjectMappings,
},
config(Joi: typeof JoiNamespace) {
return getConfigSchema(Joi);
return Joi.object({
enabled: Joi.boolean().default(true),
})
.unknown()
.default();
},
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 = {
home: legacyServer.newPlatform.setup.plugins.home,
usageCollection: plugins.usageCollection as UsageCollectionSetup,
indexPatterns: {
indexPatternsServiceFactory: legacyServer.indexPatternsServiceFactory,
// NP_TODO: How do we move this to new platform?
legacyServer.addAppLinksToSampleDataset('logs', [
Copy link
Contributor

Choose a reason for hiding this comment

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

I think something may have potentially gone wrong with a merge somewhere along the line, and the migration from legacyServer.addAppLinksToSampleDataset to plugins.home.sampleData.addAppLinksToSampleDataset in #52753.

We can remove legacyServer.addAppLinksToSampleDataset (it doesn't exist in master).

(This file is also throwing an exception as logsSampleDataLinkLabel doesn't exist here).

{
path: `/app/${APP_ID}#/logs`,
label: logsSampleDataLinkLabel,
icon: 'logsApp',
},
metrics: plugins.metrics as VisTypeTimeseriesSetup,
spaces: plugins.spaces as SpacesPluginSetup,
features: plugins.features as FeaturesPluginSetup,
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_NOTE: Left here for now for legacy plugins to consume
legacyServer.expose(
'defineInternalSourceConfiguration',
libs.sources.defineInternalSourceConfiguration.bind(libs.sources)
);
]);
},
});
}
15 changes: 0 additions & 15 deletions x-pack/legacy/plugins/infra/server/new_platform_index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/monitoring/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ export const monitoring = kibana =>
uiExports: getUiExports(),
postInit(server) {
const serverConfig = server.config();
initInfraSource(serverConfig, server.plugins.infra);
initInfraSource(serverConfig, server.newPlatform.setup.plugins.infra);
},
});
38 changes: 38 additions & 0 deletions x-pack/plugins/infra/common/color_palette.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 { sampleColor, MetricsExplorerColor, colorTransformer } from './color_palette';
describe('Color Palette', () => {
describe('sampleColor()', () => {
it('should just work', () => {
const usedColors = [MetricsExplorerColor.color0];
const color = sampleColor(usedColors);
expect(color).toBe(MetricsExplorerColor.color1);
});

it('should return color0 when nothing is available', () => {
const usedColors = [
MetricsExplorerColor.color0,
MetricsExplorerColor.color1,
MetricsExplorerColor.color2,
MetricsExplorerColor.color3,
MetricsExplorerColor.color4,
MetricsExplorerColor.color5,
MetricsExplorerColor.color6,
MetricsExplorerColor.color7,
MetricsExplorerColor.color8,
MetricsExplorerColor.color9,
];
const color = sampleColor(usedColors);
expect(color).toBe(MetricsExplorerColor.color0);
});
});
describe('colorTransformer()', () => {
it('should just work', () => {
expect(colorTransformer(MetricsExplorerColor.color0)).toBe('#3185FC');
});
});
});
56 changes: 56 additions & 0 deletions x-pack/plugins/infra/common/color_palette.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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 { difference, first, values } from 'lodash';

export enum MetricsExplorerColor {
color0 = 'color0',
color1 = 'color1',
color2 = 'color2',
color3 = 'color3',
color4 = 'color4',
color5 = 'color5',
color6 = 'color6',
color7 = 'color7',
color8 = 'color8',
color9 = 'color9',
}

export interface MetricsExplorerPalette {
[MetricsExplorerColor.color0]: string;
[MetricsExplorerColor.color1]: string;
[MetricsExplorerColor.color2]: string;
[MetricsExplorerColor.color3]: string;
[MetricsExplorerColor.color4]: string;
[MetricsExplorerColor.color5]: string;
[MetricsExplorerColor.color6]: string;
[MetricsExplorerColor.color7]: string;
[MetricsExplorerColor.color8]: string;
[MetricsExplorerColor.color9]: string;
}

export const defaultPalette: MetricsExplorerPalette = {
[MetricsExplorerColor.color0]: '#3185FC', // euiColorVis1 (blue)
[MetricsExplorerColor.color1]: '#DB1374', // euiColorVis2 (red-ish)
[MetricsExplorerColor.color2]: '#00B3A4', // euiColorVis0 (green-ish)
[MetricsExplorerColor.color3]: '#490092', // euiColorVis3 (purple)
[MetricsExplorerColor.color4]: '#FEB6DB', // euiColorVis4 (pink)
[MetricsExplorerColor.color5]: '#E6C220', // euiColorVis5 (yellow)
[MetricsExplorerColor.color6]: '#BFA180', // euiColorVis6 (tan)
[MetricsExplorerColor.color7]: '#F98510', // euiColorVis7 (orange)
[MetricsExplorerColor.color8]: '#461A0A', // euiColorVis8 (brown)
[MetricsExplorerColor.color9]: '#920000', // euiColorVis9 (maroon)
};

export const createPaletteTransformer = (palette: MetricsExplorerPalette) => (
color: MetricsExplorerColor
) => palette[color];

export const colorTransformer = createPaletteTransformer(defaultPalette);

export const sampleColor = (usedColors: MetricsExplorerColor[] = []): MetricsExplorerColor => {
const available = difference(values(MetricsExplorerColor) as MetricsExplorerColor[], usedColors);
return first(available) || MetricsExplorerColor.color0;
};
42 changes: 42 additions & 0 deletions x-pack/plugins/infra/common/ecs_allowed_list.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 {
getAllowedListForPrefix,
ECS_ALLOWED_LIST,
K8S_ALLOWED_LIST,
PROMETHEUS_ALLOWED_LIST,
DOCKER_ALLOWED_LIST,
} from './ecs_allowed_list';
describe('getAllowedListForPrefix()', () => {
test('kubernetes', () => {
expect(getAllowedListForPrefix('kubernetes.pod')).toEqual([
...ECS_ALLOWED_LIST,
'kubernetes.pod',
...K8S_ALLOWED_LIST,
]);
});
test('docker', () => {
expect(getAllowedListForPrefix('docker.container')).toEqual([
...ECS_ALLOWED_LIST,
'docker.container',
...DOCKER_ALLOWED_LIST,
]);
});
test('prometheus', () => {
expect(getAllowedListForPrefix('prometheus.metrics')).toEqual([
...ECS_ALLOWED_LIST,
'prometheus.metrics',
...PROMETHEUS_ALLOWED_LIST,
]);
});
test('anything.else', () => {
expect(getAllowedListForPrefix('anything.else')).toEqual([
...ECS_ALLOWED_LIST,
'anything.else',
]);
});
});
67 changes: 67 additions & 0 deletions x-pack/plugins/infra/common/ecs_allowed_list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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 { first } from 'lodash';

export const ECS_ALLOWED_LIST = [
'host',
'cloud',
'event',
'agent',
'fields',
'service',
'ecs',
'metricset',
'tags',
'message',
'labels',
'@timestamp',
'source',
'container',
];

export const K8S_ALLOWED_LIST = [
'kubernetes.pod.name',
'kubernetes.pod.uid',
'kubernetes.namespace',
'kubernetes.node.name',
'kubernetes.labels',
'kubernetes.annotations',
'kubernetes.replicaset.name',
'kubernetes.deployment.name',
'kubernetes.statefulset.name',
'kubernetes.container.name',
'kubernetes.container.image',
];

export const PROMETHEUS_ALLOWED_LIST = ['prometheus.labels', 'prometheus.metrics'];

export const DOCKER_ALLOWED_LIST = [
'docker.container.id',
'docker.container.image',
'docker.container.name',
'docker.container.labels',
];

export const AWS_S3_ALLOWED_LIST = ['aws.s3'];

export const getAllowedListForPrefix = (prefix: string) => {
const firstPart = first(prefix.split(/\./));
const defaultAllowedList = prefix ? [...ECS_ALLOWED_LIST, prefix] : ECS_ALLOWED_LIST;
switch (firstPart) {
case 'docker':
return [...defaultAllowedList, ...DOCKER_ALLOWED_LIST];
case 'prometheus':
return [...defaultAllowedList, ...PROMETHEUS_ALLOWED_LIST];
case 'kubernetes':
return [...defaultAllowedList, ...K8S_ALLOWED_LIST];
case 'aws':
if (prefix === 'aws.s3_daily_storage') {
return [...defaultAllowedList, ...AWS_S3_ALLOWED_LIST];
}
default:
return defaultAllowedList;
}
};
7 changes: 7 additions & 0 deletions x-pack/plugins/infra/common/errors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export * from './metrics';
10 changes: 10 additions & 0 deletions x-pack/plugins/infra/common/errors/metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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.
*/

export enum InfraMetricsErrorCodes {
// eslint-disable-next-line @typescript-eslint/camelcase
invalid_node = 'METRICS_INVALID_NODE',
}
7 changes: 7 additions & 0 deletions x-pack/plugins/infra/common/graphql/root/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export { rootSchema } from './schema.gql';
18 changes: 18 additions & 0 deletions x-pack/plugins/infra/common/graphql/root/schema.gql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 gql from 'graphql-tag';

export const rootSchema = gql`
schema {
query: Query
mutation: Mutation
}

type Query

type Mutation
`;
Loading