Skip to content

Commit

Permalink
[Uptime] Replace usage of date_histogram with aut_date_histogr… (#59577)
Browse files Browse the repository at this point in the history
* remove usage of manual date_histogram

* update

* update

* remove unused

* update fixtures

* update snaps

* remove duplicate test

* type

* update test

* update fixtures

* update interface

* updated type

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
shahzad31 and elasticmachine authored Apr 6, 2020
1 parent bdf628d commit 6a32b45
Show file tree
Hide file tree
Showing 44 changed files with 5,106 additions and 10,661 deletions.
10 changes: 5 additions & 5 deletions x-pack/legacy/plugins/uptime/common/types/ping/histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
*/

export interface HistogramDataPoint {
upCount?: number | null;
upCount?: number;

downCount?: number | null;
downCount?: number;

x?: number | null;
x?: number;

x0?: number | null;
x0?: number;

y?: number | null;
y?: number;
}

export interface GetPingHistogramParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export interface PingHistogramComponentProps {
loading?: boolean;
}

interface BarPoint {
x?: number;
y?: number;
type: string;
}

export const PingHistogramComponent: React.FC<PingHistogramComponentProps> = ({
absoluteStartDate,
absoluteEndDate,
Expand Down Expand Up @@ -65,8 +71,8 @@ export const PingHistogramComponent: React.FC<PingHistogramComponentProps> = ({
} else {
const { histogram } = data;

const downSpecId = i18n.translate('xpack.uptime.snapshotHistogram.downMonitorsId', {
defaultMessage: 'Down Monitors',
const downSpecId = i18n.translate('xpack.uptime.snapshotHistogram.series.downLabel', {
defaultMessage: 'Down',
});

const upMonitorsId = i18n.translate('xpack.uptime.snapshotHistogram.series.upLabel', {
Expand All @@ -79,6 +85,16 @@ export const PingHistogramComponent: React.FC<PingHistogramComponentProps> = ({
dateRangeEnd: moment(max).toISOString(),
});
};

const barData: BarPoint[] = [];

histogram.forEach(({ x, upCount, downCount }) => {
barData.push(
{ x, y: downCount ?? 0, type: downSpecId },
{ x, y: upCount ?? 0, type: upMonitorsId }
);
});

content = (
<ChartWrapper
height={height}
Expand Down Expand Up @@ -122,29 +138,18 @@ export const PingHistogramComponent: React.FC<PingHistogramComponentProps> = ({
/>

<BarSeries
color={danger}
data={histogram.map(({ x, downCount }) => [x, downCount || 0])}
color={[danger, gray]}
data={barData}
id={downSpecId}
name={i18n.translate('xpack.uptime.snapshotHistogram.series.downLabel', {
defaultMessage: 'Down',
name={i18n.translate('xpack.uptime.snapshotHistogram.series.pings', {
defaultMessage: 'Monitor Pings',
})}
stackAccessors={[0]}
timeZone="local"
xAccessor={0}
xScaleType="time"
yAccessors={[1]}
yScaleType="linear"
/>
<BarSeries
color={gray}
data={histogram.map(({ x, upCount }) => [x, upCount || 0])}
id={upMonitorsId}
name={upMonitorsId}
stackAccessors={[0]}
stackAccessors={['x']}
splitSeriesAccessors={['type']}
timeZone="local"
xAccessor={0}
xAccessor="x"
xScaleType="time"
yAccessors={[1]}
yAccessors={['y']}
yScaleType="linear"
/>
</Chart>
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -12589,7 +12589,6 @@
"xpack.uptime.snapshot.noDataTitle": "ヒストグラムデータがありません",
"xpack.uptime.snapshot.pingsOverTimeTitle": "一定時間のピング",
"xpack.uptime.snapshotHistogram.description": "{startTime} から {endTime} までの期間のアップタイムステータスを表示する棒グラフです。",
"xpack.uptime.snapshotHistogram.downMonitorsId": "ダウンモニター",
"xpack.uptime.snapshotHistogram.series.downLabel": "ダウン",
"xpack.uptime.snapshotHistogram.series.upLabel": "アップ",
"xpack.uptime.snapshotHistogram.xAxisId": "スナップショットX軸",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -12589,7 +12589,6 @@
"xpack.uptime.snapshot.noDataTitle": "没有可用的直方图数据",
"xpack.uptime.snapshot.pingsOverTimeTitle": "时移 Ping 数",
"xpack.uptime.snapshotHistogram.description": "显示从 {startTime} 到 {endTime} 的运行时间时移状态的条形图。",
"xpack.uptime.snapshotHistogram.downMonitorsId": "已关闭监测",
"xpack.uptime.snapshotHistogram.series.downLabel": "关闭",
"xpack.uptime.snapshotHistogram.series.upLabel": "运行",
"xpack.uptime.snapshotHistogram.xAxisId": "快照 X 轴",
Expand Down

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion x-pack/plugins/uptime/server/lib/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@

export { getFilterClause } from './get_filter_clause';
export { parseRelativeDate } from './get_histogram_interval';
export { getHistogramIntervalFormatted } from './get_histogram_interval_formatted';
export { assertCloseTo } from './assert_close_to';
export { objectValuesToArrays } from './object_to_array';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { get, set } from 'lodash';
import { set } from 'lodash';
import mockChartsData from './monitor_charts_mock.json';
import { assertCloseTo } from '../../helper';
import { getMonitorDurationChart } from '../get_monitor_duration';
import { defaultDynamicSettings } from '../../../../../../legacy/plugins/uptime/common/runtime_types';

describe('ElasticsearchMonitorsAdapter', () => {
it('getMonitorChartsData will run expected parameters when no location is specified', async () => {
expect.assertions(3);
const searchMock = jest.fn();
const search = searchMock.bind({});
await getMonitorDurationChart({
callES: search,
dynamicSettings: defaultDynamicSettings,
monitorId: 'fooID',
dateStart: 'now-15m',
dateEnd: 'now',
});
expect(searchMock).toHaveBeenCalledTimes(1);
// protect against possible rounding errors polluting the snapshot comparison
const fixedInterval = parseInt(
get(
searchMock.mock.calls[0][1],
'body.aggs.timeseries.date_histogram.fixed_interval',
''
).split('ms')[0],
10
);
expect(fixedInterval).not.toBeNaN();

/**
* The value based on the input should be ~36000
*/
assertCloseTo(fixedInterval, 36000, 100);

set(
searchMock.mock.calls[0][1],
'body.aggs.timeseries.date_histogram.fixed_interval',
'36000ms'
);
expect(searchMock.mock.calls[0]).toMatchSnapshot();
});

it('getMonitorChartsData will provide expected filters', async () => {
expect.assertions(3);
expect.assertions(2);
const searchMock = jest.fn();
const search = searchMock.bind({});
await getMonitorDurationChart({
Expand All @@ -60,20 +23,6 @@ describe('ElasticsearchMonitorsAdapter', () => {
});
expect(searchMock).toHaveBeenCalledTimes(1);
// protect against possible rounding errors polluting the snapshot comparison
const fixedInterval = parseInt(
get(
searchMock.mock.calls[0][1],
'body.aggs.timeseries.date_histogram.fixed_interval',
''
).split('ms')[0],
10
);
expect(fixedInterval).not.toBeNaN();

/**
* The value based on the input should be ~36000
*/
assertCloseTo(fixedInterval, 36000, 100);

set(
searchMock.mock.calls[0][1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { UMElasticsearchQueryFn } from '../adapters';
import { getHistogramIntervalFormatted } from '../helper';
import { QUERY } from '../../../../../legacy/plugins/uptime/common/constants';
import {
LocationDurationLine,
MonitorDurationResult,
Expand Down Expand Up @@ -62,10 +62,9 @@ export const getMonitorDurationChart: UMElasticsearchQueryFn<
size: 0,
aggs: {
timeseries: {
date_histogram: {
auto_date_histogram: {
field: '@timestamp',
fixed_interval: getHistogramIntervalFormatted(dateStart, dateEnd),
min_doc_count: 0,
buckets: QUERY.DEFAULT_BUCKET_COUNT,
},
aggs: {
location: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

import { get, sortBy } from 'lodash';
import { QueryContext } from './query_context';
import { getHistogramIntervalFormatted } from '../../helper';
import { STATES } from '../../../../../../legacy/plugins/uptime/common/constants';
import { QUERY, STATES } from '../../../../../../legacy/plugins/uptime/common/constants';
import {
MonitorSummary,
SummaryHistogram,
Expand Down Expand Up @@ -322,12 +321,9 @@ const getHistogramForMonitors = async (
},
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
Loading

0 comments on commit 6a32b45

Please sign in to comment.