package metrics // Global histograms for the relay's hot paths. Single-threaded per // domain so direct globals are race-free under the moxie cooperative // scheduler. Code on the hot path observes via these references; the // /metrics endpoint snapshots via SnapshotAll. // // To add a new metric: declare a *Histogram global, initialize in init, // and append to allHistograms below. var ( // IngestPipelineNs measures end-to-end pipeline.Ingest cost from // envelope-parsed event in to Result emitted out. Includes signature // verify, ACL, expiration check, replaceable resolution, and store. IngestPipelineNs = NewHistogram("ingest_pipeline_ns") // SigVerifyNs measures BIP340 Schnorr verification time per event. SigVerifyNs = NewHistogram("sig_verify_ns") // ACLAllowWriteNs measures the ACL.AllowWrite call duration. Open // mode is sub-µs; social/grapevine modes can spike under cold cache. ACLAllowWriteNs = NewHistogram("acl_allowwrite_ns") // WALAppendNs measures WAL.Append wall time, including the optional // fsync at the configured cadence (default every 100 writes). WALAppendNs = NewHistogram("wal_append_ns") // WALFsyncNs measures the explicit fsync syscall when triggered. WALFsyncNs = NewHistogram("wal_fsync_ns") // AcceptLoopHandleNs measures wall time of one EpollWait → handler // dispatch cycle (excluding the EpollWait blocking wait itself). AcceptLoopHandleNs = NewHistogram("accept_handle_ns") // AcceptLoopWaitNs measures EpollWait blocking wait. AcceptLoopWaitNs = NewHistogram("accept_wait_ns") ) var allHistograms = []*Histogram{ IngestPipelineNs, SigVerifyNs, ACLAllowWriteNs, WALAppendNs, WALFsyncNs, AcceptLoopHandleNs, AcceptLoopWaitNs, } // SnapshotAll emits a JSON object of all registered histograms. func SnapshotAll(buf []byte) []byte { buf = append(buf, '{') for i, h := range allHistograms { if i > 0 { buf = append(buf, ',') } buf = h.AppendJSON(buf) } buf = append(buf, '}') return buf } // ResetAll clears all histograms. Used between benchmark phases. func ResetAll() { for _, h := range allHistograms { h.Reset() } }