From 27c3a9e12b5797fb3b43c749b50cc9fb2720b96c Mon Sep 17 00:00:00 2001 From: gorkem-bwl Date: Thu, 19 Feb 2026 10:31:15 -0500 Subject: [PATCH] feat: add location tier presets (3, 6, 15) to Globalping settings ## Changes ### Server - Expand LOCATION_MAP to support city/country-level locations for the 15-location tier (US East/West, Toronto, London, Frankfurt, Amsterdam, Warsaw, Tokyo, Singapore, Mumbai, Sydney, Brazil, Santiago, Johannesburg, Dubai) - Add globalpingLocationsTier field to Settings type, Mongoose model, repository mapper, and Joi validation (valid: 3, 6, 15, default: 6) - Update getGlobalpingLocations endpoint to return locations based on the configured tier from settings - Pass settingsService to MonitorController for tier lookup ### Client - Add tier selector (radio buttons) to SettingsGlobalping component with descriptions for each option: - 3 locations: North America, Europe, Asia - 6 locations: all continents - 15 locations: city-level global coverage - Add rate limits info box explaining credit usage per tier: - Without token: 250 tests/hour - With free token: 500 tests/hour - GitHub sponsors: higher limits - Add all translation keys for tier labels, descriptions, and rate info ## Benefits - Admins can choose the right balance of coverage vs API usage - Rate limit info helps users decide whether they need authentication --- client/src/Hooks/useSettingsForm.ts | 1 + .../src/Pages/Settings/SettingsGlobalping.jsx | 108 +++++++++++++++++- client/src/Types/Settings.ts | 1 + client/src/Validation/settings.ts | 1 + client/src/locales/en.json | 19 ++- server/src/config/controllers.ts | 2 +- server/src/controllers/monitorController.ts | 12 +- server/src/db/models/AppSettings.ts | 1 + .../settings/MongoSettingsRepository.ts | 1 + .../infrastructure/globalpingService.ts | 64 ++++++++++- server/src/types/settings.ts | 1 + server/src/validation/joi.ts | 1 + 12 files changed, 202 insertions(+), 10 deletions(-) diff --git a/client/src/Hooks/useSettingsForm.ts b/client/src/Hooks/useSettingsForm.ts index 653c593da..2e932e798 100644 --- a/client/src/Hooks/useSettingsForm.ts +++ b/client/src/Hooks/useSettingsForm.ts @@ -30,6 +30,7 @@ export const useSettingsForm = ({ data = null }: UseSettingsFormOptions = {}) => checkTTL: data?.checkTTL ?? 30, pagespeedApiKey: "", globalpingApiKey: "", + globalpingLocationsTier: data?.globalpingLocationsTier ?? 6, systemEmailPassword: "", }; diff --git a/client/src/Pages/Settings/SettingsGlobalping.jsx b/client/src/Pages/Settings/SettingsGlobalping.jsx index 24e607c6b..3384eab7d 100644 --- a/client/src/Pages/Settings/SettingsGlobalping.jsx +++ b/client/src/Pages/Settings/SettingsGlobalping.jsx @@ -2,12 +2,14 @@ import Box from "@mui/material/Box"; import Stack from "@mui/material/Stack"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; +import RadioGroup from "@mui/material/RadioGroup"; +import FormControlLabel from "@mui/material/FormControlLabel"; +import Radio from "@mui/material/Radio"; import ConfigBox from "@/Components/v1/ConfigBox/index.jsx"; import TextInput from "@/Components/v1/Inputs/TextInput/index.jsx"; import { PasswordEndAdornment } from "@/Components/v1/Inputs/TextInput/Adornments/index.jsx"; import { useTheme } from "@emotion/react"; import { PropTypes } from "prop-types"; -import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Controller } from "react-hook-form"; @@ -52,7 +54,7 @@ const SettingsGlobalping = ({ {...field} label={t("pages.settings.globalpingSettings.labelApiKey")} type={"password"} - optionalLabel="(Optional)" + optionalLabel={t("pages.settings.globalpingSettings.optionalLabel")} endAdornment={} error={!!fieldState.error} helperText={fieldState.error?.message} @@ -79,6 +81,108 @@ const SettingsGlobalping = ({ )} + + + + {t("pages.settings.globalpingSettings.locationsTierTitle")} + + + {t("pages.settings.globalpingSettings.locationsTierDescription")} + + ( + field.onChange(Number(e.target.value))} + > + } + label={ + + + {t("pages.settings.globalpingSettings.tier3Label")} + + + {t("pages.settings.globalpingSettings.tier3Description")} + + + } + sx={{ mb: theme.spacing(4), alignItems: "flex-start" }} + /> + } + label={ + + + {t("pages.settings.globalpingSettings.tier6Label")} + + + {t("pages.settings.globalpingSettings.tier6Description")} + + + } + sx={{ mb: theme.spacing(4), alignItems: "flex-start" }} + /> + } + label={ + + + {t("pages.settings.globalpingSettings.tier15Label")} + + + {t("pages.settings.globalpingSettings.tier15Description")} + + + } + sx={{ alignItems: "flex-start" }} + /> + + )} + /> + + + + + {t("pages.settings.globalpingSettings.rateLimitsTitle")} + + + {t("pages.settings.globalpingSettings.rateLimitsDescription")} + + + + {t("pages.settings.globalpingSettings.rateLimitNoAuth")} + + + {t("pages.settings.globalpingSettings.rateLimitAuth")} + + + {t("pages.settings.globalpingSettings.rateLimitSponsor")} + + + + {t("pages.settings.globalpingSettings.rateLimitsNote")} + + ); diff --git a/client/src/Types/Settings.ts b/client/src/Types/Settings.ts index 36f30180d..14a833e53 100644 --- a/client/src/Types/Settings.ts +++ b/client/src/Types/Settings.ts @@ -21,6 +21,7 @@ export interface Settings { systemEmailRequireTLS: boolean; systemEmailRejectUnauthorized: boolean; showURL: boolean; + globalpingLocationsTier?: number; singleton: boolean; globalThresholds?: SettingsThresholds; createdAt: string; diff --git a/client/src/Validation/settings.ts b/client/src/Validation/settings.ts index f4c2d1a43..ac0c16434 100644 --- a/client/src/Validation/settings.ts +++ b/client/src/Validation/settings.ts @@ -35,6 +35,7 @@ export const settingsSchema = z.object({ .max(365, "Maximum 365 days"), pagespeedApiKey: optionalString(), globalpingApiKey: optionalString(), + globalpingLocationsTier: z.coerce.number().optional(), systemEmailHost: z.preprocess( (val) => val === "" || val === null || val === undefined ? undefined : String(val).trim(), diff --git a/client/src/locales/en.json b/client/src/locales/en.json index f0c19b737..ece0ba5c5 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -957,10 +957,25 @@ "title": "Google PageSpeed API key" }, "globalpingSettings": { - "description": "Enter your Globalping API key to enable multi-location uptime monitoring. This allows checking your monitors from different geographic regions.", + "description": "Configure Globalping to run uptime checks from multiple geographic regions worldwide.", "labelApiKeySet": "API key is set. Click Reset to change it.", "labelApiKey": "Globalping API key", - "title": "Globalping API key" + "optionalLabel": "(Optional)", + "title": "Globalping", + "locationsTierTitle": "Global locations", + "locationsTierDescription": "Choose how many probe locations are available when creating monitors.", + "tier3Label": "3 locations — core regions", + "tier3Description": "North America, Europe, Asia", + "tier6Label": "6 locations — all continents", + "tier6Description": "North America, Europe, Asia, South America, Oceania, Africa", + "tier15Label": "15 locations — city level", + "tier15Description": "US East, US West, Canada, UK, Germany, Netherlands, Poland, Japan, Singapore, India, Australia, Brazil, Chile, South Africa, UAE", + "rateLimitsTitle": "Rate limits", + "rateLimitsDescription": "Globalping limits how many tests you can run per hour. Each location check on each monitor uses 1 credit per interval.", + "rateLimitNoAuth": "Without a token: 250 tests per hour (no authentication needed)", + "rateLimitAuth": "With a free token: 500 tests per hour (sign in at dash.globalping.io)", + "rateLimitSponsor": "GitHub sponsors: higher limits based on sponsorship tier + hosting probes", + "rateLimitsNote": "For example, 3 monitors with 5 locations each, checked every minute, uses 15 credits per minute (900/hour). Choose your tier accordingly." }, "saveButtonLabel": "Save", "statsSettings": { diff --git a/server/src/config/controllers.ts b/server/src/config/controllers.ts index 8a83a0f63..93324664e 100644 --- a/server/src/config/controllers.ts +++ b/server/src/config/controllers.ts @@ -29,7 +29,7 @@ export interface InitializedControllers { export const initializeControllers = (services: InitializedServices): InitializedControllers => { return { authController: new AuthController(services.userService), - monitorController: new MonitorController(services.monitorService), + monitorController: new MonitorController(services.monitorService, services.settingsService), settingsController: new SettingsController(services.settingsService, services.emailService), checkController: new CheckController(services.checkService), inviteController: new InviteController(services.inviteService), diff --git a/server/src/controllers/monitorController.ts b/server/src/controllers/monitorController.ts index cfea254c8..1b38bf4d0 100644 --- a/server/src/controllers/monitorController.ts +++ b/server/src/controllers/monitorController.ts @@ -26,16 +26,19 @@ import { } from "./controllerUtils.js"; import { AppError } from "@/utils/AppError.js"; import { IMonitorService } from "@/service/index.js"; -import { GLOBALPING_LOCATIONS } from "@/service/infrastructure/globalpingService.js"; +import { getGlobalpingLocationsByTier } from "@/service/infrastructure/globalpingService.js"; +import type { ISettingsService } from "@/service/system/settingsService.js"; const SERVICE_NAME = "monitorController"; class MonitorController { static SERVICE_NAME = SERVICE_NAME; private monitorService: IMonitorService; + private settingsService: ISettingsService; - constructor(monitorService: IMonitorService) { + constructor(monitorService: IMonitorService, settingsService: ISettingsService) { this.monitorService = monitorService; + this.settingsService = settingsService; } get serviceName() { @@ -390,10 +393,13 @@ class MonitorController { getGlobalpingLocations = async (_req: Request, res: Response, next: NextFunction) => { try { + const settings = await this.settingsService.getDBSettings(); + const tier = settings.globalpingLocationsTier ?? 6; + const locations = getGlobalpingLocationsByTier(tier); return res.status(200).json({ success: true, msg: "Globalping locations retrieved successfully", - data: GLOBALPING_LOCATIONS, + data: locations, }); } catch (error) { next(error); diff --git a/server/src/db/models/AppSettings.ts b/server/src/db/models/AppSettings.ts index 820fe08d1..b5b546d8a 100644 --- a/server/src/db/models/AppSettings.ts +++ b/server/src/db/models/AppSettings.ts @@ -24,6 +24,7 @@ const AppSettingsSchema = new Schema( jwtSecret: { type: String }, pagespeedApiKey: { type: String }, globalpingApiKey: { type: String }, + globalpingLocationsTier: { type: Number, default: 6 }, systemEmailHost: { type: String }, systemEmailPort: { type: Number }, systemEmailAddress: { type: String }, diff --git a/server/src/repositories/settings/MongoSettingsRepository.ts b/server/src/repositories/settings/MongoSettingsRepository.ts index 1c963096f..82ca17933 100644 --- a/server/src/repositories/settings/MongoSettingsRepository.ts +++ b/server/src/repositories/settings/MongoSettingsRepository.ts @@ -39,6 +39,7 @@ class MongoSettingsRepository implements ISettingsRepository { systemEmailRejectUnauthorized: doc.systemEmailRejectUnauthorized ?? true, showURL: doc.showURL ?? false, globalpingApiKey: doc.globalpingApiKey ?? undefined, + globalpingLocationsTier: doc.globalpingLocationsTier ?? 6, singleton: doc.singleton, version: doc.version ?? 1, globalThresholds: doc.globalThresholds ?? undefined, diff --git a/server/src/service/infrastructure/globalpingService.ts b/server/src/service/infrastructure/globalpingService.ts index 38828a203..be25a966c 100644 --- a/server/src/service/infrastructure/globalpingService.ts +++ b/server/src/service/infrastructure/globalpingService.ts @@ -5,16 +5,47 @@ import type { MonitorStatusResponse } from "@/types/network.js"; const SERVICE_NAME = "GlobalpingService"; -const LOCATION_MAP: Record = { +// Maps location IDs to Globalping API location objects +const LOCATION_MAP: Record> = { + // Continent-level (used for 3 and 6 tier) "north-america": { continent: "NA" }, europe: { continent: "EU" }, asia: { continent: "AS" }, "south-america": { continent: "SA" }, oceania: { continent: "OC" }, africa: { continent: "AF" }, + // City-level (used for 15 tier) + "us-east": { country: "US", state: "VA" }, + "us-west": { country: "US", state: "CA" }, + canada: { country: "CA", city: "Toronto" }, + "uk": { country: "GB", city: "London" }, + germany: { country: "DE", city: "Frankfurt" }, + netherlands: { country: "NL", city: "Amsterdam" }, + poland: { country: "PL", city: "Warsaw" }, + japan: { country: "JP", city: "Tokyo" }, + singapore: { country: "SG", city: "Singapore" }, + india: { country: "IN", city: "Mumbai" }, + australia: { country: "AU", city: "Sydney" }, + brazil: { country: "BR" }, + chile: { country: "CL", city: "Santiago" }, + "south-africa": { country: "ZA", city: "Johannesburg" }, + uae: { country: "AE", city: "Dubai" }, }; -export const GLOBALPING_LOCATIONS = [ +interface GlobalpingLocationOption { + id: string; + label: string; +} + +// 3 locations: core regions +const LOCATIONS_TIER_3: GlobalpingLocationOption[] = [ + { id: "north-america", label: "North America" }, + { id: "europe", label: "Europe" }, + { id: "asia", label: "Asia" }, +]; + +// 6 locations: all continents +const LOCATIONS_TIER_6: GlobalpingLocationOption[] = [ { id: "north-america", label: "North America" }, { id: "europe", label: "Europe" }, { id: "asia", label: "Asia" }, @@ -23,6 +54,35 @@ export const GLOBALPING_LOCATIONS = [ { id: "africa", label: "Africa" }, ]; +// 15 locations: city/country level +const LOCATIONS_TIER_15: GlobalpingLocationOption[] = [ + { id: "us-east", label: "US East (Virginia)" }, + { id: "us-west", label: "US West (California)" }, + { id: "canada", label: "Canada (Toronto)" }, + { id: "uk", label: "UK (London)" }, + { id: "germany", label: "Germany (Frankfurt)" }, + { id: "netherlands", label: "Netherlands (Amsterdam)" }, + { id: "poland", label: "Poland (Warsaw)" }, + { id: "japan", label: "Japan (Tokyo)" }, + { id: "singapore", label: "Singapore" }, + { id: "india", label: "India (Mumbai)" }, + { id: "australia", label: "Australia (Sydney)" }, + { id: "brazil", label: "Brazil" }, + { id: "chile", label: "Chile (Santiago)" }, + { id: "south-africa", label: "South Africa (Johannesburg)" }, + { id: "uae", label: "UAE (Dubai)" }, +]; + +const LOCATIONS_BY_TIER: Record = { + 3: LOCATIONS_TIER_3, + 6: LOCATIONS_TIER_6, + 15: LOCATIONS_TIER_15, +}; + +export const getGlobalpingLocationsByTier = (tier: number): GlobalpingLocationOption[] => { + return LOCATIONS_BY_TIER[tier] ?? LOCATIONS_TIER_6; +}; + class GlobalpingService { static SERVICE_NAME = SERVICE_NAME; diff --git a/server/src/types/settings.ts b/server/src/types/settings.ts index 464f51364..5f02688f5 100644 --- a/server/src/types/settings.ts +++ b/server/src/types/settings.ts @@ -25,6 +25,7 @@ export interface Settings { systemEmailRejectUnauthorized: boolean; showURL: boolean; globalpingApiKey?: string; + globalpingLocationsTier?: number; singleton: boolean; version: number; globalThresholds?: SettingsThresholds; diff --git a/server/src/validation/joi.ts b/server/src/validation/joi.ts index 672c60f43..c4ba6ef2b 100755 --- a/server/src/validation/joi.ts +++ b/server/src/validation/joi.ts @@ -431,6 +431,7 @@ const updateAppSettingsBodyValidation = joi.object({ systemEmailRejectUnauthorized: joi.boolean(), globalpingApiKey: joi.string().allow(""), + globalpingLocationsTier: joi.number().valid(3, 6, 15).optional(), globalThresholds: joi .object({ cpu: joi.number().min(1).max(100).allow(""),