Skip to content

Commit

Permalink
[CON-429] Add user status by primary metric to network monitoring (#3975
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jonaylor89 committed Sep 30, 2022
1 parent e04e1ac commit 09fb7a4
Show file tree
Hide file tree
Showing 4 changed files with 423 additions and 154 deletions.
Expand Up @@ -287,4 +287,60 @@ SELECT COUNT(*) as user_count
AND
secondary1spid != ALL('{1, 2, 3, 4, 5, 6, 7, 8, 9}'::int[])
AND
secondary2spid != ALL ('{1, 2, 3, 4, 5, 6, 7, 8, 9}'::int[]);
secondary2spid != ALL ('{1, 2, 3, 4, 5, 6, 7, 8, 9}'::int[]);

-- FULLY SYNCED

SELECT fully_synced.spid, cnodes.endpoint, fully_synced.fully_synced_count, partially_synced.partially_synced_count, unsynced.unsynced_count
FROM (
SELECT primaryspid AS spid, COUNT(*) as fully_synced_count
FROM network_monitoring_users
WHERE
run_id = 71
AND
primary_clock_value IS NOT NULL
AND
primary_clock_value = secondary1_clock_value
AND
secondary1_clock_value = secondary2_clock_value
GROUP BY primaryspid
) AS fully_synced
JOIN (
SELECT primaryspid AS SPID, COUNT(*) AS partially_synced_count
FROM network_monitoring_users
WHERE
run_id = 71
AND
primary_clock_value IS NOT NULL
AND (
primary_clock_value = secondary1_clock_value
OR
primary_clock_value = secondary2_clock_value
)
AND
secondary1_clock_value != secondary2_clock_value
GROUP BY primaryspid
) AS partially_synced
ON fully_synced.spid = partially_synced.spid
JOIN (
SELECT primaryspid AS spid, COUNT(*) AS unsynced_count
FROM network_monitoring_users
WHERE
run_id = 71
AND
primary_clock_value IS NOT NULL
AND
primary_clock_value != secondary1_clock_value
AND
primary_clock_value != secondary2_clock_value
GROUP BY primaryspid
) AS unsynced
ON fully_synced.spid = unsynced.spid
JOIN (
SELECT spid, endpoint
FROM network_monitoring_content_nodes
WHERE
run_id = 71
) AS cnodes
ON cnodes.spid = fully_synced.spid
ORDER BY fully_synced.spid;
18 changes: 18 additions & 0 deletions discovery-provider/plugins/network-monitoring/src/metrics/index.ts
@@ -1,12 +1,15 @@
import axios from "axios";
import {
allUserCountGauge,
fullySyncedUsersByPrimaryCountGauge,
fullySyncedUsersCountGauge,
gateway,
generatingMetricsDurationGauge,
nullPrimaryUsersCountGauge,
partiallySyncedUsersByPrimaryCountGauge,
partiallySyncedUsersCountGauge,
primaryUserCountGauge,
unsyncedUsersByPrimaryCountGauge,
unsyncedUsersCountGauge,
userCountGauge,
usersWithAllFoundationNodeReplicaSetGauge,
Expand All @@ -24,6 +27,7 @@ import {
getUserCount,
getRunStartTime,
getUsersWithEntireReplicaSetNotInSpidSetCount,
getUserStatusByPrimary,
} from "./queries";

export const generateMetrics = async (run_id: number) => {
Expand Down Expand Up @@ -58,12 +62,26 @@ export const generateMetrics = async (run_id: number) => {
foundationNodes
);

const userStatusByPrimary = await getUserStatusByPrimary(run_id);

allUserCount.forEach(({ endpoint, count }) => {
allUserCountGauge.set({ endpoint, run_id }, count);
});
primaryUserCount.forEach(({ endpoint, count }) => {
primaryUserCountGauge.set({ endpoint, run_id }, count);
});
userStatusByPrimary.forEach(
({
endpoint,
fullySyncedCount,
partiallySyncedCount,
unsyncedCount,
}) => {
fullySyncedUsersByPrimaryCountGauge.set({ endpoint, run_id }, fullySyncedCount);
partiallySyncedUsersByPrimaryCountGauge.set({ endpoint, run_id }, partiallySyncedCount);
unsyncedUsersByPrimaryCountGauge.set({ endpoint, run_id }, unsyncedCount);
}
);

userCountGauge.set({ run_id }, userCount);
fullySyncedUsersCountGauge.set({ run_id }, fullySyncedUsersCount);
Expand Down

0 comments on commit 09fb7a4

Please sign in to comment.