Skip to content

Commit af38192

Browse files
[Synthetics] Fixed monitor history histogram and group by location issue (elastic#218550)
This PR closes elastic#217105 and closes elastic#217118 https://github.com/user-attachments/assets/4426c5bc-dfda-483c-a974-3a3d6832d6c7 --------- Co-authored-by: Dominique Clarke <dominique.clarke@elastic.co>
1 parent f8354b0 commit af38192

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

x-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_status/use_monitor_status_data.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,23 @@ export const useMonitorStatusData = ({ from, to, initialSizeRef }: Props) => {
5353
const dispatch = useDispatch();
5454
const { heatmap: dateHistogram, loading } = useSelector(selectHeatmap);
5555

56+
const getBinsNo = useCallback(
57+
(maxNoOfBins: number) => {
58+
// Each bin represents a time interval of at least 1 minute. If the available width allows for more bins
59+
// than there are minutes in the time range, we cap the number of bins to match the number of minutes
60+
// to ensure each bin represents a meaningful time interval.
61+
return Math.min(maxNoOfBins, totalMinutes);
62+
},
63+
[totalMinutes]
64+
);
65+
5666
useEffect(() => {
5767
if (binsAvailableByWidth === null && initialSizeRef?.current) {
58-
setBinsAvailableByWidth(Math.floor(initialSizeRef?.current?.clientWidth / CHART_CELL_WIDTH));
68+
setBinsAvailableByWidth(
69+
getBinsNo(Math.floor(initialSizeRef?.current?.clientWidth / CHART_CELL_WIDTH))
70+
);
5971
}
60-
}, [binsAvailableByWidth, initialSizeRef]);
72+
}, [binsAvailableByWidth, initialSizeRef, getBinsNo]);
6173

6274
useEffect(() => {
6375
if (monitor?.id && location?.label && debouncedBinsCount !== null && !!minsPerBin) {
@@ -88,8 +100,8 @@ export const useMonitorStatusData = ({ from, to, initialSizeRef }: Props) => {
88100

89101
const handleResize = useCallback(
90102
(e: { width: number; height: number }) =>
91-
setBinsAvailableByWidth(Math.floor(e.width / CHART_CELL_WIDTH)),
92-
[]
103+
setBinsAvailableByWidth(getBinsNo(Math.floor(e.width / CHART_CELL_WIDTH))),
104+
[getBinsNo]
93105
);
94106

95107
useDebounce(

x-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/grid_by_group/grid_items_by_group.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export const GridItemsByGroup = ({
5050
values: getSyntheticsFilterDisplayValues(locations, 'locations', allLocations),
5151
otherValues: {
5252
label: 'Without any location',
53-
items: allConfigs?.filter((monitor) => get(monitor, 'locations', []).length === 0),
53+
// All monitors should have a locationId. This array tracks monitors that are missing it, which helps identify potential issues
54+
items: allConfigs?.filter((monitor) => !get(monitor, 'locationId')),
5455
},
5556
};
5657

@@ -80,7 +81,8 @@ export const GridItemsByGroup = ({
8081
defaultMessage: 'Without any location',
8182
}
8283
),
83-
items: allConfigs?.filter((monitor) => !get(monitor, 'location')),
84+
// All monitors should have a locationId. This array tracks monitors that are missing it, which helps identify potential issues
85+
items: allConfigs?.filter((monitor) => !get(monitor, 'locationId')),
8486
},
8587
};
8688
break;

0 commit comments

Comments
 (0)