Skip to content

Commit

Permalink
synthetics - standardize monitor overview queries
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiqueclarke committed Nov 21, 2022
1 parent 80af40e commit 553690b
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ export type MonitorManagementListResult = t.TypeOf<typeof MonitorManagementListR
export const MonitorOverviewItemCodec = t.interface({
name: t.string,
id: t.string,
configId: t.string,
location: MonitorServiceLocationCodec,
isEnabled: t.boolean,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import { syntheticsEditMonitorLocatorID } from '@kbn/observability-plugin/common';

async function navigate({ monitorId }: { monitorId: string }) {
async function navigate({ configId }: { configId: string }) {
return {
app: 'synthetics',
path: `/edit-monitor/${monitorId}`,
path: `/edit-monitor/${configId}`,
state: {},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import { syntheticsMonitorDetailLocatorID } from '@kbn/observability-plugin/common';

async function navigate({ monitorId, locationId }: { monitorId: string; locationId?: string }) {
async function navigate({ configId, locationId }: { configId: string; locationId?: string }) {
const locationUrlQueryParam = locationId ? `?locationId=${locationId}` : '';
return {
app: 'synthetics',
path: `/monitor/${monitorId}${locationUrlQueryParam}`,
path: `/monitor/${configId}${locationUrlQueryParam}`,
state: {},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useEffect, useState } from 'react';
import { syntheticsEditMonitorLocatorID } from '@kbn/observability-plugin/common';
import { useSyntheticsStartPlugins } from '../../../contexts';

export function useEditMonitorLocator({ monitorId }: { monitorId: string }) {
export function useEditMonitorLocator({ configId }: { configId: string }) {
const [editUrl, setEditUrl] = useState<string | undefined>(undefined);
const locator = useSyntheticsStartPlugins()?.share?.url.locators.get(
syntheticsEditMonitorLocatorID
Expand All @@ -19,12 +19,12 @@ export function useEditMonitorLocator({ monitorId }: { monitorId: string }) {
useEffect(() => {
async function generateUrl() {
const url = await locator?.getUrl({
monitorId,
configId,
});
setEditUrl(url);
}
generateUrl();
}, [locator, monitorId]);
}, [locator, configId]);

return editUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { syntheticsMonitorDetailLocatorID } from '@kbn/observability-plugin/comm
import { useSyntheticsStartPlugins } from '../../../contexts';

export function useMonitorDetailLocator({
monitorId,
configId,
locationId,
}: {
monitorId: string;
configId: string;
locationId?: string;
}) {
const [monitorUrl, setMonitorUrl] = useState<string | undefined>(undefined);
Expand All @@ -24,13 +24,13 @@ export function useMonitorDetailLocator({
useEffect(() => {
async function generateUrl() {
const url = await locator?.getUrl({
monitorId,
configId,
locationId,
});
setMonitorUrl(url);
}
generateUrl();
}, [locator, monitorId, locationId]);
}, [locator, configId, locationId]);

return monitorUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ export function ActionsPopover({
const locationName = useLocationName({ locationId: monitor.location.id });

const detailUrl = useMonitorDetailLocator({
monitorId: monitor.id,
configId: monitor.configId,
locationId: monitor.location.id,
});
const editUrl = useEditMonitorLocator({ monitorId: monitor.id });
const editUrl = useEditMonitorLocator({ configId: monitor.configId });

const labels = useMemo(
() => ({
Expand All @@ -101,7 +101,7 @@ export function ActionsPopover({
[monitor.name]
);
const { status, isEnabled, updateMonitorEnabledState } = useMonitorEnableHandler({
id: monitor.id,
id: monitor.configId,
isEnabled: monitor.isEnabled,
labels,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ export const MetricItem = ({
>
<Chart>
<Settings
onElementClick={() => monitor.id && locationName && onClick(monitor.id, locationName)}
onElementClick={() =>
monitor.configId && locationName && onClick(monitor.configId, locationName)
}
baseTheme={DARK_THEME}
/>
<Metric
id={`${monitor.id}-${monitor.location?.id}`}
id={`${monitor.configId}-${monitor.location?.id}`}
data={[
[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ export const getAllSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () =>

const countResult = isMonitorsQueryFiltered(request.query)
? await savedObjectsClient.find({
type: syntheticsMonitorType,
perPage: 0,
page: 1,
})
type: syntheticsMonitorType,
perPage: 0,
page: 1,
})
: queryResult;

const { saved_objects: monitors, per_page: perPageT, ...rest } = queryResult;
Expand Down Expand Up @@ -104,14 +104,16 @@ export const getSyntheticsMonitorOverviewRoute: SyntheticsRestApiRouteFactory =
/* collect all monitor ids for use
* in filtering overview requests */
result.saved_objects.forEach((monitor) => {
const id = monitor.id;
allMonitorIds.push(id);
const id = monitor.attributes[ConfigKey.MONITOR_QUERY_ID];
const configId = monitor.attributes[ConfigKey.CONFIG_ID];
allMonitorIds.push(configId);

/* for reach location, add a config item */
const locations = monitor.attributes[ConfigKey.LOCATIONS];
locations.forEach((location) => {
const config = {
id,
configId,
name: monitor.attributes[ConfigKey.NAME],
location,
isEnabled: monitor.attributes[ConfigKey.ENABLED],
Expand Down

0 comments on commit 553690b

Please sign in to comment.