refactor: switch Globalping to dynamic tier-based location lookup

## Changes
- Remove per-monitor location selection — locations are now determined
  globally by the tier setting in admin settings (3, 6, or 15 locations)
- GlobalpingService reads tier from settings on each check run, so
  changing the tier in settings immediately affects all HTTP/ping monitors
- Add resolveLocationId() to map Globalping probe results back to
  configured location IDs for proper grouping
- Export LOCATION_LABELS for human-readable location names on the client
- Remove unused locations field from Zod schemas and form defaults
- Remove per-monitor location ConfigBox from CreateMonitor page
- Fix settingsController.updateAppSettings missing try/catch
- Fix MongoSettingsRepository duplicate findOneAndUpdate call
- Use typed LocationCheckData instead of Record<string, any>
- Remove unused REVERSE_LOCATION_MAP from globalpingService

## Benefits
- Changing the location tier in settings takes effect immediately for
  all monitors without needing to edit each one individually
- Cleaner separation of concerns — location configuration lives in
  settings, not scattered across monitors
- Human-readable location labels shown in uptime details tabs
This commit is contained in:
gorkem-bwl committed 2026-02-19 10:58:18 -05:00
1 parent 7646d11ea0
commit 1966134647
10 files changed
+92 -113

No files matched your search

-2
View File
@@ -37,7 +37,6 @@ export const useMonitorForm = ({
matchMethod: data?.matchMethod || "",
expectedValue: data?.expectedValue || "",
jsonPath: data?.jsonPath || "",
locations: data?.locations || [],
};
break;
case "ping":
@@ -45,7 +44,6 @@ export const useMonitorForm = ({
...base,
type: "ping",
url: data?.url || "",
locations: data?.locations || [],
};
break;
case "port":
-60
View File
@@ -27,18 +27,12 @@ import {
SliderWithLabel,
Dialog,
} from "@/Components/v2/inputs";
import Chip from "@mui/material/Chip";
import { useGet, usePost, usePatch, useDelete } from "@/Hooks/UseApi";
import { useMonitorForm } from "@/Hooks/useMonitorForm";
import type { Monitor, MonitorType, GamesMap } from "@/Types/Monitor";
import type { Notification } from "@/Types/Notification";
import type { MonitorFormData } from "@/Validation/monitor";
interface GlobalpingLocation {
id: string;
label: string;
}
interface GeneralSettingsConfig {
urlLabel: string;
urlPlaceholder: string;
@@ -152,10 +146,6 @@ const CreateMonitorPage = () => {
const { data: notifications } = useGet<Notification[]>("/notifications/team");
const { data: games } = useGet<GamesMap>("/monitors/games");
const { data: globalpingLocations } = useGet<GlobalpingLocation[]>(
"/monitors/globalping/locations"
);
const { schema, defaults } = useMonitorForm({
data: existingMonitor ?? null,
defaultType,
@@ -498,56 +488,6 @@ const CreateMonitorPage = () => {
}
/>
{/* Global locations - only for http and ping types */}
{(watchedType === "http" || watchedType === "ping") && globalpingLocations && globalpingLocations.length > 0 && (
<ConfigBox
title={t("pages.createMonitor.form.locations.title")}
subtitle={t("pages.createMonitor.form.locations.description")}
rightContent={
<Controller
name="locations"
control={control}
render={({ field }) => {
const locationOptions = (globalpingLocations ?? []).map((loc) => ({
...loc,
name: loc.label,
}));
const selectedLocations = locationOptions.filter((loc) =>
(field.value ?? []).includes(loc.id)
);
return (
<Stack spacing={theme.spacing(4)}>
<Autocomplete
multiple
options={locationOptions}
value={selectedLocations}
getOptionLabel={(option) => option.name}
onChange={(_: unknown, newValue: typeof locationOptions) => {
const ids = newValue.map((loc) => loc.id);
if (ids.length <= 5) {
field.onChange(ids);
}
}}
isOptionEqualToValue={(option, value) => option.id === value.id}
renderTags={(value, getTagProps) =>
value.map((option, index) => (
<Chip
{...getTagProps({ index })}
key={option.id}
label={option.name}
size="small"
/>
))
}
/>
</Stack>
);
}}
/>
}
/>
)}
{/* Alert Thresholds - only for hardware type */}
{generalSettingsConfig.showSecret && (
<ConfigBox
+7 -1
View File
@@ -113,6 +113,12 @@ const UptimeDetailsPage = () => {
const checks = checksData?.checks ?? [];
const checksCount = checksData?.checksCount ?? 0;
const { data: globalpingData } = useGet<{
locations: { id: string; label: string }[];
labels: Record<string, string>;
}>("/monitors/globalping/locations");
const locationLabels = globalpingData?.labels ?? {};
const locationChecks = monitorData?.locationChecks;
const locationKeys = useMemo(
() => (locationChecks ? Object.keys(locationChecks).sort() : []),
@@ -182,7 +188,7 @@ const UptimeDetailsPage = () => {
{locationKeys.map((loc) => (
<Tab
key={loc}
label={loc}
label={locationLabels[loc] ?? loc}
/>
))}
</Tabs>
-2
View File
@@ -31,14 +31,12 @@ const httpSchema = baseSchema.extend({
matchMethod: z.enum(["equal", "include", "regex", ""]).optional(),
expectedValue: z.string().optional(),
jsonPath: z.string().optional(),
locations: z.array(z.string()).max(5).optional(),
});
// Ping monitor schema
const pingSchema = baseSchema.extend({
type: z.literal("ping"),
url: z.string().min(1, "Host is required"),
locations: z.array(z.string()).max(5).optional(),
});
// Port monitor schema