mirror of https://github.com/waku-org/nwaku.git
feat(store): add query and insertion time metrics
This commit is contained in:
parent
728e298dd7
commit
a4860d92a0
|
@ -31,6 +31,8 @@ declarePublicGauge waku_store_messages, "number of historical messages", ["type"
|
|||
declarePublicGauge waku_store_peers, "number of store peers"
|
||||
declarePublicGauge waku_store_errors, "number of store protocol errors", ["type"]
|
||||
declarePublicGauge waku_store_queries, "number of store queries received"
|
||||
declarePublicHistogram waku_store_insert_time, "time spent storing a message (ms)"
|
||||
declarePublicHistogram waku_store_query_time, "time spent processing a history query (ms)"
|
||||
|
||||
logScope:
|
||||
topics = "wakustore"
|
||||
|
@ -92,7 +94,11 @@ proc findMessages(w: WakuStore, query: HistoryQuery): HistoryResponse {.gcsafe.}
|
|||
qMaxPageSize = query.pagingInfo.pageSize
|
||||
qAscendingOrder = query.pagingInfo.direction == PagingDirection.FORWARD
|
||||
|
||||
let queryStartTime = getTime().toUnixFloat()
|
||||
|
||||
let queryRes = block:
|
||||
# TODO: Move this logic, together with the insert message logic and load messages on boot
|
||||
# into a "dual-store" message store implementation.
|
||||
if w.isSqliteOnly:
|
||||
w.store.getMessagesByHistoryQuery(
|
||||
contentTopic = qContentTopics,
|
||||
|
@ -114,6 +120,10 @@ proc findMessages(w: WakuStore, query: HistoryQuery): HistoryResponse {.gcsafe.}
|
|||
ascendingOrder = qAscendingOrder
|
||||
)
|
||||
|
||||
let queryTime = getTime().toUnixFloat() - queryStartTime
|
||||
waku_store_query_time.observe(getMillisecondTime(queryTime))
|
||||
|
||||
|
||||
# Build response
|
||||
# TODO: Improve error reporting
|
||||
if queryRes.isErr():
|
||||
|
@ -216,11 +226,14 @@ proc handleMessage*(w: WakuStore, pubsubTopic: string, msg: WakuMessage) {.async
|
|||
# The message is ephemeral, should not be stored
|
||||
return
|
||||
|
||||
let insertStartTime = getTime().toUnixFloat()
|
||||
|
||||
let now = getNanosecondTime(getTime().toUnixFloat())
|
||||
let index = Index.compute(msg, receivedTime=now, pubsubTopic=pubsubTopic)
|
||||
|
||||
trace "handling message", topic=pubsubTopic, index=index
|
||||
|
||||
block:
|
||||
if w.isSqliteOnly:
|
||||
# Add messages to persistent store, if present
|
||||
if w.store.isNil():
|
||||
|
@ -230,6 +243,7 @@ proc handleMessage*(w: WakuStore, pubsubTopic: string, msg: WakuMessage) {.async
|
|||
if resPutStore.isErr():
|
||||
debug "failed to insert message to persistent store", index=index, err=resPutStore.error()
|
||||
waku_store_errors.inc(labelValues = [insertFailure])
|
||||
|
||||
waku_store_messages.set(w.store.getMessagesCount(), labelValues = ["stored"])
|
||||
|
||||
# TODO: Move this logic, together with the load from persistent store on init
|
||||
|
@ -241,6 +255,7 @@ proc handleMessage*(w: WakuStore, pubsubTopic: string, msg: WakuMessage) {.async
|
|||
debug "failed to insert message to in-memory store", index=index, err=resPutInmemory.error()
|
||||
waku_store_errors.inc(labelValues = [insertFailure])
|
||||
return
|
||||
|
||||
waku_store_messages.set(w.messages.getMessagesCount(), labelValues = ["stored"])
|
||||
|
||||
# Add messages to persistent store, if present
|
||||
|
@ -251,7 +266,10 @@ proc handleMessage*(w: WakuStore, pubsubTopic: string, msg: WakuMessage) {.async
|
|||
if resPutStore.isErr():
|
||||
debug "failed to insert message to persistent store", index=index, err=resPutStore.error()
|
||||
waku_store_errors.inc(labelValues = [insertFailure])
|
||||
return
|
||||
|
||||
let insertTime = getTime().toUnixFloat() - insertStartTime
|
||||
waku_store_insert_time.observe(getMillisecondTime(insertTime))
|
||||
|
||||
|
||||
# TODO: Remove after converting the query method into a non-callback method
|
||||
|
|
Loading…
Reference in New Issue