From cac8c140016e1ce2257d918f85b9893ba6c3254d Mon Sep 17 00:00:00 2001 From: Ben Brooks Date: Tue, 24 Sep 2024 16:24:24 +0100 Subject: [PATCH] Add stat to track number of assertion failures --- base/devmode.go | 1 + base/stats.go | 6 ++++++ base/stats_descriptions.go | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/base/devmode.go b/base/devmode.go index 34d04f2975..d017429162 100644 --- a/base/devmode.go +++ b/base/devmode.go @@ -21,5 +21,6 @@ func IsDevMode() bool { // AssertfCtx panics when compiled with the `cb_sg_devmode` build tag, and just warns otherwise. // Callers must be aware that they are responsible for handling returns to cover the non-devmode warn case. func AssertfCtx(ctx context.Context, format string, args ...any) { + SyncGatewayStats.GlobalStats.ResourceUtilization.AssertionFailCount.Add(1) assertLogFn(ctx, format, args...) } diff --git a/base/stats.go b/base/stats.go index e1f0c4b1d1..59eea11a4f 100644 --- a/base/stats.go +++ b/base/stats.go @@ -299,6 +299,10 @@ func (g *GlobalStat) initResourceUtilizationStats() error { if err != nil { return err } + resUtil.AssertionFailCount, err = NewIntStat(ResourceUtilizationSubsystem, "assertion_fail_count", StatUnitNoUnits, AssertionFailCountDesc, StatAddedVersion3dot2dot1, StatDeprecatedVersionNotDeprecated, StatStabilityCommitted, nil, nil, prometheus.CounterValue, 0) + if err != nil { + return err + } resUtil.CpuPercentUtil, err = NewFloatStat(ResourceUtilizationSubsystem, "process_cpu_percent_utilization", StatUnitPercent, ProcessCPUPercentUtilDesc, StatAddedVersion3dot0dot0, StatDeprecatedVersion3dot2dot0, StatStabilityCommitted, nil, nil, prometheus.GaugeValue, 0) if err != nil { return err @@ -379,6 +383,8 @@ type ResourceUtilization struct { SystemMemoryTotal *SgwIntStat `json:"system_memory_total"` // The total number of warnings logged. WarnCount *SgwIntStat `json:"warn_count"` + // The total number of assertion failures logged. + AssertionFailCount *SgwIntStat `json:"assertion_fail_count"` // The total uptime. Uptime *SgwDurStat `json:"uptime"` } diff --git a/base/stats_descriptions.go b/base/stats_descriptions.go index f7f521dcfa..87265f63a7 100644 --- a/base/stats_descriptions.go +++ b/base/stats_descriptions.go @@ -64,7 +64,8 @@ const ( SystemMemoryTotalDesc = "The total memory available on the system in bytes." - WarnCountDesc = "The total number of warnings logged." + WarnCountDesc = "The total number of warnings logged." + AssertionFailCountDesc = "The total number of assertion failures logged." UptimeDesc = "The total uptime." )