Skip to content

Commit

Permalink
Add audit metric (#55)
Browse files Browse the repository at this point in the history
## Description

Adding custom audit metric for audit errors.

## Motivation and Context

This is needed to track audit errors and create alerts when they happen.

## How Has This Been Tested?

Built a local copy from this PR and integrated it with Reporting locally
by running the binary. Used invalid audit environment variables to make
the audit request fail.

Commands:
- make build
- set envs (grab from Pics containers) and include invalid audit envs
- ./oauth2-proxy --http-address=127.0.0.1:9876
--https-address=127.0.0.1:9877 --metrics-address=127.0.0.1:9090
- change evs in .env.local.worklist-gateway file in pics repo (worklist
Oauth) to OAUTH_PROXY_ENDPOINT=host.docker.internal and
OAUTH_PROXY_PORT=9876
- run pics


![image](https://github.com/user-attachments/assets/248f2865-4bf3-47dd-83f4-7799931eeb77)
  • Loading branch information
andersonvcv authored Sep 24, 2024
2 parents 7eec31f + cb1ecf8 commit b3a8631
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/audit/audit_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,13 @@ func (c *Client) createAuditEntry(ss *sessions.SessionState, appURL string, tena
auditMessage, err := json.Marshal(auditObject)
if err != nil {
logger.Errorf("%s: could not marshal the audit object: %v", ErrPersitAuditEvent.Error(), err)
AuditErrorMetricCounter.Inc()
return
}
err = c.send(string(auditMessage))
if err != nil {
logger.Errorf("%s: could not send the audit message to the url '%s': %v", ErrPersitAuditEvent.Error(), c.opts.URL, err)
AuditErrorMetricCounter.Inc()
return
}
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/audit/audit_metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package audit

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

var AuditErrorMetricCounter = promauto.NewCounter(prometheus.CounterOpts{
Name: "oauth2_proxy_audit_errors_requests_total",
Help: "Total number of failed audit requests.",
})

0 comments on commit b3a8631

Please sign in to comment.