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] Standardize the uses of MONITOR_QUERY_ID and CONFIG_ID throughout the app #144176

Merged
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
43cce31
synthetics - add monitor id migration
dominiqueclarke Oct 24, 2022
9bf96f9
add id to all monitors
dominiqueclarke Oct 24, 2022
508278a
add config id to migration
dominiqueclarke Oct 24, 2022
06a0434
adjust import
dominiqueclarke Oct 24, 2022
56c8e44
update tests
dominiqueclarke Oct 25, 2022
71c47a6
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Oct 25, 2022
1e3fba1
update tests
dominiqueclarke Oct 26, 2022
26d8a92
Merge branch 'feature/synthetics-monitor-id-migration' of https://git…
dominiqueclarke Oct 26, 2022
2f72667
adjust types
dominiqueclarke Oct 26, 2022
fd4bd4e
Merge branch 'main' into feature/synthetics-monitor-id-migration
kibanamachine Oct 26, 2022
4757a83
rename id key
dominiqueclarke Oct 27, 2022
f58fb0a
Merge branch 'feature/synthetics-monitor-id-migration' of https://git…
dominiqueclarke Oct 27, 2022
558e7fc
rename id key
dominiqueclarke Oct 27, 2022
2c14464
adjust types and tests
dominiqueclarke Oct 28, 2022
1e3acaa
adjust test
dominiqueclarke Oct 28, 2022
cef4828
Merge branch 'main' of github.com:elastic/kibana into feature/synthet…
dominiqueclarke Oct 28, 2022
15414c5
synthetics - update references to CUSTOM_HEARTBEAT_ID to prefer HEART…
dominiqueclarke Oct 28, 2022
1f37768
update formatHeartbeatRequest
dominiqueclarke Oct 28, 2022
93681bf
update legacy uptime monitor details saved object query
dominiqueclarke Oct 28, 2022
887f0c0
update jest test
dominiqueclarke Oct 28, 2022
ea01bb8
adjust tests
dominiqueclarke Oct 28, 2022
53c1d9e
adjust tests
dominiqueclarke Oct 28, 2022
6ba17df
update selectors and hooks
dominiqueclarke Oct 28, 2022
64c9fe6
Merge branch 'main' of github.com:elastic/kibana into feature/synthet…
dominiqueclarke Oct 31, 2022
d7a5fa9
rename HEARTBEAT_ID to MONITOR_QUERY_ID
dominiqueclarke Nov 1, 2022
9e62978
update flaky test
dominiqueclarke Nov 3, 2022
8c790db
merge upstream
dominiqueclarke Nov 3, 2022
7a642d5
merge migration upstream
dominiqueclarke Nov 3, 2022
628463f
Merge branch 'main' of github.com:elastic/kibana into feature/synthet…
dominiqueclarke Nov 3, 2022
b81bd78
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Nov 3, 2022
739b1f6
adjust id uses
dominiqueclarke Nov 3, 2022
734e519
Merge branch 'feature/synthetics-monitor-id-hook' of https://github.c…
dominiqueclarke Nov 3, 2022
1fc1bd0
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Nov 3, 2022
bc09dc7
update monitor list tests
dominiqueclarke Nov 8, 2022
7571acd
adjust inline error tests
dominiqueclarke Nov 8, 2022
b5fa7c7
adjusts edit monitor api tests
dominiqueclarke Nov 8, 2022
36bed4a
Merge branch 'feature/synthetics-monitor-id-hook' of https://github.c…
dominiqueclarke Nov 8, 2022
88d6ec0
merge upstream
dominiqueclarke Nov 8, 2022
d2ad438
adjust query ids
dominiqueclarke Nov 8, 2022
3b5727c
adjust types
dominiqueclarke Nov 8, 2022
4e5e0de
Merge branch 'main' of github.com:elastic/kibana into feature/synthet…
shahzad31 Nov 10, 2022
df6fd23
resolve conflicts
shahzad31 Nov 10, 2022
30823eb
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Nov 10, 2022
2a91b3a
Merge branch 'main' into feature/synthetics-monitor-id-hook
shahzad31 Nov 14, 2022
1d4cac2
update types
shahzad31 Nov 14, 2022
6916334
Merge branch 'main' of github.com:elastic/kibana into feature/synthet…
shahzad31 Nov 14, 2022
af94c32
Merge branch 'main' into feature/synthetics-monitor-id-hook
dominiqueclarke Nov 14, 2022
da8bf96
Merge branch 'main' into feature/synthetics-monitor-id-hook
shahzad31 Nov 15, 2022
9d6c1ac
Update x-pack/plugins/synthetics/public/apps/synthetics/components/mo…
shahzad31 Nov 15, 2022
d4da6f8
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Nov 15, 2022
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 @@ -5,18 +5,11 @@
* 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;
return monitor?.[ConfigKey.MONITOR_QUERY_ID];
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { useEffect, useCallback, useRef } from 'react';
import { useSelector, useDispatch } from 'react-redux';

import { PingStatus } from '../../../../../../common/runtime_types';
import { ConfigKey, PingStatus } from '../../../../../../common/runtime_types';
import {
getMonitorPingStatusesAction,
selectIsMonitorStatusesLoading,
Expand All @@ -35,8 +35,11 @@ export const usePingStatuses = ({
const location = useSelectedLocation();

const pingStatusesSelector = useCallback(() => {
return selectPingStatusesForMonitorAndLocationAsc(monitor?.id ?? '', location?.label ?? '');
}, [monitor?.id, location?.label]);
return selectPingStatusesForMonitorAndLocationAsc(
monitor?.[ConfigKey.CONFIG_ID] ?? '',
location?.label ?? ''
);
}, [monitor, location?.label]);
const isLoading = useSelector(selectIsMonitorStatusesLoading);
const pingStatuses = useSelector(pingStatusesSelector()) as PingStatus[];
const dispatch = useDispatch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { useEffect, useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useParams } from 'react-router-dom';
import { ConfigKey } from '../../../../../../common/runtime_types';
import {
getMonitorAction,
selectEncryptedSyntheticsSavedMonitors,
Expand All @@ -20,16 +21,16 @@ export const useSelectedMonitor = () => {
const monitorsList = useSelector(selectEncryptedSyntheticsSavedMonitors);
const { loading: monitorListLoading } = useSelector(selectMonitorListState);
const monitorFromList = useMemo(
() => monitorsList.find((monitor) => monitor.id === monitorId) ?? null,
() => monitorsList.find((monitor) => monitor[ConfigKey.CONFIG_ID] === monitorId) ?? null,
[monitorId, monitorsList]
);

const { syntheticsMonitor, syntheticsMonitorLoading } = useSelector(selectorMonitorDetailsState);
const dispatch = useDispatch();

const isMonitorFromListValid = monitorId && monitorFromList && monitorFromList?.id === monitorId;
const isMonitorFromListValid =
monitorId && monitorFromList && monitorFromList[ConfigKey.CONFIG_ID] === monitorId;
const isLoadedSyntheticsMonitorValid =
monitorId && syntheticsMonitor && syntheticsMonitor?.id === monitorId;
monitorId && syntheticsMonitor && syntheticsMonitor[ConfigKey.CONFIG_ID] === monitorId;
const availableMonitor = isLoadedSyntheticsMonitorValid
? syntheticsMonitor
: isMonitorFromListValid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@

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

export const MonitorFailedTests = ({ time }: { time: { to: string; from: string } }) => {
const { observability } = useKibana<ClientPluginsStart>().services;

const { ExploratoryViewEmbeddable } = observability;

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

if (!monitorId) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

May be a loading here? or maybe monitorId should be passed from parent component and there we can a central loading.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What loader do you think we should have, since most of these are exploratory view visualizations.

}

return (
<ExploratoryViewEmbeddable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export const FailedTestsCount = (time: { to: string; from: string }) => {

const monitorId = useMonitorQueryId();

if (!monitorId) {
return null;
}

return (
<ExploratoryViewEmbeddable
reportType="single-metric"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const MonitorErrors = () => {
<EuiSpacer />
<EuiFlexGroup>
<EuiFlexItem grow={1}>
<EuiPanel>
<EuiPanel hasBorder>
<EuiTitle size="xs">
<h3 css={{ margin: euiTheme.size.s, marginBottom: 0 }}>{OVERVIEW_LABEL}</h3>
</EuiTitle>
Expand All @@ -52,7 +52,7 @@ export const MonitorErrors = () => {
</EuiPanel>
</EuiFlexItem>
<EuiFlexItem grow={3}>
<EuiPanel>
<EuiPanel hasBorder>
<EuiTitle size="xs">
<h3 css={{ margin: euiTheme.size.s, marginBottom: 0 }}>{FAILED_TESTS_LABEL}</h3>
</EuiTitle>
Expand All @@ -62,15 +62,15 @@ export const MonitorErrors = () => {
</EuiFlexGroup>
<EuiFlexGroup>
<EuiFlexItem grow={2}>
<EuiPanel>
<EuiPanel hasBorder>
<EuiTitle size="xs">
<h3 css={{ margin: euiTheme.size.s, marginBottom: 0 }}>{ERRORS_LABEL}</h3>
</EuiTitle>
<ErrorsList />
</EuiPanel>
</EuiFlexItem>
<EuiFlexItem grow={1}>
<EuiPanel>
<EuiPanel hasBorder>
<EuiTitle size="xs">
<h3 css={{ margin: euiTheme.size.s, marginBottom: 0 }}>
{FAILED_TESTS_BY_STEPS_LABEL}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { css } from '@emotion/css';
import { useHistory } from 'react-router-dom';

import { ConfigKey } from '../../../../../../common/runtime_types';
import { MONITOR_HISTORY_ROUTE } from '../../../../../../common/constants';
import { stringifyUrlParams } from '../../../utils/url_params';
import { useGetUrlParams } from '../../../hooks';
Expand Down Expand Up @@ -69,9 +70,12 @@ export const MonitorStatusHeader = ({
<EuiFlexItem grow={false}>
<EuiLink
href={
monitor?.id
monitor?.[ConfigKey.CONFIG_ID]
? history.createHref({
pathname: MONITOR_HISTORY_ROUTE.replace(':monitorId', monitor?.id),
pathname: MONITOR_HISTORY_ROUTE.replace(
':monitorId',
monitor[ConfigKey.CONFIG_ID]
),
search: stringifyUrlParams(
{ ...params, dateRangeStart: 'now-24h', dateRangeEnd: 'now' },
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export const AvailabilityPanel = (props: AvailabilityPanelprops) => {

const monitorId = useMonitorQueryId();

if (!monitorId) {
return null;
}

return (
<ExploratoryViewEmbeddable
customHeight="70px"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const AvailabilitySparklines = (props: AvailabilitySparklinesProps) => {

const theme = useTheme();

if (!monitorId) {
return null;
}

return (
<ExploratoryViewEmbeddable
customHeight="70px"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export const DurationPanel = (props: DurationPanelProps) => {
} = useKibana<ClientPluginsStart>();
const monitorId = useMonitorQueryId();

if (!monitorId) {
return null;
}

return (
<ExploratoryViewEmbeddable
customHeight="70px"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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 { useMonitorQueryId } from '../hooks/use_monitor_query_id';
import { ClientPluginsStart } from '../../../../../plugin';

interface DurationSparklinesProps {
Expand All @@ -22,10 +22,13 @@ export const DurationSparklines = (props: DurationSparklinesProps) => {
observability: { ExploratoryViewEmbeddable },
},
} = useKibana<ClientPluginsStart>();
const { monitorId } = useParams<{ monitorId: string }>();

const monitorId = useMonitorQueryId();
const theme = useTheme();

if (!monitorId) {
return null;
}

return (
<>
<ExploratoryViewEmbeddable
Expand All @@ -40,7 +43,7 @@ export const DurationSparklines = (props: DurationSparklinesProps) => {
name: 'Monitor duration',
dataType: 'synthetics',
selectedMetricField: 'monitor.duration.us',
reportDefinitions: { config_id: [monitorId] },
reportDefinitions: { 'monitor.id': [monitorId] },
color: theme.eui.euiColorVis1,
},
]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export const MonitorDurationTrend = (props: MonitorDurationTrendProps) => {

const metricsToShow = ['min', 'max', 'median', '25th', '75th'];
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved

if (!monitorId) {
return null;
}

return (
<ExploratoryViewEmbeddable
customHeight="240px"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const MonitorDetailsPanel = () => {

if (
(latestPing && latestPing?.config_id !== monitorId) ||
(monitor && monitor.id !== monitorId)
(monitor && monitor[ConfigKey.CONFIG_ID] !== monitorId)
) {
return <EuiLoadingContent lines={6} />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export const MonitorErrorsCount = (props: MonitorErrorsCountProps) => {

const monitorId = useMonitorQueryId();

if (!monitorId) {
return null;
}

return (
<ExploratoryViewEmbeddable
customHeight="70px"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export const StepDurationPanel = () => {

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

if (!monitorId) {
return null;
}

return (
<EuiPanel hasShadow={false} hasBorder>
<EuiFlexGroup alignItems="center" gutterSize="s">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function useInlineErrors({
filter: getInlineErrorFilters(),
},
},
collapse: { field: 'config_id' },
collapse: { field: 'monitor.id' },
sort: sortFieldMap[sortField] ? [{ [sortFieldMap[sortField]]: sortOrder }] : undefined,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function useInlineErrorsCount() {
},
aggs: {
total: {
cardinality: { field: 'config_id' },
cardinality: { field: 'monitor.id' },
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export const MonitorDetailsLink = ({
const locationId =
lastSelectedLocationId && monitorHasLocation ? lastSelectedLocationId : firstMonitorLocationId;

const monitorDetailLinkUrl = useMonitorDetailLocator({ monitorId: monitor.id, locationId });
const monitorDetailLinkUrl = useMonitorDetailLocator({
monitorId: monitor[ConfigKey.CONFIG_ID],
locationId,
});

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function useLastXChecks<Fields>({
EXCLUDE_RUN_ONCE_FILTER,
{
term: {
config_id: monitorId,
'monitor.id': monitorId,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export const fetchSyntheticsMonitor = async ({

return {
...savedObject.attributes,
id: savedObject.id,
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was removed in favor of MONITOR_QUERY_ID, which is on the attributes. Now, there's no longer an id field on the front end that is the monitor saved object id. Instead, we rely on CONFIG_ID for that value.

updated_at: savedObject.updated_at,
} as EncryptedSyntheticsSavedMonitor;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { createSelector } from 'reselect';

import { EncryptedSyntheticsSavedMonitor } from '../../../../../common/runtime_types';
import { ConfigKey, EncryptedSyntheticsSavedMonitor } from '../../../../../common/runtime_types';
import { SyntheticsAppState } from '../root_reducer';

export const selectMonitorListState = (state: SyntheticsAppState) => state.monitorList;
Expand All @@ -16,7 +16,7 @@ export const selectEncryptedSyntheticsSavedMonitors = createSelector(
(state) =>
state.data.monitors.map((monitor) => ({
...monitor.attributes,
id: monitor.id,
id: monitor.attributes[ConfigKey.MONITOR_QUERY_ID],
updated_at: monitor.updated_at,
})) as EncryptedSyntheticsSavedMonitor[]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('useInlineErrors', function () {
3,
{
body: {
collapse: { field: 'config_id' },
collapse: { field: 'monitor.id' },
query: {
bool: {
filter: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function useInlineErrors({
filter: getInlineErrorFilters(),
},
},
collapse: { field: 'config_id' },
collapse: { field: 'monitor.id' },
sort: [{ [sortFieldMap[sortField]]: sortOrder }],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('useInlineErrorsCount', function () {
2,
{
body: {
aggs: { total: { cardinality: { field: 'config_id' } } },
aggs: { total: { cardinality: { field: 'monitor.id' } } },
query: {
bool: {
filter: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function useInlineErrorsCount() {
},
aggs: {
total: {
cardinality: { field: 'config_id' },
cardinality: { field: 'monitor.id' },
},
},
},
Expand Down
Loading