Skip to content

Commit 5852b12

Browse files
authored
Merge pull request #71 from unisoncomputing/cp/queue-metrics
Add metric tracking causal diff queue size
2 parents 574abd2 + 1369dcd commit 5852b12

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/Share/Metrics.hs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ deployment :: Text
4242
deployment = tShow Deployment.deployment
4343

4444
metricUpdateInterval :: Time.NominalDiffTime
45-
metricUpdateInterval = 10 * 60 -- 10 mins
45+
metricUpdateInterval = 5 * 60 -- 5 mins
4646

4747
-- | Low resolution metrics that are updated rarely.
4848
data SlowChangingMetrics = SlowChangingMetrics
@@ -63,7 +63,8 @@ data SlowChangingMetrics = SlowChangingMetrics
6363
-- Number of total public or private definitions on /main branch of all Share projects
6464
numTotalPublicOrPrivateDefinitions :: Int64,
6565
usersWithContributions :: Int64,
66-
usersWithTickets :: Int64
66+
usersWithTickets :: Int64,
67+
causalDiffQueueEntriesCount :: Int64
6768
}
6869

6970
-- | Serves the app's prometheus metrics at `/metrics`
@@ -77,7 +78,7 @@ serveMetricsMiddleware env = do
7778
refreshGauges getMetrics
7879
Prom.prometheus prometheusSettings app req handleResponse
7980
where
80-
runPG = PG.runSessionWithPool (Env.pgConnectionPool env) . PG.readTransaction
81+
runPG = PG.runSessionWithPool (Env.pgConnectionPool env) . PG.transaction PG.ReadCommitted PG.Read
8182
prometheusSettings =
8283
Prom.def
8384
{ Prom.prometheusEndPoint = ["metrics"],
@@ -311,6 +312,7 @@ queryMetrics now = do
311312
numTotalPublicDefinitions <- Q.numTotalPublicDefinitions
312313
usersWithContributions <- Q.usersInteractedWithContributions
313314
usersWithTickets <- Q.usersInteractedWithTickets
315+
causalDiffQueueEntriesCount <- Q.numCausalDiffQueueEntries
314316
pure SlowChangingMetrics {..}
315317

316318
-- | Since some time-based metrics will change due to the passage of time rather than any
@@ -339,6 +341,8 @@ refreshGauges getMetrics = do
339341
Prom.withLabel numUsersWithContributions (deployment, service) \gauge -> Prom.setGauge gauge (fromIntegral usersWithContributions)
340342
Prom.withLabel numUsersWithTickets (deployment, service) \gauge -> Prom.setGauge gauge (fromIntegral usersWithTickets)
341343

344+
Prom.withLabel numCausalDiffQueueEntries (deployment, service) \gauge -> Prom.setGauge gauge (fromIntegral causalDiffQueueEntriesCount)
345+
342346
{-# NOINLINE numUniqueAccountsWithAPushInLastWeek #-}
343347
numUniqueAccountsWithAPushInLastWeek :: Prom.Vector Prom.Label2 Prom.Gauge
344348
numUniqueAccountsWithAPushInLastWeek =
@@ -423,6 +427,18 @@ webhookSendingDurationSeconds =
423427
"webhook_sending_duration_seconds"
424428
"The time it took to send a notification webhook"
425429

430+
{-# NOINLINE numCausalDiffQueueEntries #-}
431+
numCausalDiffQueueEntries :: Prom.Vector Prom.Label2 Prom.Gauge
432+
numCausalDiffQueueEntries =
433+
Prom.unsafeRegister $
434+
Prom.vector ("deployment", "service") $
435+
Prom.gauge info
436+
where
437+
info =
438+
Prom.Info
439+
"causal_diff_queue_entries_count"
440+
"The number of causal diffs in the queue."
441+
426442
timeActionIntoHistogram :: (Prom.Label l, MonadUnliftIO m) => (Prom.Vector l Prom.Histogram) -> l -> m c -> m c
427443
timeActionIntoHistogram histogram l m = do
428444
startTime <- liftIO $ Clock.getTime Monotonic

src/Share/Postgres/Metrics/Queries.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,8 @@ WITH namespaces(handle, slug, name, namespace_hash_id, private) AS (
162162
) :: bigint, 0 :: bigint) as num
163163
FROM namespaces
164164
|]
165+
166+
numCausalDiffQueueEntries :: PG.Transaction e Int64
167+
numCausalDiffQueueEntries =
168+
PG.queryExpect1Col
169+
[PG.sql| SELECT COUNT(*) FROM causal_diff_queue |]

0 commit comments

Comments
 (0)