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] Update relative time handling #55693

Merged
merged 16 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export const getSupportedUrlParams = (params: {
),
absoluteDateRangeEnd: parseAbsoluteDate(
dateRangeEnd || DATE_RANGE_END,
ABSOLUTE_DATE_RANGE_END
ABSOLUTE_DATE_RANGE_END,
{ roundUp: true }
),
autorefreshInterval: parseUrlInt(autorefreshInterval, AUTOREFRESH_INTERVAL),
autorefreshIsPaused: parseIsPaused(autorefreshIsPaused, AUTOREFRESH_IS_PAUSED),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import DateMath from '@elastic/datemath';

export const parseAbsoluteDate = (date: string, defaultValue: number): number => {
const momentWrapper = DateMath.parse(date);
export const parseAbsoluteDate = (date: string, defaultValue: number, options = {}): number => {
const momentWrapper = DateMath.parse(date, options);
if (momentWrapper) {
return momentWrapper.valueOf();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const findPotentialMatches = async (
size: number
) => {
const queryResult = await query(queryContext, searchAfter, size);

const checkGroups = new Set<string>();
const monitorIds: string[] = [];
get<any>(queryResult, 'aggregations.monitors.buckets', []).forEach((b: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import { APICaller } from 'kibana/server';
import { CursorPagination } from '../adapter_types';
import { INDEX_NAMES } from '../../../../../common/constants';

const parseRelativeDates = (startDate: string, _endDate: string): { tsStart: any; tsEnd: any } => {
let endDate: string = _endDate ?? '';
if (startDate === endDate && endDate.includes('now')) {
endDate = 'now';
}

const tsStart = DateMath.parse(endDate)?.subtract(10, 'seconds');
const tsEnd = DateMath.parse(endDate);

return { tsStart, tsEnd };
};

export class QueryContext {
callES: APICaller;
dateRangeStart: string;
Expand Down Expand Up @@ -95,8 +107,8 @@ export class QueryContext {
// latencies and slowdowns that's dangerous. Making this value larger makes things
// only slower, but only marginally so, and prevents people from seeing weird
// behavior.
const tsStart = DateMath.parse(this.dateRangeEnd)!.subtract(5, 'minutes');
const tsEnd = DateMath.parse(this.dateRangeEnd)!;

const { tsStart, tsEnd } = parseRelativeDates(this.dateRangeStart, this.dateRangeEnd);

return {
range: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ export const getHistogramInterval = (
dateRangeEnd: string,
bucketCount?: number
): number => {
let endDate = dateRangeEnd;
if (dateRangeStart === dateRangeEnd && endDate.includes('now')) {
endDate = 'now';
}

const from = DateMath.parse(dateRangeStart);
const to = DateMath.parse(dateRangeEnd);
const to = DateMath.parse(endDate);
if (from === undefined) {
throw Error('Invalid dateRangeStart value');
}
Expand Down