Skip to content

Commit

Permalink
[Uptime] Migrate server to new platform (#53939) (#58527)
Browse files Browse the repository at this point in the history
* Move uptime legacy server to plugins directory.

* Re-add feature registration code.

* Move feature registration back to kibana bootstrap file.

* Delete obsolete test file.

* Remove i18n call from untracked file.

* Implement feedback.

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
justinkambic and elasticmachine authored Feb 26, 2020
1 parent 650a317 commit 4bc787d
Show file tree
Hide file tree
Showing 119 changed files with 204 additions and 134 deletions.
7 changes: 6 additions & 1 deletion x-pack/legacy/plugins/uptime/common/constants/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
* you may not use this file except in compliance with the Elastic License.
*/

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

export const PLUGIN = {
APP_ROOT_ID: 'react-uptime-root',
DESCRIPTION: 'Uptime monitoring',
ID: 'uptime',
ROUTER_BASE_NAME: '/app/uptime#',
LOCAL_STORAGE_KEY: 'xpack.uptime',
NAME: i18n.translate('xpack.uptime.featureRegistry.uptimeFeatureName', {
defaultMessage: 'Uptime',
}),
ROUTER_BASE_NAME: '/app/uptime#',
TITLE: 'uptime',
};
19 changes: 0 additions & 19 deletions x-pack/legacy/plugins/uptime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

import { i18n } from '@kbn/i18n';
import { resolve } from 'path';
import { PluginInitializerContext } from 'src/core/server';
import { PLUGIN } from './common/constants';
import { KibanaServer, plugin } from './server';
import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/utils';

export const uptime = (kibana: any) =>
Expand All @@ -35,21 +33,4 @@ export const uptime = (kibana: any) =>
},
home: ['plugins/uptime/register_feature'],
},
init(server: KibanaServer) {
const initializerContext = {} as PluginInitializerContext;
const { savedObjects } = server;
const { xpack_main } = server.plugins;
const { usageCollection } = server.newPlatform.setup.plugins;

plugin(initializerContext).setup(
{
route: server.newPlatform.setup.core.http.createRouter(),
},
{
savedObjects,
usageCollection,
xpack: xpack_main,
}
);
},
});
15 changes: 0 additions & 15 deletions x-pack/legacy/plugins/uptime/scripts/graphql_schemas.ts

This file was deleted.

This file was deleted.

19 changes: 0 additions & 19 deletions x-pack/legacy/plugins/uptime/server/plugin.ts

This file was deleted.

9 changes: 9 additions & 0 deletions x-pack/plugins/uptime/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"configPath": ["xpack"],
"id": "uptime",
"kibanaVersion": "kibana",
"requiredPlugins": ["features", "licensing", "usageCollection"],
"server": true,
"ui": false,
"version": "8.0.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import { CreateUMGraphQLResolvers, UMContext } from '../types';
import { UMServerLibs } from '../../lib/lib';
import { UMResolver } from '../../../common/graphql/resolver_types';
import { UMResolver } from '../../../../../legacy/plugins/uptime/common/graphql/resolver_types';
import {
GetMonitorStatesQueryArgs,
MonitorSummaryResult,
StatesIndexStatus,
} from '../../../common/graphql/types';
import { CONTEXT_DEFAULTS } from '../../../common/constants/context_defaults';
} from '../../../../../legacy/plugins/uptime/common/graphql/types';
import { CONTEXT_DEFAULTS } from '../../../../../legacy/plugins/uptime/common/constants/context_defaults';

export type UMGetMonitorStatesResolver = UMResolver<
MonitorSummaryResult | Promise<MonitorSummaryResult>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { UMResolver } from '../../../common/graphql/resolver_types';
import { GetMonitorChartsDataQueryArgs, MonitorChart } from '../../../common/graphql/types';
import { UMGqlRange } from '../../../../../legacy/plugins/uptime/common/domain_types';
import { UMResolver } from '../../../../../legacy/plugins/uptime/common/graphql/resolver_types';
import {
GetMonitorChartsDataQueryArgs,
MonitorChart,
} from '../../../../../legacy/plugins/uptime/common/graphql/types';
import { UMServerLibs } from '../../lib/lib';
import { CreateUMGraphQLResolvers, UMContext } from '../types';

export type UMMonitorsResolver = UMResolver<any | Promise<any>, any, UMGqlRange, UMContext>;

export type UMGetMonitorChartsResolver = UMResolver<
any | Promise<any>,
any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { UMResolver } from '../../../common/graphql/resolver_types';
import { AllPingsQueryArgs, PingResults } from '../../../common/graphql/types';
import { UMResolver } from '../../../../../legacy/plugins/uptime/common/graphql/resolver_types';
import {
AllPingsQueryArgs,
PingResults,
} from '../../../../../legacy/plugins/uptime/common/graphql/types';
import { UMServerLibs } from '../../lib/lib';
import { UMContext } from '../types';
import { CreateUMGraphQLResolvers } from '../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { PluginInitializerContext } from '../../../../src/core/server';
import { Plugin } from './plugin';

export { initServerWithKibana, KibanaServer } from './kibana.index';
export { plugin } from './plugin';
export const plugin = (initializerContext: PluginInitializerContext) =>
new Plugin(initializerContext);
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { i18n } from '@kbn/i18n';
import { Request, Server } from 'hapi';
import { PLUGIN } from '../common/constants';
import { PLUGIN } from '../../../legacy/plugins/uptime/common/constants';
import { KibanaTelemetryAdapter } from './lib/adapters/telemetry';
import { compose } from './lib/compose/kibana';
import { initUptimeServer } from './uptime_server';
Expand All @@ -25,17 +24,13 @@ export interface KibanaServer extends Server {
}

export const initServerWithKibana = (server: UptimeCoreSetup, plugins: UptimeCorePlugins) => {
const { usageCollection, xpack } = plugins;
const libs = compose(server, plugins);
const { features, usageCollection } = plugins;
const libs = compose(server);
KibanaTelemetryAdapter.registerUsageCollector(usageCollection);

initUptimeServer(libs);

xpack.registerFeature({
features.registerFeature({
id: PLUGIN.ID,
name: i18n.translate('xpack.uptime.featureRegistry.uptimeFeatureName', {
defaultMessage: 'Uptime',
}),
name: PLUGIN.NAME,
navLinkId: PLUGIN.ID,
icon: 'uptimeApp',
app: ['uptime', 'kibana'],
Expand All @@ -59,4 +54,6 @@ export const initServerWithKibana = (server: UptimeCoreSetup, plugins: UptimeCor
},
},
});

initUptimeServer(libs);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@

import { GraphQLSchema } from 'graphql';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import {
SavedObjectsLegacyService,
IRouter,
CallAPIOptions,
SavedObjectsClientContract,
} from 'src/core/server';
import { IRouter, CallAPIOptions, SavedObjectsClientContract } from 'src/core/server';
import { UMKibanaRoute } from '../../../rest_api';
import { PluginSetupContract } from '../../../../../features/server';

type APICaller = (
endpoint: string,
Expand All @@ -34,9 +30,8 @@ export interface UptimeCoreSetup {
}

export interface UptimeCorePlugins {
savedObjects: SavedObjectsLegacyService;
features: PluginSetupContract;
usageCollection: UsageCollectionSetup;
xpack: any;
}

export interface UMBackendFrameworkAdapter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { UMKibanaBackendFrameworkAdapter } from '../adapters/framework';
import * as requests from '../requests';
import { licenseCheck } from '../domains';
import { UMDomainLibs, UMServerLibs } from '../lib';
import { UptimeCorePlugins, UptimeCoreSetup } from '../adapters/framework';
import { UptimeCoreSetup } from '../adapters/framework';

export function compose(server: UptimeCoreSetup, plugins: UptimeCorePlugins): UMServerLibs {
export function compose(server: UptimeCoreSetup): UMServerLibs {
const framework = new UMKibanaBackendFrameworkAdapter(server);

const domainLibs: UMDomainLibs = {
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 { ILicense } from '../../../../../../../plugins/licensing/server';
import { ILicense } from '../../../../../licensing/server';
import { licenseCheck } from '../license';

describe('license check', () => {
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 { ILicense } from '../../../../../../plugins/licensing/server';
import { ILicense } from '../../../../licensing/server';

export interface UMLicenseStatusResponse {
statusCode: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import DateMath from '@elastic/datemath';
import { QUERY } from '../../../common/constants';
import { QUERY } from '../../../../../legacy/plugins/uptime/common/constants';

export const parseRelativeDate = (dateStr: string, options = {}) => {
// We need this this parsing because if user selects This week or this date
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/

import { UMElasticsearchQueryFn } from '../adapters';
import { OverviewFilters } from '../../../common/runtime_types';
import { OverviewFilters } from '../../../../../legacy/plugins/uptime/common/runtime_types';
import { generateFilterAggs } from './generate_filter_aggs';
import { INDEX_NAMES } from '../../../common/constants';
import { INDEX_NAMES } from '../../../../../legacy/plugins/uptime/common/constants';

export interface GetFilterBarParams {
/** @param dateRangeStart timestamp bounds */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import { APICaller } from 'src/core/server';
import { UMElasticsearchQueryFn } from '../adapters';
import { IndexPatternsFetcher, IIndexPattern } from '../../../../../../../src/plugins/data/server';
import { INDEX_NAMES } from '../../../common/constants';
import { IndexPatternsFetcher, IIndexPattern } from '../../../../../../src/plugins/data/server';
import { INDEX_NAMES } from '../../../../../legacy/plugins/uptime/common/constants';

export const getUptimeIndexPattern: UMElasticsearchQueryFn<any, {}> = async callES => {
const indexPatternsFetcher = new IndexPatternsFetcher((...rest: Parameters<APICaller>) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import { UMElasticsearchQueryFn } from '../adapters';
import { StatesIndexStatus } from '../../../common/graphql/types';
import { INDEX_NAMES } from '../../../common/constants';
import { StatesIndexStatus } from '../../../../../legacy/plugins/uptime/common/graphql/types';
import { INDEX_NAMES } from '../../../../../legacy/plugins/uptime/common/constants';

export const getIndexStatus: UMElasticsearchQueryFn<{}, StatesIndexStatus> = async ({ callES }) => {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import { UMElasticsearchQueryFn } from '../adapters';
import { Ping } from '../../../common/graphql/types';
import { INDEX_NAMES } from '../../../common/constants';
import { Ping } from '../../../../../legacy/plugins/uptime/common/graphql/types';
import { INDEX_NAMES } from '../../../../../legacy/plugins/uptime/common/constants';

export interface GetLatestMonitorParams {
/** @member dateRangeStart timestamp bounds */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import { UMElasticsearchQueryFn } from '../adapters';
import { Ping } from '../../../common/graphql/types';
import { INDEX_NAMES } from '../../../common/constants';
import { Ping } from '../../../../../legacy/plugins/uptime/common/graphql/types';
import { INDEX_NAMES } from '../../../../../legacy/plugins/uptime/common/constants';

export interface GetMonitorParams {
/** @member monitorId optional limit to monitorId */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
*/

import { UMElasticsearchQueryFn } from '../adapters';
import { INDEX_NAMES } from '../../../common/constants';
import { INDEX_NAMES } from '../../../../../legacy/plugins/uptime/common/constants';
import { getHistogramIntervalFormatted } from '../helper';
import { MonitorChart, LocationDurationLine } from '../../../common/graphql/types';
import {
MonitorChart,
LocationDurationLine,
} from '../../../../../legacy/plugins/uptime/common/graphql/types';

export interface GetMonitorChartsParams {
/** @member monitorId ID value for the selected monitor */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
*/

import { UMElasticsearchQueryFn } from '../adapters';
import { MonitorDetails, MonitorError } from '../../../common/runtime_types';
import { INDEX_NAMES } from '../../../common/constants';
import {
MonitorDetails,
MonitorError,
} from '../../../../../legacy/plugins/uptime/common/runtime_types';
import { INDEX_NAMES } from '../../../../../legacy/plugins/uptime/common/constants';

export interface GetMonitorDetailsParams {
monitorId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
*/

import { UMElasticsearchQueryFn } from '../adapters';
import { INDEX_NAMES, UNNAMED_LOCATION } from '../../../common/constants';
import { MonitorLocations, MonitorLocation } from '../../../common/runtime_types';
import {
INDEX_NAMES,
UNNAMED_LOCATION,
} from '../../../../../legacy/plugins/uptime/common/constants';
import {
MonitorLocations,
MonitorLocation,
} from '../../../../../legacy/plugins/uptime/common/runtime_types';

/**
* Fetch data for the monitor page title.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { CONTEXT_DEFAULTS } from '../../../common/constants';
import { CONTEXT_DEFAULTS } from '../../../../../legacy/plugins/uptime/common/constants';
import { fetchPage } from './search';
import { UMElasticsearchQueryFn } from '../adapters';
import { MonitorSummary, SortOrder, CursorDirection } from '../../../common/graphql/types';
import {
MonitorSummary,
SortOrder,
CursorDirection,
} from '../../../../../legacy/plugins/uptime/common/graphql/types';
import { QueryContext } from './search';

export interface CursorPagination {
Expand Down
Loading

0 comments on commit 4bc787d

Please sign in to comment.