Skip to content

Commit

Permalink
emit error metric only if prometheus metrics are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
rudrakhp committed Nov 21, 2023
1 parent decc6bc commit f125efb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,21 +391,21 @@ func (p *envoyExtAuthzGrpcServer) check(ctx context.Context, req interface{}) (*

stop := func() *rpc_status.Status {
stopeval()
if internalErr.Unwrap() != nil || internalErr.Code != "" {
if p.cfg.EnablePerformanceMetrics {
var topdownError *topdown.Error
if errors.As(internalErr.Unwrap(), &topdownError) {
if internalErr.Unwrap() != nil && errors.As(internalErr.Unwrap(), &topdownError) {
p.metricErrorCounter.With(prometheus.Labels{"reason": topdownError.Code}).Inc()
} else if internalErr.Code != "" {
p.metricErrorCounter.With(prometheus.Labels{"reason": internalErr.Code}).Inc()
} else {
p.metricErrorCounter.With(prometheus.Labels{"reason": "unknown_check_error"}).Inc()
}
}
logErr := p.log(ctx, input, result, err)
if logErr != nil {
_ = txnClose(ctx, logErr) // Ignore error
p.Logger().Debug("Error when logging event: %v", logErr)
p.metricErrorCounter.With(prometheus.Labels{"reason": "unknown_log_error"}).Inc()
p.Logger().WithFields(map[string]interface{}{"err": logErr}).Debug("Error when logging event")
if p.cfg.EnablePerformanceMetrics {
p.metricErrorCounter.With(prometheus.Labels{"reason": "unknown_log_error"}).Inc()
}
return &rpc_status.Status{
Code: int32(code.Code_UNKNOWN),
Message: logErr.Error(),
Expand Down

0 comments on commit f125efb

Please sign in to comment.