Skip to content

Commit

Permalink
added middleware name metric
Browse files Browse the repository at this point in the history
  • Loading branch information
sachsingh committed Nov 4, 2022
1 parent 3984088 commit 33d311f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions runtime/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const (
scopeTagEndpoint = "endpointid"
scopeTagHandler = "handlerid"
scopeTagError = "error"
scopeTagMiddleWare = "middlewarename"
scopeTagStatus = "status"
scopeTagProtocol = "protocol"
scopeTagHTTP = "HTTP"
Expand Down
5 changes: 3 additions & 2 deletions runtime/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (m *MiddlewareStack) Handle(
//for error metrics only emit when there is gateway error and not request error
// the percentage can be calculated via error_count/total_request
if res.pendingStatusCode >= 500 {
m.emitAvailabilityError(middlewareRequestStatusTag, req.scope)
m.emitAvailabilityError(middlewareRequestStatusTag, m.middlewares[i].Name(), req.scope)
}
return ctx
}
Expand All @@ -159,9 +159,10 @@ func (m *MiddlewareStack) recordLatency(tagName string, startTime time.Time, sco
}

// emitAvailability is used to increment the error counter for a particular tagName.
func (m *MiddlewareStack) emitAvailabilityError(tagName string, scope tally.Scope) {
func (m *MiddlewareStack) emitAvailabilityError(tagName string, middlewareName string, scope tally.Scope) {
tagged := scope.Tagged(map[string]string{
scopeTagStatus: "error",
scopeTagMiddleWare: middlewareName,
})
tagged.Counter(tagName).Inc(1)
}

0 comments on commit 33d311f

Please sign in to comment.