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

[Monitoring] NP migration: Local angular module #51823

Merged
merged 36 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ec7e660
More np stuff
igoristic Dec 6, 2019
ae37275
Fixed tests and added more np stuff
igoristic Dec 20, 2019
2c9b966
Added missing variable
igoristic Dec 21, 2019
a19f668
Fixed path and linting
igoristic Dec 30, 2019
619738e
resolved conflicts
igoristic Jan 13, 2020
c9dd620
Fixed liniting issues
igoristic Jan 14, 2020
d12baea
Fixed type tests
igoristic Jan 14, 2020
784f18e
Fixed i18n check
igoristic Jan 15, 2020
1467bef
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Jan 29, 2020
0a2fa91
Added from master
igoristic Jan 29, 2020
69791d4
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Jan 29, 2020
0b79ecc
Added more shims
igoristic Jan 30, 2020
392589e
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Jan 30, 2020
8d33f59
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Jan 31, 2020
f78e278
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Jan 31, 2020
08f8421
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Feb 3, 2020
4bc829c
Updated master
igoristic Feb 3, 2020
b31832f
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Feb 3, 2020
db58c76
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Feb 3, 2020
3530b99
Merged master
igoristic Feb 3, 2020
c5724ac
Fixed ts config file
igoristic Feb 3, 2020
ed9127c
Fixed ui_exports
igoristic Feb 4, 2020
5aff3ee
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Feb 4, 2020
f00194a
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Feb 4, 2020
9e3a033
Fixed snapshots
igoristic Feb 4, 2020
d32856e
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Feb 4, 2020
30f3dfc
Fixed hard refresh bug and some tests
igoristic Feb 4, 2020
7ca4b03
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Feb 7, 2020
a490ea4
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Feb 7, 2020
3089ed1
Addresed feedback
igoristic Feb 7, 2020
27c3b05
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Feb 7, 2020
5916cff
Added missing imports
igoristic Feb 8, 2020
4342c4c
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Feb 8, 2020
dac0602
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Feb 10, 2020
08761c2
Merge branch 'master' of https://github.com/elastic/kibana into np_re…
igoristic Feb 10, 2020
9a7e26c
Merge branch 'master' into np_ready_2
elasticmachine Feb 10, 2020
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
3 changes: 0 additions & 3 deletions x-pack/legacy/plugins/monitoring/.kibana-plugin-helpers.json

This file was deleted.

98 changes: 0 additions & 98 deletions x-pack/legacy/plugins/monitoring/index.js

This file was deleted.

138 changes: 138 additions & 0 deletions x-pack/legacy/plugins/monitoring/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* 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 { resolve } from 'path';
import KbnServer, { Server } from 'src/legacy/server/kbn_server';
import {
LegacyPluginApi,
LegacyPluginSpec,
LegacyPluginOptions,
} from 'src/legacy/plugin_discovery/types';
import { KIBANA_ALERTING_ENABLED } from './common/constants';

// @ts-ignore
import { getUiExports } from './ui_exports';
// @ts-ignore
import { config as configDefaults } from './config';
// @ts-ignore
import { deprecations } from './deprecations';
// @ts-ignore
import { Plugin } from './server/plugin';
// @ts-ignore
import { initInfraSource } from './server/lib/logs/init_infra_source';

type InfraPlugin = any; // TODO
type PluginsSetup = any; // TODO
type LegacySetup = any; // TODO

const deps = ['kibana', 'elasticsearch', 'xpack_main'];
if (KIBANA_ALERTING_ENABLED) {
deps.push(...['alerting', 'actions']);
}

const validConfigOptions: string[] = [
'monitoring.ui.enabled',
'monitoring.kibana.collection.enabled',
'monitoring.ui.max_bucket_size',
'monitoring.ui.min_interval_seconds',
'kibana.index',
'monitoring.ui.show_license_expiration',
'monitoring.ui.container.elasticsearch.enabled',
'monitoring.ui.container.logstash.enabled',
'monitoring.tests.cloud_detector.enabled',
'monitoring.kibana.collection.interval',
'monitoring.ui.elasticsearch.hosts',
'monitoring.ui.elasticsearch',
'monitoring.xpack_api_polling_frequency_millis',
'server.uuid',
Copy link
Contributor

@mshustov mshustov Feb 7, 2020

Choose a reason for hiding this comment

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

you can already start consuming them from server.newPlatform.setup.core.http.getServerInfo and server.newPlatform.setup.core.uuid.getInstanceUuid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this will also be in the next phase, when we start using np alternatives and whitelisting config properties

Copy link
Contributor

Choose a reason for hiding this comment

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

fair enough

'server.name',
'server.host',
'server.port',
'monitoring.cluster_alerts.email_notifications.enabled',
'monitoring.cluster_alerts.email_notifications.email_address',
'monitoring.ui.ccs.enabled',
'monitoring.ui.elasticsearch.logFetchCount',
'monitoring.ui.logs.index',
];

interface LegacyPluginOptionsWithKbnServer extends LegacyPluginOptions {
kbnServer?: KbnServer;
}

/**
* Invokes plugin modules to instantiate the Monitoring plugin for Kibana
* @param kibana {Object} Kibana plugin instance
* @return {Object} Monitoring UI Kibana plugin object
*/
export const monitoring = (kibana: LegacyPluginApi): LegacyPluginSpec => {
return new kibana.Plugin({
require: deps,
id: 'monitoring',
configPrefix: 'monitoring',
publicDir: resolve(__dirname, 'public'),
config: configDefaults,
uiExports: getUiExports(),
deprecations,

init(server: Server) {
const serverConfig = server.config();
const { getOSInfo, plugins, injectUiAppVars } = server as typeof server & { getOSInfo?: any };
const log = (...args: Parameters<typeof server.log>) => server.log(...args);
const route = (...args: Parameters<typeof server.route>) => server.route(...args);
const expose = (...args: Parameters<typeof server.expose>) => server.expose(...args);
const serverFacade = {
config: () => ({
get: (key: string) => {
if (validConfigOptions.includes(key)) {
return serverConfig.get(key);
}
throw new Error(`Unknown key '${key}'`);
},
}),
injectUiAppVars,
log,
logger: server.newPlatform.coreContext.logger,
getOSInfo,
events: {
on: (...args: Parameters<typeof server.events.on>) => server.events.on(...args),
},
route,
expose,
_hapi: server,
_kbnServer: this.kbnServer,
};

const legacyPlugins = plugins as Partial<typeof plugins> & { infra?: InfraPlugin };
const { xpack_main, elasticsearch, infra, alerting } = legacyPlugins;
const {
core: coreSetup,
plugins: { usageCollection, licensing },
} = server.newPlatform.setup;

const pluginsSetup: PluginsSetup = {
usageCollection,
licensing,
};

const __LEGACY: LegacySetup = {
...serverFacade,
plugins: {
xpack_main,
elasticsearch,
infra,
alerting,
},
};

new Plugin().setup(coreSetup, pluginsSetup, __LEGACY);
},

postInit(server: Server) {
const { infra } = server.plugins as Partial<typeof server.plugins> & { infra?: InfraPlugin };
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't you declare dependency on infra plugin?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean through kibana.json? We'll do that in the next phase when we move the client outside the legacy directory

Copy link
Contributor

Choose a reason for hiding this comment

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

initInfraSource(server.config(), infra);
},
} as Partial<LegacyPluginOptionsWithKbnServer>);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ jest.mock('../../', () => ({
MonitoringTimeseriesContainer: () => 'MonitoringTimeseriesContainer',
}));

jest.mock('../../../np_imports/ui/chrome', () => {
return {
getBasePath: () => '',
};
});

import { BeatsOverview } from './overview';

describe('Overview', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,34 @@ const props = {
updateLegend: () => void 0,
};

describe('Test legends to toggle series: ', () => {
jest.mock('../../np_imports/ui/chrome', () => {
return {
getBasePath: () => '',
};
});

// TODO: Skipping for now, seems flaky in New Platform (needs more investigation)
describe.skip('Test legends to toggle series: ', () => {
const ids = props.series.map(item => item.id);

it('should toggle based on seriesToShow array', () => {
const component = shallow(<ChartTarget {...props} />);
describe('props.series: ', () => {
it('should toggle based on seriesToShow array', () => {
const component = shallow(<ChartTarget {...props} />);

const componentClass = component.instance();
const componentClass = component.instance();

const seriesA = componentClass.filterData(props.series, [ids[0]]);
expect(seriesA.length).to.be(1);
expect(seriesA[0].id).to.be(ids[0]);
const seriesA = componentClass.filterData(props.series, [ids[0]]);
expect(seriesA.length).to.be(1);
expect(seriesA[0].id).to.be(ids[0]);

const seriesB = componentClass.filterData(props.series, [ids[1]]);
expect(seriesB.length).to.be(1);
expect(seriesB[0].id).to.be(ids[1]);
const seriesB = componentClass.filterData(props.series, [ids[1]]);
expect(seriesB.length).to.be(1);
expect(seriesB[0].id).to.be(ids[1]);

const seriesAB = componentClass.filterData(props.series, ids);
expect(seriesAB.length).to.be(2);
expect(seriesAB[0].id).to.be(ids[0]);
expect(seriesAB[1].id).to.be(ids[1]);
const seriesAB = componentClass.filterData(props.series, ids);
expect(seriesAB.length).to.be(2);
expect(seriesAB[0].id).to.be(ids[0]);
expect(seriesAB[1].id).to.be(ids[1]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import chrome from 'ui/chrome';
import chrome from '../../np_imports/ui/chrome';
import { merge } from 'lodash';
import { CHART_LINE_COLOR, CHART_TEXT_COLOR } from '../../../common/constants';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import React, { Fragment, Component } from 'react';
import chrome from 'ui/chrome';
import chrome from 'plugins/monitoring/np_imports/ui/chrome';
import moment from 'moment';
import numeral from '@elastic/numeral';
import { capitalize, partial } from 'lodash';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import React from 'react';
import { shallow } from 'enzyme';
import { CcrShard } from './ccr_shard';

jest.mock('../../../np_imports/ui/chrome', () => {
return {
getBasePath: () => '',
};
});

describe('CcrShard', () => {
const props = {
formattedLeader: 'leader on remote',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { SetupModeBadge } from '../../setup_mode/badge';
import { KIBANA_SYSTEM_ID } from '../../../../common/constants';
import { ListingCallOut } from '../../setup_mode/listing_callout';

const getColumns = (kbnUrl, scope, setupMode) => {
const getColumns = setupMode => {
const columns = [
{
name: i18n.translate('xpack.monitoring.kibana.listing.nameColumnTitle', {
Expand Down Expand Up @@ -68,11 +68,7 @@ const getColumns = (kbnUrl, scope, setupMode) => {
return (
<div>
<EuiLink
onClick={() => {
scope.$evalAsync(() => {
kbnUrl.changePath(`/kibana/instances/${kibana.kibana.uuid}`);
});
}}
href={`#/kibana/instances/${kibana.kibana.uuid}`}
data-test-subj={`kibanaLink-${name}`}
>
{name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@elastic/eui';
import { LicenseStatus, AddLicense } from 'plugins/xpack_main/components';
import { FormattedMessage } from '@kbn/i18n/react';
import chrome from 'ui/chrome';
import chrome from 'plugins/monitoring/np_imports/ui/chrome';

const licenseManagement = `${chrome.getBasePath()}/app/kibana#/management/elasticsearch/license_management`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/
import React, { PureComponent } from 'react';
import { capitalize } from 'lodash';
import chrome from 'ui/chrome';
import chrome from '../../np_imports/ui/chrome';
import { EuiBasicTable, EuiTitle, EuiSpacer, EuiText, EuiCallOut, EuiLink } from '@elastic/eui';
import { INFRA_SOURCE_ID } from '../../../common/constants';
import { formatDateTimeLocal } from '../../../common/formatting';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { Reason } from './reason';
import { capabilities } from 'ui/capabilities';
import { capabilities } from '../../np_imports/ui/capabilities';

const columnTimestampTitle = i18n.translate('xpack.monitoring.logs.listing.timestampTitle', {
defaultMessage: 'Timestamp',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import React from 'react';
import { shallow } from 'enzyme';
import { Logs } from './logs';

jest.mock('ui/chrome', () => {
jest.mock('../../np_imports/ui/chrome', () => {
return {
getBasePath: () => '',
};
});

jest.mock(
'ui/capabilities',
'../../np_imports/ui/capabilities',
() => ({
capabilities: {
get: () => ({ logs: { show: true } }),
Expand Down
Loading