From 265b96f26b032de5c3224285be987eb2354a7013 Mon Sep 17 00:00:00 2001 From: John Simons Date: Fri, 21 Nov 2025 16:40:18 +1000 Subject: [PATCH 1/4] Refactor monitoring store to only have state Introduced a monitoringClient --- .../components/BackendChecksNotifications.vue | 12 +- src/Frontend/src/components/PageFooter.vue | 11 +- src/Frontend/src/components/PageHeader.vue | 8 +- .../configuration/EndpointConnection.vue | 21 +-- .../configuration/PlatformConnections.vue | 22 +--- .../components/monitoring/EndpointDetails.vue | 5 +- .../monitoring/EndpointInstances.vue | 26 +--- .../monitoring/MonitoringNotAvailable.vue | 6 +- .../components/monitoring/monitoringClient.ts | 123 ++++++++++++++++++ .../src/stores/ConnectionsAndStatsStore.ts | 56 +++----- .../src/stores/EnvironmentAndVersionsStore.ts | 12 +- .../stores/MonitoringEndpointDetailsStore.ts | 10 +- src/Frontend/src/stores/MonitoringStore.ts | 77 +---------- .../src/stores/ServiceControlStore.ts | 9 ++ src/Frontend/src/stores/ThroughputStore.ts | 10 +- .../src/views/throughputreport/SetupView.vue | 5 +- .../setup/ConnectionSetupView.vue | 9 +- .../setup/DiagnosticsView.vue | 5 +- src/Frontend/test/drivers/vitest/setup.ts | 3 + .../hasServiceControlMonitoringInstance.ts | 6 +- 20 files changed, 199 insertions(+), 237 deletions(-) create mode 100644 src/Frontend/src/components/monitoring/monitoringClient.ts diff --git a/src/Frontend/src/components/BackendChecksNotifications.vue b/src/Frontend/src/components/BackendChecksNotifications.vue index d04a147fd9..4f5b82c971 100644 --- a/src/Frontend/src/components/BackendChecksNotifications.vue +++ b/src/Frontend/src/components/BackendChecksNotifications.vue @@ -9,20 +9,16 @@ import useConnectionsAndStatsAutoRefresh from "@/composables/useConnectionsAndSt import useEnvironmentAndVersionsAutoRefresh from "@/composables/useEnvironmentAndVersionsAutoRefresh"; import { useServiceControlStore } from "@/stores/ServiceControlStore"; import { storeToRefs } from "pinia"; -import { useMonitoringStore } from "@/stores/MonitoringStore"; +import monitoringClient from "./monitoring/monitoringClient"; const router = useRouter(); - const { store: connectionStore } = useConnectionsAndStatsAutoRefresh(); const connectionState = connectionStore.connectionState; const monitoringConnectionState = connectionStore.monitoringConnectionState; const { store: environmentStore } = useEnvironmentAndVersionsAutoRefresh(); const environment = environmentStore.environment; const serviceControlStore = useServiceControlStore(); -const monitoringStore = useMonitoringStore(); const { serviceControlUrl } = storeToRefs(serviceControlStore); -const { monitoringUrl, isMonitoringDisabled } = storeToRefs(monitoringStore); - const primaryConnectionFailure = computed(() => connectionState.unableToConnect); const monitoringConnectionFailure = computed(() => monitoringConnectionState.unableToConnect); @@ -40,7 +36,7 @@ watch(primaryConnectionFailure, (newValue, oldValue) => { watch(monitoringConnectionFailure, (newValue, oldValue) => { // Only watch the state change if monitoring is enabled - if (isMonitoringDisabled.value) { + if (monitoringClient.isMonitoringDisabled) { return; } @@ -48,9 +44,9 @@ watch(monitoringConnectionFailure, (newValue, oldValue) => { if (newValue !== oldValue && !(oldValue === null && newValue === false)) { const connectionUrl = router.resolve(routeLinks.configuration.connections.link).href; if (newValue) { - useShowToast(TYPE.ERROR, "Error", `Could not connect to the ServiceControl Monitoring service at ${monitoringUrl.value}. View connection settings`); + useShowToast(TYPE.ERROR, "Error", `Could not connect to the ServiceControl Monitoring service at ${monitoringClient.url}. View connection settings`); } else { - useShowToast(TYPE.SUCCESS, "Success", `Connection to ServiceControl Monitoring service was successful at ${monitoringUrl.value}.`); + useShowToast(TYPE.SUCCESS, "Success", `Connection to ServiceControl Monitoring service was successful at ${monitoringClient.url}.`); } } }); diff --git a/src/Frontend/src/components/PageFooter.vue b/src/Frontend/src/components/PageFooter.vue index b6f5a40d6e..bde947cbb6 100644 --- a/src/Frontend/src/components/PageFooter.vue +++ b/src/Frontend/src/components/PageFooter.vue @@ -10,7 +10,7 @@ import { useServiceControlStore } from "@/stores/ServiceControlStore"; import { storeToRefs } from "pinia"; import { useConfigurationStore } from "@/stores/ConfigurationStore"; import { useLicenseStore } from "@/stores/LicenseStore"; -import { useMonitoringStore } from "@/stores/MonitoringStore"; +import monitoringClient from "./monitoring/monitoringClient"; const { store: connectionStore } = useConnectionsAndStatsAutoRefresh(); const connectionState = connectionStore.connectionState; @@ -19,22 +19,17 @@ const { store: environmentAndVersionsStore } = useEnvironmentAndVersionsAutoRefr const newVersions = environmentAndVersionsStore.newVersions; const environment = environmentAndVersionsStore.environment; const serviceControlStore = useServiceControlStore(); -const monitoringStore = useMonitoringStore(); const { serviceControlUrl } = storeToRefs(serviceControlStore); -const { monitoringUrl } = storeToRefs(monitoringStore); const licenseStore = useLicenseStore(); const { licenseStatus, license } = licenseStore; - -const isMonitoringEnabled = computed(() => { - return monitoringUrl.value !== "!" && monitoringUrl.value !== "" && monitoringUrl.value !== null && monitoringUrl.value !== undefined; -}); +const isMonitoringEnabled = monitoringClient.isMonitoringEnabled; const scAddressTooltip = computed(() => { return `ServiceControl URL ${serviceControlUrl.value}`; }); const scMonitoringAddressTooltip = computed(() => { - return `Monitoring URL ${monitoringUrl.value}`; + return `Monitoring URL ${monitoringClient.url}`; }); const configurationStore = useConfigurationStore(); diff --git a/src/Frontend/src/components/PageHeader.vue b/src/Frontend/src/components/PageHeader.vue index 0e46ff00a7..e059894b22 100644 --- a/src/Frontend/src/components/PageHeader.vue +++ b/src/Frontend/src/components/PageHeader.vue @@ -12,17 +12,15 @@ import DashboardMenuItem from "@/components/dashboard/DashboardMenuItem.vue"; import FeedbackButton from "@/components/FeedbackButton.vue"; import ThroughputMenuItem from "@/views/throughputreport/ThroughputMenuItem.vue"; import AuditMenuItem from "./audit/AuditMenuItem.vue"; -import { useMonitoringStore } from "@/stores/MonitoringStore"; -import { storeToRefs } from "pinia"; +import monitoringClient from "@/components/monitoring/monitoringClient"; -const monitoringStore = useMonitoringStore(); -const { isMonitoringEnabled } = storeToRefs(monitoringStore); +const isMonitoringEnabled = monitoringClient.isMonitoringEnabled; // prettier-ignore const menuItems = computed( () => [ DashboardMenuItem, HeartbeatsMenuItem, - ...(isMonitoringEnabled.value ? [MonitoringMenuItem] : []), + ...(isMonitoringEnabled ? [MonitoringMenuItem] : []), AuditMenuItem, FailedMessagesMenuItem, CustomChecksMenuItem, diff --git a/src/Frontend/src/components/configuration/EndpointConnection.vue b/src/Frontend/src/components/configuration/EndpointConnection.vue index dbbb4c9c8b..98599bf0c1 100644 --- a/src/Frontend/src/components/configuration/EndpointConnection.vue +++ b/src/Frontend/src/components/configuration/EndpointConnection.vue @@ -6,23 +6,15 @@ import CodeEditor from "@/components/CodeEditor.vue"; import { useServiceControlStore } from "@/stores/ServiceControlStore"; import { storeToRefs } from "pinia"; import LoadingSpinner from "../LoadingSpinner.vue"; -import { useMonitoringStore } from "@/stores/MonitoringStore"; +import monitoringClient, { MetricsConnectionDetails } from "../monitoring/monitoringClient"; interface ServiceControlInstanceConnection { settings: { [key: string]: object }; errors: string[]; } -interface MetricsConnectionDetails { - Enabled: boolean; - MetricsQueue?: string; - Interval?: string; -} - const serviceControlStore = useServiceControlStore(); -const monitoringStore = useMonitoringStore(); const { serviceControlUrl } = storeToRefs(serviceControlStore); -const { monitoringUrl } = storeToRefs(monitoringStore); const loading = ref(true); const showCodeOnlyTab = ref(true); @@ -79,7 +71,7 @@ function switchJsonTab() { async function serviceControlConnections() { const scConnectionResult = getServiceControlConnection(); - const monitoringConnectionResult = getMonitoringConnection(); + const monitoringConnectionResult = monitoringClient.getMonitoringConnection(); const [scConnection, mConnection] = await Promise.all([scConnectionResult, monitoringConnectionResult]); return { @@ -102,15 +94,6 @@ async function getServiceControlConnection() { return { errors: [`Error reaching ServiceControl at ${serviceControlUrl.value} connection`] } as ServiceControlInstanceConnection; } } - -async function getMonitoringConnection() { - try { - const [, data] = await monitoringStore.fetchTypedFromMonitoring<{ Metrics: MetricsConnectionDetails }>("connection"); - return { ...data, errors: [] }; - } catch { - return { Metrics: null, errors: [`Error SC Monitoring instance at ${monitoringUrl.value}connection`] }; - } -}