Skip to content

Commit

Permalink
[Uptime] Remove hard coded value for monitor states histograms (elast…
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Apr 30, 2020
1 parent 28360e3 commit bf99fe6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
7 changes: 0 additions & 7 deletions x-pack/legacy/plugins/uptime/common/constants/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
16 changes: 16 additions & 0 deletions x-pack/plugins/uptime/common/constants/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -251,11 +250,8 @@ export const enrichMonitorGroups: MonitorEnricher = async (
const summaries: MonitorSummary[] = monitorBuckets.map((monitor: any) => {
const monitorId = get<string>(monitor, 'key.monitor_id');
monitorIds.push(monitorId);
let state = get<any>(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<SortChecks, Check>(checks, checksSortBy);
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit bf99fe6

Please sign in to comment.