Skip to content

Commit

Permalink
[Uptime] Remove redundant adapter function (elastic#56980)
Browse files Browse the repository at this point in the history
* Remove get_doc_count function in favor of index status function.

* Rename adapter function.

* Remove obsolete import.

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
justinkambic and elasticmachine committed Feb 25, 2020
1 parent cc655a7 commit de8507c
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 105 deletions.
12 changes: 0 additions & 12 deletions x-pack/legacy/plugins/uptime/common/graphql/introspection.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,6 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "getDocCount",
"description": "Gets the number of documents in the target index",
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": { "kind": "OBJECT", "name": "DocCount", "ofType": null }
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "getMonitors",
"description": "",
Expand Down
2 changes: 0 additions & 2 deletions x-pack/legacy/plugins/uptime/common/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export type UnsignedInteger = any;
export interface Query {
/** Get a list of all recorded pings for all monitors */
allPings: PingResults;
/** Gets the number of documents in the target index */
getDocCount: DocCount;

getMonitors?: LatestMonitorsResult | null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export const createMonitorStatesResolvers: CreateUMGraphQLResolvers = (
? JSON.parse(decodeURIComponent(pagination))
: CONTEXT_DEFAULTS.CURSOR_PAGINATION;
const [
totalSummaryCount,
indexStatus,
{ summaries, nextPagePagination, prevPagePagination },
] = await Promise.all([
libs.requests.getDocCount({ callES: APICaller }),
libs.requests.getIndexStatus({ callES: APICaller }),
libs.requests.getMonitorStates({
callES: APICaller,
dateRangeStart,
Expand All @@ -63,6 +63,9 @@ export const createMonitorStatesResolvers: CreateUMGraphQLResolvers = (
statusFilter: statusFilter || undefined,
}),
]);

const totalSummaryCount = indexStatus?.docCount ?? { count: undefined };

return {
summaries,
nextPagePagination,
Expand All @@ -71,7 +74,7 @@ export const createMonitorStatesResolvers: CreateUMGraphQLResolvers = (
};
},
async getStatesIndexStatus(_resolver, {}, { APICaller }): Promise<StatesIndexStatus> {
return await libs.requests.getStatesIndexStatus({ callES: APICaller });
return await libs.requests.getIndexStatus({ callES: APICaller });
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { UMResolver } from '../../../common/graphql/resolver_types';
import { AllPingsQueryArgs, DocCount, PingResults } from '../../../common/graphql/types';
import { AllPingsQueryArgs, PingResults } from '../../../common/graphql/types';
import { UMServerLibs } from '../../lib/lib';
import { UMContext } from '../types';
import { CreateUMGraphQLResolvers } from '../types';
Expand All @@ -17,19 +17,15 @@ export type UMAllPingsResolver = UMResolver<
UMContext
>;

export type UMGetDocCountResolver = UMResolver<DocCount | Promise<DocCount>, any, never, UMContext>;

export interface UMPingResolver {
allPings: () => PingResults;
getDocCount: () => number;
}

export const createPingsResolvers: CreateUMGraphQLResolvers = (
libs: UMServerLibs
): {
Query: {
allPings: UMAllPingsResolver;
getDocCount: UMGetDocCountResolver;
};
} => ({
Query: {
Expand All @@ -49,8 +45,5 @@ export const createPingsResolvers: CreateUMGraphQLResolvers = (
location,
});
},
async getDocCount(_resolver, _args, { APICaller }): Promise<DocCount> {
return libs.requests.getDocCount({ callES: APICaller });
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ export const pingsSchema = gql`
"Optional: agent location to filter by."
location: String
): PingResults!
"Gets the number of documents in the target index"
getDocCount: DocCount!
}
type ContainerImage {
Expand Down

This file was deleted.

15 changes: 0 additions & 15 deletions x-pack/legacy/plugins/uptime/server/lib/requests/get_doc_count.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { UMElasticsearchQueryFn } from '../adapters';
import { StatesIndexStatus } from '../../../common/graphql/types';
import { INDEX_NAMES } from '../../../common/constants';

export const getStatesIndexStatus: UMElasticsearchQueryFn<{}, StatesIndexStatus> = async ({
callES,
}) => {
export const getIndexStatus: UMElasticsearchQueryFn<{}, StatesIndexStatus> = async ({ callES }) => {
const {
_shards: { total },
count,
Expand Down
3 changes: 1 addition & 2 deletions x-pack/legacy/plugins/uptime/server/lib/requests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { getDocCount } from './get_doc_count';
export { getFilterBar, GetFilterBarParams } from './get_filter_bar';
export { getUptimeIndexPattern as getIndexPattern } from './get_index_pattern';
export { getLatestMonitor, GetLatestMonitorParams } from './get_latest_monitor';
Expand All @@ -17,4 +16,4 @@ export { getPings, GetPingsParams } from './get_pings';
export { getPingHistogram, GetPingHistogramParams } from './get_ping_histogram';
export { UptimeRequests } from './uptime_requests';
export { getSnapshotCount, GetSnapshotCountParams } from './get_snapshot_counts';
export { getStatesIndexStatus } from './get_states_index_status';
export { getIndexStatus } from './get_index_status';
7 changes: 1 addition & 6 deletions x-pack/legacy/plugins/uptime/server/lib/requests/types.ts
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 { DocCount, Ping, PingResults } from '../../../common/graphql/types';
import { Ping, PingResults } from '../../../common/graphql/types';
import { UMElasticsearchQueryFn } from '../adapters';
import { GetPingHistogramParams, HistogramResult } from '../../../common/types';

Expand Down Expand Up @@ -54,11 +54,6 @@ export interface UMPingsAdapter {
getLatestMonitorStatus: UMElasticsearchQueryFn<GetLatestMonitorDocsParams, Ping>;

getPingHistogram: UMElasticsearchQueryFn<GetPingHistogramParams, HistogramResult>;

/**
* Gets data used for a composite histogram for the currently-running monitors.
*/
getDocCount: UMElasticsearchQueryFn<{}, DocCount>;
}

export interface HistogramQueryResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
*/

import { UMElasticsearchQueryFn } from '../adapters';
import {
DocCount,
Ping,
MonitorChart,
PingResults,
StatesIndexStatus,
} from '../../../common/graphql/types';
import { Ping, MonitorChart, PingResults, StatesIndexStatus } from '../../../common/graphql/types';
import {
GetFilterBarParams,
GetLatestMonitorParams,
Expand All @@ -36,7 +30,6 @@ import { HistogramResult } from '../../../common/types';
type ESQ<P, R> = UMElasticsearchQueryFn<P, R>;

export interface UptimeRequests {
getDocCount: ESQ<{}, DocCount>;
getFilterBar: ESQ<GetFilterBarParams, OverviewFilters>;
getIndexPattern: ESQ<any, {}>;
getLatestMonitor: ESQ<GetLatestMonitorParams, Ping>;
Expand All @@ -48,5 +41,5 @@ export interface UptimeRequests {
getPings: ESQ<GetPingsParams, PingResults>;
getPingHistogram: ESQ<GetPingHistogramParams, HistogramResult>;
getSnapshotCount: ESQ<GetSnapshotCountParams, Snapshot>;
getStatesIndexStatus: ESQ<{}, StatesIndexStatus>;
getIndexStatus: ESQ<{}, StatesIndexStatus>;
}

0 comments on commit de8507c

Please sign in to comment.