From cb1ecf8886ee36e15f52ea6fbba71a46f8ecce9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anderson=20Val=C3=A9rio?= Date: Mon, 23 Sep 2024 15:48:29 -0300 Subject: [PATCH] add audit metric --- pkg/audit/audit_client.go | 2 ++ pkg/audit/audit_metrics.go | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 pkg/audit/audit_metrics.go diff --git a/pkg/audit/audit_client.go b/pkg/audit/audit_client.go index 2f60842d63..2603dfde23 100644 --- a/pkg/audit/audit_client.go +++ b/pkg/audit/audit_client.go @@ -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 } } diff --git a/pkg/audit/audit_metrics.go b/pkg/audit/audit_metrics.go new file mode 100644 index 0000000000..6522681679 --- /dev/null +++ b/pkg/audit/audit_metrics.go @@ -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.", +})