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

[Synthetics] Fix monitor details project monitor view #143258

Merged
merged 2 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -7,6 +7,7 @@

import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { ConfigKey } from '../../../../../../common/runtime_types';
import { getMonitorRecentPingsAction, selectLatestPing, selectPingsLoading } from '../../../state';
import { useSelectedLocation } from './use_selected_location';
import { useSelectedMonitor } from './use_selected_monitor';
Expand All @@ -28,10 +29,14 @@ export const useMonitorLatestPing = (params?: UseMonitorLatestPingParams) => {
const latestPing = useSelector(selectLatestPing);
const pingsLoading = useSelector(selectPingsLoading);

const isUpToDate =
latestPing &&
latestPing.monitor.id === monitorId &&
latestPing.observer?.geo?.name === locationLabel;
const latestPingId = latestPing?.monitor.id;

const isIdSame =
Copy link
Contributor

Choose a reason for hiding this comment

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

Take into account that both latestPingId and monitorId might be undefined, and in that case this will evaluate to true.

latestPingId === monitorId || latestPingId === monitor?.[ConfigKey.CUSTOM_HEARTBEAT_ID];

const isLocationSame = latestPing?.observer?.geo?.name === locationLabel;

const isUpToDate = isIdSame && isLocationSame;

useEffect(() => {
if (monitorId && locationLabel && !isUpToDate) {
Expand All @@ -47,7 +52,7 @@ export const useMonitorLatestPing = (params?: UseMonitorLatestPingParams) => {
return { loading: pingsLoading, latestPing: null };
}

if (latestPing.monitor.id !== monitorId || latestPing.observer?.geo?.name !== locationLabel) {
if (!isIdSame || !isLocationSame) {
return { loading: pingsLoading, latestPing: null };
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { useParams } from 'react-router-dom';
import { ConfigKey } from '../../../../../../common/runtime_types';
import { useSelectedMonitor } from './use_selected_monitor';

export const useMonitorQueryId = () => {
const { monitorId } = useParams<{ monitorId: string }>();

const { monitor } = useSelectedMonitor();

if (monitor && monitor.origin === 'project') {
return monitor[ConfigKey.CUSTOM_HEARTBEAT_ID]!;
}

return monitorId;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import React from 'react';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { ReportTypes, useTheme } from '@kbn/observability-plugin/public';
import { useParams } from 'react-router-dom';
import { ClientPluginsStart } from '../../../../../plugin';
import { useMonitorQueryId } from '../hooks/use_monitor_query_id';

export const AvailabilitySparklines = () => {
const {
services: {
observability: { ExploratoryViewEmbeddable },
},
} = useKibana<ClientPluginsStart>();
const { monitorId } = useParams<{ monitorId: string }>();
const monitorId = useMonitorQueryId();

const theme = useTheme();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
import React from 'react';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { ReportTypes } from '@kbn/observability-plugin/public';
import { useParams } from 'react-router-dom';
import { ClientPluginsStart } from '../../../../../plugin';

import { KpiWrapper } from './kpi_wrapper';
import { useMonitorQueryId } from '../hooks/use_monitor_query_id';

export const DurationPanel = () => {
const {
services: {
observability: { ExploratoryViewEmbeddable },
},
} = useKibana<ClientPluginsStart>();
const { monitorId } = useParams<{ monitorId: string }>();
const monitorId = useMonitorQueryId();

return (
<KpiWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

import React from 'react';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { useParams } from 'react-router-dom';
import { ClientPluginsStart } from '../../../../../plugin';
import { useMonitorQueryId } from '../hooks/use_monitor_query_id';

export const MonitorDurationTrend = () => {
const { observability } = useKibana<ClientPluginsStart>().services;

const { ExploratoryViewEmbeddable } = observability;

const { monitorId } = useParams<{ monitorId: string }>();
const monitorId = useMonitorQueryId();

const metricsToShow = ['min', 'max', 'median', '25th', '75th'];

Expand All @@ -31,9 +31,7 @@ export const MonitorDurationTrend = () => {
},
name: metric + ' Series',
selectedMetricField: 'monitor.duration.us',
reportDefinitions: {
'monitor.id': [monitorId],
},
reportDefinitions: { 'monitor.id': [monitorId] },
seriesType: 'line',
operationType: metric,
}))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import React from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiPanel, EuiText, EuiTitle } from '@elastic/eui';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { ReportTypes } from '@kbn/observability-plugin/public';
import { useParams } from 'react-router-dom';
import { i18n } from '@kbn/i18n';

import { useMonitorQueryId } from '../hooks/use_monitor_query_id';
import { useSelectedMonitor } from '../hooks/use_selected_monitor';
import { ClientPluginsStart } from '../../../../../plugin';
export const StepDurationPanel = () => {
const { observability } = useKibana<ClientPluginsStart>().services;

const { ExploratoryViewEmbeddable } = observability;

const { monitorId } = useParams<{ monitorId: string }>();

const { monitor } = useSelectedMonitor();

const monitorId = useMonitorQueryId();

const isBrowser = monitor?.type === 'browser';

return (
Expand Down