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] Improve duration chart #58404

Merged
merged 19 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from 18 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
4,032 changes: 0 additions & 4,032 deletions x-pack/legacy/plugins/uptime/common/graphql/introspection.json

This file was deleted.

81 changes: 1 addition & 80 deletions x-pack/legacy/plugins/uptime/common/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// Scalars
// ====================================================


export type UnsignedInteger = any;

// ====================================================
Expand All @@ -18,14 +19,6 @@ export interface Query {
/** Get a list of all recorded pings for all monitors */
allPings: PingResults;

getMonitors?: LatestMonitorsResult | null;

getSnapshot?: Snapshot | null;

getMonitorChartsData?: MonitorChart | null;
/** Fetch the most recent event data for a monitor ID, date range, location. */
getLatestMonitors: Ping[];

/** Fetches the current state of Uptime monitors for the given parameters. */
getMonitorStates?: MonitorSummaryResult | null;
/** Fetches details about the uptime index. */
Expand Down Expand Up @@ -376,32 +369,6 @@ export interface DocCount {
count: UnsignedInteger;
}

export interface LatestMonitorsResult {
monitors?: LatestMonitor[] | null;
}
/** Represents the latest recorded information about a monitor. */
export interface LatestMonitor {
/** The ID of the monitor represented by this data. */
id: MonitorKey;
/** Information from the latest document. */
ping?: Ping | null;
/** Buckets of recent up count status data. */
upSeries?: MonitorSeriesPoint[] | null;
/** Buckets of recent down count status data. */
downSeries?: MonitorSeriesPoint[] | null;
}

export interface MonitorKey {
key: string;

url?: string | null;
}

export interface MonitorSeriesPoint {
x?: UnsignedInteger | null;

y?: number | null;
}

export interface Snapshot {
counts: SnapshotCount;
Expand All @@ -416,42 +383,6 @@ export interface SnapshotCount {
}


/** The data used to populate the monitor charts. */
export interface MonitorChart {
/** The average values for the monitor duration. */
locationDurationLines: LocationDurationLine[];
/** The counts of up/down checks for the monitor. */
status: StatusData[];
/** The maximum status doc count in this chart. */
statusMaxCount: number;
/** The maximum duration value in this chart. */
durationMaxValue: number;
}

export interface LocationDurationLine {
name: string;

line: MonitorDurationAveragePoint[];
}
/** Represents the average monitor duration ms at a point in time. */
export interface MonitorDurationAveragePoint {
/** The timeseries value for this point. */
x: UnsignedInteger;
/** The average duration ms for the monitor. */
y?: number | null;
}
/** Represents a bucket of monitor status information. */
export interface StatusData {
/** The timeseries point for this status data. */
x: UnsignedInteger;
/** The value of up counts for this point. */
up?: number | null;
/** The value for down counts for this point. */
down?: number | null;
/** The total down counts for this point. */
total?: number | null;
}

/** The primary object returned for monitor states. */
export interface MonitorSummaryResult {
/** Used to go to the next page of results */
Expand Down Expand Up @@ -619,16 +550,6 @@ export interface AllPingsQueryArgs {
location?: string | null;
}

export interface GetMonitorChartsDataQueryArgs {
monitorId: string;

dateRangeStart: string;

dateRangeEnd: string;

location?: string | null;
}

export interface GetMonitorStatesQueryArgs {
dateRangeStart: string;

Expand Down
38 changes: 38 additions & 0 deletions x-pack/legacy/plugins/uptime/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,42 @@
* you may not use this file except in compliance with the Elastic License.
*/

/** Represents a bucket of monitor status information. */
export interface StatusData {
/** The timeseries point for this status data. */
x: number;
/** The value of up counts for this point. */
up?: number | null;
/** The value for down counts for this point. */
down?: number | null;
/** The total down counts for this point. */
total?: number | null;
}

/** Represents the average monitor duration ms at a point in time. */
export interface MonitorDurationAveragePoint {
/** The timeseries value for this point. */
x: number;
/** The average duration ms for the monitor. */
y?: number | null;
}

export interface LocationDurationLine {
name: string;

line: MonitorDurationAveragePoint[];
}

/** The data used to populate the monitor charts. */
export interface MonitorDurationResult {
/** The average values for the monitor duration. */
locationDurationLines: LocationDurationLine[];
/** The counts of up/down checks for the monitor. */
status: StatusData[];
/** The maximum status doc count in this chart. */
statusMaxCount: number;
/** The maximum duration value in this chart. */
durationMaxValue: number;
}

export * from './ping/histogram';
8 changes: 3 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 @@ -4,18 +4,16 @@
* you may not use this file except in compliance with the Elastic License.
*/

export type UnsignedInteger = any;

export interface HistogramDataPoint {
upCount?: number | null;

downCount?: number | null;

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

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

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

export interface GetPingHistogramParams {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.
*/

import React, { useContext, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
import { useUrlParams } from '../../../hooks';
import { getMonitorDurationAction } from '../../../state/actions';
import { DurationChartComponent } from '../../functional/charts';
import { selectDurationLines } from '../../../state/selectors';
import { UptimeRefreshContext } from '../../../contexts';

interface Props {
monitorId: string;
}

export const DurationChart: React.FC<Props> = ({ monitorId }: Props) => {
const [getUrlParams] = useUrlParams();
const { dateRangeStart, dateRangeEnd } = getUrlParams();

const { monitor_duration, loading } = useSelector(selectDurationLines);

const dispatch = useDispatch();

const { lastRefresh } = useContext(UptimeRefreshContext);

useEffect(() => {
dispatch(
getMonitorDurationAction({ monitorId, dateStart: dateRangeStart, dateEnd: dateRangeEnd })
);
}, [dateRangeStart, dateRangeEnd, dispatch, lastRefresh, monitorId]);

return (
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
<DurationChartComponent
locationDurationLines={monitor_duration?.locationDurationLines ?? []}
loading={loading}
/>
);
};
Comment on lines +19 to +41
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justinkambic using hooks redux becomes much cleaner and simple. At least the connect part.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ was just thinking that to myself. I have never used the hooks before; does this mean...

const { monitor_duration, loading } = useSelector(selectDurationLines);

...is effectively mapStateToProps? And we could use multiple selectors if needed to get the state we want, instead of doing it in a function we'd pass to connect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you can use as many selectors as you like.

Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export { MonitorStatusDetails } from './monitor/status_details_container';
export { MonitorStatusBar } from './monitor/status_bar_container';
export { MonitorListDrawer } from './monitor/list_drawer_container';
export { MonitorListActionsPopover } from './monitor/drawer_popover_container';
export { DurationChart } from './charts/monitor_duration';

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

Loading