浏览代码

Fix requests_total counter in prometheus

DarthSim 3 年之前
父节点
当前提交
bed786372f
共有 2 个文件被更改,包括 6 次插入6 次删除
  1. 1 0
      CHANGELOG.md
  2. 5 6
      metrics/prometheus/prometheus.go

+ 1 - 0
CHANGELOG.md

@@ -15,6 +15,7 @@
 ### Fix
 - Fix Client Hints behavior. `Width` is physical size, so we should divide it by `DPR` value.
 - Fix scale-on-load in some rare cases.
+- Fix `requests_total` counter in Prometheus.
 
 ## [3.0.0.beta1] - 2021-10-01
 ### Added

+ 5 - 6
metrics/prometheus/prometheus.go

@@ -119,6 +119,11 @@ func StartServer(cancel context.CancelFunc) error {
 }
 
 func StartRequest() context.CancelFunc {
+	if !enabled {
+		return func() {}
+	}
+
+	requestsTotal.Inc()
 	return startDuration(requestDuration)
 }
 
@@ -147,12 +152,6 @@ func IncrementErrorsTotal(t string) {
 	}
 }
 
-func IncrementRequestsTotal() {
-	if enabled {
-		requestsTotal.Inc()
-	}
-}
-
 func ObserveBufferSize(t string, size int) {
 	if enabled {
 		bufferSize.With(prometheus.Labels{"type": t}).Observe(float64(size))