Skip to content

Commit 454b098

Browse files
new metric in postgres_driver to estimate payload stats (#3596)
1 parent 088e310 commit 454b098

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

waku/waku_archive/driver/postgres_driver/postgres_driver.nim

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import
55
stew/[byteutils, arrayops],
66
results,
77
chronos,
8+
metrics,
89
db_connector/[postgres, db_common],
910
chronicles
1011
import
@@ -16,6 +17,9 @@ import
1617
./postgres_healthcheck,
1718
./partitions_manager
1819

20+
declarePublicGauge postgres_payload_size_bytes,
21+
"Payload size in bytes of correctly stored messages"
22+
1923
type PostgresDriver* = ref object of ArchiveDriver
2024
## Establish a separate pools for read/write operations
2125
writeConnPool: PgAsyncPool
@@ -333,14 +337,18 @@ method put*(
333337
return err("could not put msg in messages table: " & $error)
334338

335339
## Now add the row to messages_lookup
336-
return await s.writeConnPool.runStmt(
340+
let ret = await s.writeConnPool.runStmt(
337341
InsertRowInMessagesLookupStmtName,
338342
InsertRowInMessagesLookupStmtDefinition,
339343
@[messageHash, timestamp],
340344
@[int32(messageHash.len), int32(timestamp.len)],
341345
@[int32(0), int32(0)],
342346
)
343347

348+
if ret.isOk():
349+
postgres_payload_size_bytes.set(message.payload.len)
350+
return ret
351+
344352
method getAllMessages*(
345353
s: PostgresDriver
346354
): Future[ArchiveDriverResult[seq[ArchiveRow]]] {.async.} =

0 commit comments

Comments
 (0)