diff --git a/x-pack/legacy/plugins/uptime/common/constants/query.ts b/x-pack/legacy/plugins/uptime/common/constants/query.ts index d728f114aae76..21574f1d8b27e 100644 --- a/x-pack/legacy/plugins/uptime/common/constants/query.ts +++ b/x-pack/legacy/plugins/uptime/common/constants/query.ts @@ -25,10 +25,3 @@ export const QUERY = { 'error.type', ], }; - -export const STATES = { - // Number of results returned for a states query - LEGACY_STATES_QUERY_SIZE: 10, - // The maximum number of monitors that should be supported - MAX_MONITORS: 35000, -}; diff --git a/x-pack/plugins/uptime/common/constants/index.ts b/x-pack/plugins/uptime/common/constants/index.ts new file mode 100644 index 0000000000000..00baa39044a55 --- /dev/null +++ b/x-pack/plugins/uptime/common/constants/index.ts @@ -0,0 +1,16 @@ +/* + * 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. + */ + +export { ACTION_GROUP_DEFINITIONS } from './alerts'; +export { CHART_FORMAT_LIMITS } from './chart_format_limits'; +export { CLIENT_DEFAULTS } from './client_defaults'; +export { CONTEXT_DEFAULTS } from './context_defaults'; +export * from './capabilities'; +export * from './settings_defaults'; +export { PLUGIN } from './plugin'; +export { QUERY } from './query'; +export * from './ui'; +export * from './rest_api'; diff --git a/x-pack/plugins/uptime/server/lib/requests/search/enrich_monitor_groups.ts b/x-pack/plugins/uptime/server/lib/requests/search/enrich_monitor_groups.ts index bcb106eef0ba6..8612d71dfe939 100644 --- a/x-pack/plugins/uptime/server/lib/requests/search/enrich_monitor_groups.ts +++ b/x-pack/plugins/uptime/server/lib/requests/search/enrich_monitor_groups.ts @@ -6,15 +6,14 @@ import { get, sortBy } from 'lodash'; import { QueryContext } from './query_context'; -import { getHistogramIntervalFormatted } from '../../helper'; -import { STATES } from '../../../../../../legacy/plugins/uptime/common/constants'; +import { QUERY } from '../../../../common/constants'; import { - MonitorSummary, - SummaryHistogram, Check, + Histogram, + MonitorSummary, CursorDirection, SortOrder, -} from '../../../../../../legacy/plugins/uptime/common/graphql/types'; +} from '../../../../common/runtime_types'; import { MonitorEnricher } from './fetch_page'; export const enrichMonitorGroups: MonitorEnricher = async ( @@ -251,11 +250,8 @@ export const enrichMonitorGroups: MonitorEnricher = async ( const summaries: MonitorSummary[] = monitorBuckets.map((monitor: any) => { const monitorId = get(monitor, 'key.monitor_id'); monitorIds.push(monitorId); - let state = get(monitor, 'state.value'); - state = { - ...state, - timestamp: state['@timestamp'], - }; + const state: any = monitor.state?.value; + state.timestamp = state['@timestamp']; const { checks } = state; if (checks) { state.checks = sortBy(checks, checksSortBy); @@ -290,7 +286,7 @@ export const enrichMonitorGroups: MonitorEnricher = async ( const getHistogramForMonitors = async ( queryContext: QueryContext, monitorIds: string[] -): Promise<{ [key: string]: SummaryHistogram }> => { +): Promise<{ [key: string]: Histogram }> => { const params = { index: queryContext.heartbeatIndices, body: { @@ -318,16 +314,13 @@ const getHistogramForMonitors = async ( by_id: { terms: { field: 'monitor.id', - size: STATES.LEGACY_STATES_QUERY_SIZE, + size: queryContext.size, }, aggs: { histogram: { - date_histogram: { + auto_date_histogram: { field: '@timestamp', - fixed_interval: getHistogramIntervalFormatted( - queryContext.dateRangeStart, - queryContext.dateRangeEnd - ), + buckets: QUERY.DEFAULT_BUCKET_COUNT, missing: 0, }, aggs: {