Skip to content

Commit 40fc09a

Browse files
authored
smp server: additional stat counter for ntf credentials created together with the queue (#1589)
* smp server: additional stat counter for ntf credentials created together with the queue * fix prometheus * fix test * fix qSub
1 parent 2a90a2c commit 40fc09a

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

src/Simplex/Messaging/Server.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ client
15121512
stats <- asks serverStats
15131513
incStat $ qCreated stats
15141514
incStat $ qCount stats
1515-
when (isJust ntf) $ incStat $ ntfCreated stats
1515+
when (isJust ntf) $ incStat $ ntfNewCreated stats
15161516
case subMode of
15171517
SMOnlyCreate -> pure ()
15181518
SMSubscribe -> subscribeNewQueue rcvId qr -- no need to check if message is available, it's a new queue
@@ -1580,7 +1580,7 @@ client
15801580
subscribeQueueAndDeliver :: StoreQueue s -> QueueRec -> M s ResponseAndMessage
15811581
subscribeQueueAndDeliver q qr =
15821582
liftIO (TM.lookupIO entId $ subscriptions clnt) >>= \case
1583-
Nothing -> subscribeRcvQueue qr >>= deliver True
1583+
Nothing -> subscribeRcvQueue qr >>= deliver False
15841584
Just s@Sub {subThread} -> do
15851585
stats <- asks serverStats
15861586
case subThread of
@@ -1590,7 +1590,7 @@ client
15901590
pure (err (CMD PROHIBITED), Nothing)
15911591
_ -> do
15921592
incStat $ qSubDuplicate stats
1593-
atomically (writeTVar (delivered s) Nothing) >> deliver False s
1593+
atomically (writeTVar (delivered s) Nothing) >> deliver True s
15941594
where
15951595
deliver :: Bool -> Sub -> M s ResponseAndMessage
15961596
deliver hasSub sub = do

src/Simplex/Messaging/Server/Prometheus.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ prometheusMetrics sm rtm ts =
8282
_qSubEnd,
8383
_qSubEndB,
8484
_ntfCreated,
85+
_ntfNewCreated,
8586
_ntfDeleted,
8687
_ntfDeletedB,
8788
_ntfSub,
@@ -262,15 +263,19 @@ prometheusMetrics sm rtm ts =
262263
\simplex_smp_messages_notify_get_errors{type=\"duplicate\"} " <> mshow _msgGetDuplicate <> "\n# msgGetDuplicate\n\
263264
\simplex_smp_messages_notify_get_errors{type=\"prohibited\"} " <> mshow _msgGetProhibited <> "\n# msgGetProhibited\n\
264265
\\n\
265-
\# HELP simplex_smp_queues_notify_created Created queues with notification flag (client).\n\
266+
\# HELP simplex_smp_queues_notify_created Created queue notification credentials.\n\
266267
\# TYPE simplex_smp_queues_notify_created counter\n\
267268
\simplex_smp_queues_notify_created " <> mshow _ntfCreated <> "\n# ntfCreated\n\
268269
\\n\
269-
\# HELP simplex_smp_queues_notify_deleted Deleted queues with notification flag (client).\n\
270+
\# HELP simplex_smp_queues_notify_new_created Created new queues with notification credentials.\n\
271+
\# TYPE simplex_smp_queues_notify_new_created counter\n\
272+
\simplex_smp_queues_notify_new_created " <> mshow _ntfNewCreated <> "\n# ntfNewCreated\n\
273+
\\n\
274+
\# HELP simplex_smp_queues_notify_deleted Deleted queue notification credentials.\n\
270275
\# TYPE simplex_smp_queues_notify_deleted counter\n\
271276
\simplex_smp_queues_notify_deleted " <> mshow _ntfDeleted <> "\n# ntfDeleted\n\
272277
\\n\
273-
\# HELP simplex_smp_queues_notify_deleted_batch Deleted batched queues with notification flag (client).\n\
278+
\# HELP simplex_smp_queues_notify_deleted_batch Deleted batched queue notification credentials.\n\
274279
\# TYPE simplex_smp_queues_notify_deleted_batch counter\n\
275280
\simplex_smp_queues_notify_deleted_batch " <> mshow _ntfDeletedB <> "\n# ntfDeletedB\n\
276281
\\n\

src/Simplex/Messaging/Server/Stats.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ data ServerStats = ServerStats
4848
qSubEnd :: IORef Int,
4949
qSubEndB :: IORef Int,
5050
ntfCreated :: IORef Int,
51+
ntfNewCreated :: IORef Int, -- credentials created at the time of queue creation
5152
ntfDeleted :: IORef Int,
5253
ntfDeletedB :: IORef Int,
5354
ntfSub :: IORef Int,
@@ -107,6 +108,7 @@ data ServerStatsData = ServerStatsData
107108
_qSubEnd :: Int,
108109
_qSubEndB :: Int,
109110
_ntfCreated :: Int,
111+
_ntfNewCreated :: Int,
110112
_ntfDeleted :: Int,
111113
_ntfDeletedB :: Int,
112114
_ntfSub :: Int,
@@ -167,6 +169,7 @@ newServerStats ts = do
167169
qSubEnd <- newIORef 0
168170
qSubEndB <- newIORef 0
169171
ntfCreated <- newIORef 0
172+
ntfNewCreated <- newIORef 0
170173
ntfDeleted <- newIORef 0
171174
ntfDeletedB <- newIORef 0
172175
ntfSub <- newIORef 0
@@ -224,6 +227,7 @@ newServerStats ts = do
224227
qSubEnd,
225228
qSubEndB,
226229
ntfCreated,
230+
ntfNewCreated,
227231
ntfDeleted,
228232
ntfDeletedB,
229233
ntfSub,
@@ -283,6 +287,7 @@ getServerStatsData s = do
283287
_qSubEnd <- readIORef $ qSubEnd s
284288
_qSubEndB <- readIORef $ qSubEndB s
285289
_ntfCreated <- readIORef $ ntfCreated s
290+
_ntfNewCreated <- readIORef $ ntfNewCreated s
286291
_ntfDeleted <- readIORef $ ntfDeleted s
287292
_ntfDeletedB <- readIORef $ ntfDeletedB s
288293
_ntfSub <- readIORef $ ntfSub s
@@ -340,6 +345,7 @@ getServerStatsData s = do
340345
_qSubEnd,
341346
_qSubEndB,
342347
_ntfCreated,
348+
_ntfNewCreated,
343349
_ntfDeleted,
344350
_ntfDeletedB,
345351
_ntfSub,
@@ -400,6 +406,7 @@ setServerStats s d = do
400406
writeIORef (qSubEnd s) $! _qSubEnd d
401407
writeIORef (qSubEndB s) $! _qSubEndB d
402408
writeIORef (ntfCreated s) $! _ntfCreated d
409+
writeIORef (ntfNewCreated s) $! _ntfNewCreated d
403410
writeIORef (ntfDeleted s) $! _ntfDeleted d
404411
writeIORef (ntfDeletedB s) $! _ntfDeletedB d
405412
writeIORef (ntfSub s) $! _ntfSub d
@@ -460,6 +467,7 @@ instance StrEncoding ServerStatsData where
460467
"qSubEnd=" <> strEncode (_qSubEnd d),
461468
"qSubEndB=" <> strEncode (_qSubEndB d),
462469
"ntfCreated=" <> strEncode (_ntfCreated d),
470+
"ntfNewCreated=" <> strEncode (_ntfNewCreated d),
463471
"ntfDeleted=" <> strEncode (_ntfDeleted d),
464472
"ntfDeletedB=" <> strEncode (_ntfDeletedB d),
465473
"ntfSub=" <> strEncode (_ntfSub d),
@@ -523,6 +531,7 @@ instance StrEncoding ServerStatsData where
523531
_qSubEnd <- opt "qSubEnd="
524532
_qSubEndB <- opt "qSubEndB="
525533
_ntfCreated <- opt "ntfCreated="
534+
_ntfNewCreated <- opt "ntfNewCreated="
526535
_ntfDeleted <- opt "ntfDeleted="
527536
_ntfDeletedB <- opt "ntfDeletedB="
528537
_ntfSub <- opt "ntfSub="
@@ -590,6 +599,7 @@ instance StrEncoding ServerStatsData where
590599
_qSubEnd,
591600
_qSubEndB,
592601
_ntfCreated,
602+
_ntfNewCreated,
593603
_ntfDeleted,
594604
_ntfDeletedB,
595605
_ntfSub,

tests/ServerTests.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ testRestoreMessages =
795795
pure ()
796796
rId <- readTVarIO recipientId
797797
logSize testStoreLogFile `shouldReturn` 2
798-
logSize testServerStatsBackupFile `shouldReturn` 94
798+
logSize testServerStatsBackupFile `shouldReturn` 95
799799
Right stats1 <- strDecode <$> B.readFile testServerStatsBackupFile
800800
checkStats stats1 [rId] 5 1
801801
withSmpServerConfigOn at cfg' testPort . runTest t $ \h -> do
@@ -811,7 +811,7 @@ testRestoreMessages =
811811
logSize testStoreLogFile `shouldReturn` (if compacting then 1 else 2)
812812
-- the last message is not removed because it was not ACK'd
813813
-- logSize testStoreMsgsFile `shouldReturn` 3
814-
logSize testServerStatsBackupFile `shouldReturn` 94
814+
logSize testServerStatsBackupFile `shouldReturn` 95
815815
Right stats2 <- strDecode <$> B.readFile testServerStatsBackupFile
816816
checkStats stats2 [rId] 5 3
817817

@@ -829,7 +829,7 @@ testRestoreMessages =
829829
pure ()
830830
logSize testStoreLogFile `shouldReturn` (if compacting then 1 else 2)
831831
removeFile testStoreLogFile
832-
logSize testServerStatsBackupFile `shouldReturn` 94
832+
logSize testServerStatsBackupFile `shouldReturn` 95
833833
Right stats3 <- strDecode <$> B.readFile testServerStatsBackupFile
834834
checkStats stats3 [rId] 5 5
835835
removeFileIfExists testStoreMsgsFile

0 commit comments

Comments
 (0)