[Uptime] Migrate server to new platform (#53939)

* 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>
This commit is contained in:
Justin Kambic 2020-02-25 09:27:18 -05:00 committed by GitHub
parent 418c44a47e
commit d339740c2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
119 changed files with 204 additions and 134 deletions

View file

@ -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',
};

View file

@ -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) =>
@ -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,
}
);
},
});

View file

@ -1,15 +0,0 @@
/*
* 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 { buildSchemaFromTypeDefinitions } from 'graphql-tools';
import { typeDefs } from '../server/graphql';
export const schemas = [...typeDefs];
// this default export is used to feed the combined types to the gql-gen tool
// which generates the corresponding typescript types
// eslint-disable-next-line import/no-default-export
export default buildSchemaFromTypeDefinitions(schemas);

View file

@ -1,5 +0,0 @@
/*
* 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.
*/

View file

@ -1,19 +0,0 @@
/*
* 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 { PluginInitializerContext } from 'src/core/server';
import { initServerWithKibana } from './kibana.index';
import { UptimeCoreSetup, UptimeCorePlugins } from './lib/adapters/framework';
export function plugin(initializerContext: PluginInitializerContext) {
return new Plugin();
}
export class Plugin {
public setup(core: UptimeCoreSetup, plugins: UptimeCorePlugins) {
initServerWithKibana(core, plugins);
}
}

View file

@ -0,0 +1,9 @@
{
"configPath": ["xpack"],
"id": "uptime",
"kibanaVersion": "kibana",
"requiredPlugins": ["features", "licensing", "usageCollection"],
"server": true,
"ui": false,
"version": "8.0.0"
}

View file

@ -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>,

View file

@ -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,

View file

@ -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';

View file

@ -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);

View file

@ -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';
@ -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'],
@ -59,4 +54,6 @@ export const initServerWithKibana = (server: UptimeCoreSetup, plugins: UptimeCor
},
},
});
initUptimeServer(libs);
};

View file

@ -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,
@ -34,9 +30,8 @@ export interface UptimeCoreSetup {
}
export interface UptimeCorePlugins {
savedObjects: SavedObjectsLegacyService;
features: PluginSetupContract;
usageCollection: UsageCollectionSetup;
xpack: any;
}
export interface UMBackendFrameworkAdapter {

View file

@ -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 = {

View file

@ -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', () => {

View file

@ -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;

View file

@ -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

View file

@ -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 */

View file

@ -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>) =>

View file

@ -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 {

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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;

View file

@ -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.

View file

@ -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 {

View file

@ -5,10 +5,10 @@
*/
import { UMElasticsearchQueryFn } from '../adapters';
import { INDEX_NAMES, QUERY } from '../../../../../legacy/plugins/uptime/common/constants';
import { getFilterClause } from '../helper';
import { INDEX_NAMES, QUERY } from '../../../common/constants';
import { HistogramQueryResult } from './types';
import { HistogramResult } from '../../../common/types';
import { HistogramResult } from '../../../../../legacy/plugins/uptime/common/types';
export interface GetPingHistogramParams {
/** @member dateRangeStart timestamp bounds */

View file

@ -5,8 +5,12 @@
*/
import { UMElasticsearchQueryFn } from '../adapters/framework';
import { PingResults, Ping, HttpBody } from '../../../common/graphql/types';
import { INDEX_NAMES } from '../../../common/constants';
import {
PingResults,
Ping,
HttpBody,
} from '../../../../../legacy/plugins/uptime/common/graphql/types';
import { INDEX_NAMES } from '../../../../../legacy/plugins/uptime/common/constants';
export interface GetPingsParams {
/** @member dateRangeStart timestamp bounds */

View file

@ -5,9 +5,12 @@
*/
import { UMElasticsearchQueryFn } from '../adapters';
import { Snapshot } from '../../../common/runtime_types';
import { Snapshot } from '../../../../../legacy/plugins/uptime/common/runtime_types';
import {
CONTEXT_DEFAULTS,
INDEX_NAMES,
} from '../../../../../legacy/plugins/uptime/common/constants';
import { QueryContext } from './search';
import { CONTEXT_DEFAULTS, INDEX_NAMES } from '../../../common/constants';
export interface GetSnapshotCountParams {
dateRangeStart: string;

View file

@ -12,7 +12,7 @@ import {
MonitorGroupsPage,
} from '../fetch_page';
import { QueryContext } from '../query_context';
import { MonitorSummary } from '../../../../../common/graphql/types';
import { MonitorSummary } from '../../../../../../../legacy/plugins/uptime/common/graphql/types';
import { nextPagination, prevPagination, simpleQueryContext } from './test_helpers';
const simpleFixture: MonitorGroups[] = [

View file

@ -6,7 +6,10 @@
import { QueryContext } from '../query_context';
import { CursorPagination } from '../types';
import { CursorDirection, SortOrder } from '../../../../../common/graphql/types';
import {
CursorDirection,
SortOrder,
} from '../../../../../../../legacy/plugins/uptime/common/graphql/types';
describe(QueryContext, () => {
// 10 minute range

View file

@ -5,7 +5,10 @@
*/
import { CursorPagination } from '../types';
import { CursorDirection, SortOrder } from '../../../../../common/graphql/types';
import {
CursorDirection,
SortOrder,
} from '../../../../../../../legacy/plugins/uptime/common/graphql/types';
import { QueryContext } from '../query_context';
export const prevPagination = (key: any): CursorPagination => {

View file

@ -7,14 +7,14 @@
import { get, sortBy } from 'lodash';
import { QueryContext } from './query_context';
import { getHistogramIntervalFormatted } from '../../helper';
import { INDEX_NAMES, STATES } from '../../../../common/constants';
import { INDEX_NAMES, STATES } from '../../../../../../legacy/plugins/uptime/common/constants';
import {
MonitorSummary,
SummaryHistogram,
Check,
CursorDirection,
SortOrder,
} from '../../../../common/graphql/types';
} from '../../../../../../legacy/plugins/uptime/common/graphql/types';
import { MonitorEnricher } from './fetch_page';
export const enrichMonitorGroups: MonitorEnricher = async (

View file

@ -7,8 +7,12 @@
import { flatten } from 'lodash';
import { CursorPagination } from './types';
import { QueryContext } from './query_context';
import { QUERY } from '../../../../common/constants';
import { CursorDirection, MonitorSummary, SortOrder } from '../../../../common/graphql/types';
import { QUERY } from '../../../../../../legacy/plugins/uptime/common/constants';
import {
CursorDirection,
MonitorSummary,
SortOrder,
} from '../../../../../../legacy/plugins/uptime/common/graphql/types';
import { enrichMonitorGroups } from './enrich_monitor_groups';
import { MonitorGroupIterator } from './monitor_group_iterator';

View file

@ -5,8 +5,8 @@
*/
import { get, set } from 'lodash';
import { CursorDirection } from '../../../../common/graphql/types';
import { INDEX_NAMES } from '../../../../common/constants';
import { CursorDirection } from '../../../../../../legacy/plugins/uptime/common/graphql/types';
import { INDEX_NAMES } from '../../../../../../legacy/plugins/uptime/common/constants';
import { QueryContext } from './query_context';
// This is the first phase of the query. In it, we find the most recent check groups that matched the given query.

View file

@ -6,7 +6,7 @@
import { QueryContext } from './query_context';
import { fetchChunk } from './fetch_chunk';
import { CursorDirection } from '../../../../common/graphql/types';
import { CursorDirection } from '../../../../../../legacy/plugins/uptime/common/graphql/types';
import { MonitorGroups } from './fetch_page';
import { CursorPagination } from './types';

View file

@ -6,7 +6,7 @@
import moment from 'moment';
import { APICaller } from 'src/core/server';
import { INDEX_NAMES } from '../../../../common/constants';
import { INDEX_NAMES } from '../../../../../../legacy/plugins/uptime/common/constants';
import { CursorPagination } from './types';
import { parseRelativeDate } from '../../helper';

View file

@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { INDEX_NAMES } from '../../../../common/constants';
import { INDEX_NAMES } from '../../../../../../legacy/plugins/uptime/common/constants';
import { QueryContext } from './query_context';
import { CursorDirection } from '../../../../common/graphql/types';
import { CursorDirection } from '../../../../../../legacy/plugins/uptime/common/graphql/types';
import { MonitorGroups, MonitorLocCheckGroup } from './fetch_page';
/**

View file

@ -4,7 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { CursorDirection, SortOrder } from '../../../../common/graphql/types';
import {
CursorDirection,
SortOrder,
} from '../../../../../../legacy/plugins/uptime/common/graphql/types';
export interface CursorPagination {
cursorKey?: any;

View file

@ -4,9 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { Ping, PingResults } from '../../../common/graphql/types';
import { Ping, PingResults } from '../../../../../legacy/plugins/uptime/common/graphql/types';
import { UMElasticsearchQueryFn } from '../adapters';
import { GetPingHistogramParams, HistogramResult } from '../../../common/types';
import {
GetPingHistogramParams,
HistogramResult,
} from '../../../../../legacy/plugins/uptime/common/types';
export interface GetAllParams {
/** @member dateRangeStart timestamp bounds */

View file

@ -5,7 +5,12 @@
*/
import { UMElasticsearchQueryFn } from '../adapters';
import { Ping, MonitorChart, PingResults, StatesIndexStatus } from '../../../common/graphql/types';
import {
Ping,
MonitorChart,
PingResults,
StatesIndexStatus,
} from '../../../../../legacy/plugins/uptime/common/graphql/types';
import {
GetFilterBarParams,
GetLatestMonitorParams,
@ -22,10 +27,10 @@ import {
MonitorDetails,
MonitorLocations,
Snapshot,
} from '../../../common/runtime_types';
} from '../../../../../legacy/plugins/uptime/common/runtime_types';
import { GetMonitorStatesResult } from './get_monitor_states';
import { GetSnapshotCountParams } from './get_snapshot_counts';
import { HistogramResult } from '../../../common/types';
import { HistogramResult } from '../../../../../legacy/plugins/uptime/common/types';
type ESQ<P, R> = UMElasticsearchQueryFn<P, R>;

View file

@ -0,0 +1,17 @@
/*
* 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 { PluginInitializerContext, CoreStart, CoreSetup } from '../../../../src/core/server';
import { initServerWithKibana } from './kibana.index';
import { UptimeCorePlugins } from './lib/adapters';
export class Plugin {
constructor(_initializerContext: PluginInitializerContext) {}
public setup(core: CoreSetup, plugins: UptimeCorePlugins) {
initServerWithKibana({ route: core.http.createRouter() }, plugins);
}
public start(_core: CoreStart, _plugins: any) {}
}

Some files were not shown because too many files have changed in this diff Show more