new metric in postgres_driver to estimate payload stats (#3596)

This commit is contained in:
Ivan FB 2025-11-24 10:16:37 +01:00 committed by GitHub
parent 088e3108c8
commit 454b098ac5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,7 @@ import
stew/[byteutils, arrayops], stew/[byteutils, arrayops],
results, results,
chronos, chronos,
metrics,
db_connector/[postgres, db_common], db_connector/[postgres, db_common],
chronicles chronicles
import import
@ -16,6 +17,9 @@ import
./postgres_healthcheck, ./postgres_healthcheck,
./partitions_manager ./partitions_manager
declarePublicGauge postgres_payload_size_bytes,
"Payload size in bytes of correctly stored messages"
type PostgresDriver* = ref object of ArchiveDriver type PostgresDriver* = ref object of ArchiveDriver
## Establish a separate pools for read/write operations ## Establish a separate pools for read/write operations
writeConnPool: PgAsyncPool writeConnPool: PgAsyncPool
@ -333,7 +337,7 @@ method put*(
return err("could not put msg in messages table: " & $error) return err("could not put msg in messages table: " & $error)
## Now add the row to messages_lookup ## Now add the row to messages_lookup
return await s.writeConnPool.runStmt( let ret = await s.writeConnPool.runStmt(
InsertRowInMessagesLookupStmtName, InsertRowInMessagesLookupStmtName,
InsertRowInMessagesLookupStmtDefinition, InsertRowInMessagesLookupStmtDefinition,
@[messageHash, timestamp], @[messageHash, timestamp],
@ -341,6 +345,10 @@ method put*(
@[int32(0), int32(0)], @[int32(0), int32(0)],
) )
if ret.isOk():
postgres_payload_size_bytes.set(message.payload.len)
return ret
method getAllMessages*( method getAllMessages*(
s: PostgresDriver s: PostgresDriver
): Future[ArchiveDriverResult[seq[ArchiveRow]]] {.async.} = ): Future[ArchiveDriverResult[seq[ArchiveRow]]] {.async.} =