Skip to content

Commit

Permalink
feat(pkg/server/ginserver): add http_server_processing_request metric
Browse files Browse the repository at this point in the history
  • Loading branch information
amazing-gao committed May 28, 2024
1 parent 7200326 commit 6570123
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/server/ginserver/mid/ginprom/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,9 @@ func UrlMapping(c *gin.Context) string {
url = strings.Replace(url, "/"+p.Value, "/:"+p.Key, 1)
}

return url
if len(url) > 200 {
return url[:197] + "..."
}

return url[:200]
}
9 changes: 9 additions & 0 deletions pkg/server/ginserver/mid/ginprom/ginprom.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type (
GinProm struct {
cfg *Config
processingGauge *metric.GaugeVec
reqSizeSummary *metric.SummaryVec
reqBeginCounter *metric.CounterVec
reqFinishCounter *metric.CounterVec
Expand All @@ -22,6 +23,11 @@ type (
func newGinProm(c *Config) *GinProm {
return &GinProm{
cfg: c,
processingGauge: metric.NewGaugeVec(
"http_server_processing_request",
"http server processing request",
[]string{"method", "url"},
),
reqSizeSummary: metric.NewSummaryVec(
"http_server_request_size_bytes",
"The HTTP request sizes in bytes.",
Expand Down Expand Up @@ -81,9 +87,12 @@ func (prom *GinProm) Handler() gin.HandlerFunc {

reqSz := computeApproximateRequestSize(ctx.Request)

prom.processingGauge.WithLabelValues(labels...).Inc()
prom.reqSizeSummary.WithLabelValues(labels...).Observe(reqSz)
prom.reqBeginCounter.WithLabelValues(labels...).Inc()

defer prom.processingGauge.WithLabelValues(labels...).Dec()

ctx.Next()

resSz := ctx.Writer.Size()
Expand Down

0 comments on commit 6570123

Please sign in to comment.