Skip to content

Commit

Permalink
[Uptime] Remove legacy es client (elastic#51403)
Browse files Browse the repository at this point in the history
* Move a REST endpoint and the GQL endpoint to NP routing.

* Delete obsolete REST endpoint.

* Update remaining REST routes to work with NP router.

* Remove obsolete code, update some unit tests.

* Simplify route creation.

* Remove tests of API decommissioned API endpoint.

* Rename domain check.

* Make return shape of index pattern endpoint correspond to required NP resp body.

* Move validate to appropriate level of route definition object for monitor details endpoint.

* Update snapshot count route.

* Fix broken lint rule.

* Move a REST endpoint and the GQL endpoint to NP routing.

* Update remaining REST routes to work with NP router.

* Update remaining REST routes to work with NP router.

* Refactor query functions to accept new es client from request contexts.

* WIP updating framework adapter.

* Refactor remaining routes/resolvers to remove usage of legacy Elasticsearch client.

* Fix broken unit tests.

* Fix incorrect user usage for a REST endpoint.

* Fix some broken imports and types.

* Port monitor details REST endpoint to NP.

* Remove some merge errors.

* Update adapters to take a single options parameter.

* Update broken test files.

* Resolve typescript warnings.

* Update resolver types.

* Change GraphQL interface name for es client.

* Delete unused code and fix incorrect type.

* Rename type for REST endpoint creators.

* Nest message values in body object for invalid response messages.

* Reorganize a file and clean up some types.

* Add wrapper function to reduce boilerplate route code.
  • Loading branch information
justinkambic authored Dec 17, 2019
1 parent 75447e5 commit b7ff35d
Show file tree
Hide file tree
Showing 47 changed files with 687 additions and 688 deletions.
3 changes: 1 addition & 2 deletions x-pack/legacy/plugins/uptime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ export const uptime = (kibana: any) =>
init(server: KibanaServer) {
const initializerContext = {} as PluginInitializerContext;
const { savedObjects } = server;
const { elasticsearch, xpack_main } = server.plugins;
const { xpack_main } = server.plugins;
const { usageCollection } = server.newPlatform.setup.plugins;

plugin(initializerContext).setup(
{
route: server.newPlatform.setup.core.http.createRouter(),
},
{
elasticsearch,
savedObjects,
usageCollection,
xpack: xpack_main,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export const createMonitorStatesResolvers: CreateUMGraphQLResolvers = (
return {
Query: {
async getMonitorStates(
resolver,
_resolver,
{ dateRangeStart, dateRangeEnd, filters, pagination, statusFilter },
{ req }
{ APICaller }
): Promise<MonitorSummaryResult> {
const decodedPagination = pagination
? JSON.parse(decodeURIComponent(pagination))
Expand All @@ -50,15 +50,18 @@ export const createMonitorStatesResolvers: CreateUMGraphQLResolvers = (
totalSummaryCount,
{ summaries, nextPagePagination, prevPagePagination },
] = await Promise.all([
libs.pings.getDocCount(req),
libs.monitorStates.getMonitorStates(
req,
libs.pings.getDocCount({ callES: APICaller }),
libs.monitorStates.getMonitorStates({
callES: APICaller,
dateRangeStart,
dateRangeEnd,
decodedPagination,
pagination: decodedPagination,
filters,
statusFilter
),
// this is added to make typescript happy,
// this sort of reassignment used to be further downstream but I've moved it here
// because this code is going to be decomissioned soon
statusFilter: statusFilter || undefined,
}),
]);
return {
summaries,
Expand All @@ -67,8 +70,8 @@ export const createMonitorStatesResolvers: CreateUMGraphQLResolvers = (
totalSummaryCount,
};
},
async getStatesIndexStatus(resolver, {}, { req }): Promise<StatesIndexStatus> {
return await libs.monitorStates.statesIndexExists(req);
async getStatesIndexStatus(_resolver, {}, { APICaller }): Promise<StatesIndexStatus> {
return await libs.monitorStates.statesIndexExists({ callES: APICaller });
},
},
};
Expand Down
54 changes: 31 additions & 23 deletions x-pack/legacy/plugins/uptime/server/graphql/monitors/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,54 +71,62 @@ export const createMonitorsResolvers: CreateUMGraphQLResolvers = (
} => ({
Query: {
async getSnapshotHistogram(
resolver,
_resolver,
{ dateRangeStart, dateRangeEnd, filters, monitorId, statusFilter },
{ req }
{ APICaller }
): Promise<HistogramResult> {
return await libs.pings.getPingHistogram(
req,
return await libs.pings.getPingHistogram({
callES: APICaller,
dateRangeStart,
dateRangeEnd,
filters,
monitorId,
statusFilter
);
statusFilter,
});
},
async getMonitorChartsData(
resolver,
_resolver,
{ monitorId, dateRangeStart, dateRangeEnd, location },
{ req }
{ APICaller }
): Promise<MonitorChart> {
return await libs.monitors.getMonitorChartsData(
req,
return await libs.monitors.getMonitorChartsData({
callES: APICaller,
monitorId,
dateRangeStart,
dateRangeEnd,
location
);
location,
});
},
async getLatestMonitors(
resolver,
_resolver,
{ dateRangeStart, dateRangeEnd, monitorId, location },
{ req }
{ APICaller }
): Promise<Ping[]> {
return await libs.pings.getLatestMonitorDocs(
req,
return await libs.pings.getLatestMonitorDocs({
callES: APICaller,
dateRangeStart,
dateRangeEnd,
monitorId,
location
);
location,
});
},
async getFilterBar(resolver, { dateRangeStart, dateRangeEnd }, { req }): Promise<FilterBar> {
return await libs.monitors.getFilterBar(req, dateRangeStart, dateRangeEnd);
async getFilterBar(
_resolver,
{ dateRangeStart, dateRangeEnd },
{ APICaller }
): Promise<FilterBar> {
return await libs.monitors.getFilterBar({
callES: APICaller,
dateRangeStart,
dateRangeEnd,
});
},
async getMonitorPageTitle(
resolver: any,
_resolver: any,
{ monitorId },
{ req }
{ APICaller }
): Promise<MonitorPageTitle | null> {
return await libs.monitors.getMonitorPageTitle(req, monitorId);
return await libs.monitors.getMonitorPageTitle({ callES: APICaller, monitorId });
},
},
});
16 changes: 8 additions & 8 deletions x-pack/legacy/plugins/uptime/server/graphql/pings/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ export const createPingsResolvers: CreateUMGraphQLResolvers = (
} => ({
Query: {
async allPings(
resolver,
_resolver,
{ monitorId, sort, size, status, dateRangeStart, dateRangeEnd, location },
{ req }
{ APICaller }
): Promise<PingResults> {
return await libs.pings.getAll(
req,
return await libs.pings.getAll({
callES: APICaller,
dateRangeStart,
dateRangeEnd,
monitorId,
status,
sort,
size,
location
);
location,
});
},
async getDocCount(resolver, args, { req }): Promise<DocCount> {
return libs.pings.getDocCount(req);
async getDocCount(_resolver, _args, { APICaller }): Promise<DocCount> {
return libs.pings.getDocCount({ callES: APICaller });
},
},
});
12 changes: 8 additions & 4 deletions x-pack/legacy/plugins/uptime/server/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Request } from 'hapi';
import { RequestHandlerContext, CallAPIOptions } from 'kibana/server';
import { UMServerLibs } from '../lib/lib';

export interface UMContext {
req: Request;
}
export type UMContext = RequestHandlerContext & {
APICaller: (
endpoint: string,
clientParams?: Record<string, any>,
options?: CallAPIOptions | undefined
) => Promise<any>;
};

export interface UMGraphQLResolver {
Query?: any;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
*/

import { GraphQLSchema } from 'graphql';
import { SavedObjectsLegacyService, RequestHandler, IRouter } from 'src/core/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import {
SavedObjectsLegacyService,
RequestHandler,
IRouter,
CallAPIOptions,
SavedObjectsClientContract,
} from 'src/core/server';
import { ObjectType } from '@kbn/config-schema';
import { UMRouteDefinition } from '../../../rest_api';
import { UMKibanaRoute } from '../../../rest_api';

export interface UMFrameworkRouteOptions<
P extends ObjectType,
Expand All @@ -22,19 +28,32 @@ export interface UMFrameworkRouteOptions<
validate: any;
}

type APICaller = (
endpoint: string,
clientParams: Record<string, any>,
options?: CallAPIOptions
) => Promise<any>;

export type UMElasticsearchQueryFn<P, R = any> = (
params: { callES: APICaller } & P
) => Promise<R> | R;

export type UMSavedObjectsQueryFn<T = any, P = undefined> = (
client: SavedObjectsClientContract,
params: P
) => Promise<T> | T;

export interface UptimeCoreSetup {
route: IRouter;
}

export interface UptimeCorePlugins {
elasticsearch: any;
savedObjects: SavedObjectsLegacyService<any>;
usageCollection: UsageCollectionSetup;
xpack: any;
}

export interface UMBackendFrameworkAdapter {
registerRoute(route: UMRouteDefinition): void;
registerRoute(route: UMKibanaRoute): void;
registerGraphQLEndpoint(routePath: string, schema: GraphQLSchema): void;
getSavedObjectsClient(): any;
}
Loading

0 comments on commit b7ff35d

Please sign in to comment.