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

[Uptime] Remove legacy es client #51403

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0314775
Move a REST endpoint and the GQL endpoint to NP routing.
justinkambic Nov 19, 2019
1dd6ea8
Delete obsolete REST endpoint.
justinkambic Nov 20, 2019
a05594d
Update remaining REST routes to work with NP router.
justinkambic Nov 20, 2019
74bb6f0
Remove obsolete code, update some unit tests.
justinkambic Nov 21, 2019
b2730e5
Simplify route creation.
justinkambic Nov 21, 2019
c36e42a
Remove tests of API decommissioned API endpoint.
justinkambic Nov 21, 2019
92aee58
Rename domain check.
justinkambic Nov 21, 2019
49d8cf2
Make return shape of index pattern endpoint correspond to required NP…
justinkambic Nov 25, 2019
bb35540
Move validate to appropriate level of route definition object for mon…
justinkambic Nov 25, 2019
789d232
Update snapshot count route.
justinkambic Dec 2, 2019
a4047af
Fix broken lint rule.
justinkambic Dec 2, 2019
7221e8a
Move a REST endpoint and the GQL endpoint to NP routing.
justinkambic Nov 19, 2019
64fe387
Update remaining REST routes to work with NP router.
justinkambic Nov 20, 2019
43a1c83
Refactor query functions to accept new es client from request contexts.
justinkambic Nov 21, 2019
6eb1bf3
WIP updating framework adapter.
justinkambic Nov 21, 2019
2990071
Refactor remaining routes/resolvers to remove usage of legacy Elastic…
justinkambic Nov 22, 2019
df4d4b7
Fix broken unit tests.
justinkambic Nov 22, 2019
888ba2b
Fix incorrect user usage for a REST endpoint.
justinkambic Nov 22, 2019
5361270
Fix some broken imports and types.
justinkambic Nov 22, 2019
cafa4de
Update remaining REST routes to work with NP router.
justinkambic Nov 20, 2019
5a11ec0
Port monitor details REST endpoint to NP.
justinkambic Nov 26, 2019
cb5fe05
Remove some merge errors.
justinkambic Dec 3, 2019
19b0b41
Merge branch 'master' into uptime_remove-legacy-es-client
justinkambic Dec 5, 2019
7bac947
Merge branch 'master' of github.com:elastic/kibana into uptime_remove…
justinkambic Dec 6, 2019
025b3e0
Update adapters to take a single options parameter.
justinkambic Dec 6, 2019
e6e7f1c
Update broken test files.
justinkambic Dec 6, 2019
72e2148
Resolve typescript warnings.
justinkambic Dec 6, 2019
786a714
Update resolver types.
justinkambic Dec 6, 2019
7d91061
Merge branch 'master' into uptime_remove-legacy-es-client
justinkambic Dec 9, 2019
2300e81
Change GraphQL interface name for es client.
justinkambic Dec 9, 2019
d7601be
Delete unused code and fix incorrect type.
justinkambic Dec 9, 2019
17a6adc
Rename type for REST endpoint creators.
justinkambic Dec 9, 2019
ac4e2e9
Nest message values in body object for invalid response messages.
justinkambic Dec 9, 2019
ed9d586
Merge branch 'master' into uptime_remove-legacy-es-client
elasticmachine Dec 10, 2019
c440c64
Merge branch 'master' into uptime_remove-legacy-es-client
justinkambic Dec 12, 2019
c0d5187
Reorganize a file and clean up some types.
justinkambic Dec 12, 2019
07f9cc4
Merge branch 'uptime_remove-legacy-es-client' of github.com:justinkam…
justinkambic Dec 12, 2019
2300531
Merge master, modify new route to conform to updated ES client calling.
justinkambic Dec 16, 2019
c745fb8
Add wrapper function to reduce boilerplate route code.
justinkambic Dec 17, 2019
75e9d84
Merge branch 'master' into uptime_remove-legacy-es-client
justinkambic Dec 17, 2019
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: 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,
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason why this now has an underscore in front?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a typescript thing. You can resolve unused parameter warnings by prefixing them with _.

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html search for "exempt from unused parameter checking" to see more info.

{ 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