mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-29 09:42:25 +00:00
Update metric labeler for CE/Ent (#26537)
This commit is contained in:
@@ -8,26 +8,17 @@ import (
|
||||
"github.com/hashicorp/vault/internal/observability/event"
|
||||
)
|
||||
|
||||
var (
|
||||
_ event.Labeler = (*metricLabelerAuditSink)(nil)
|
||||
_ event.Labeler = (*metricLabelerAuditFallback)(nil)
|
||||
)
|
||||
var _ event.Labeler = (*metricLabelerAuditSink)(nil)
|
||||
|
||||
var (
|
||||
metricLabelAuditSinkSuccess = []string{"audit", "sink", "success"}
|
||||
metricLabelAuditSinkFailure = []string{"audit", "sink", "failure"}
|
||||
metricLabelAuditFallbackSuccess = []string{"audit", "fallback", "success"}
|
||||
metricLabelAuditFallbackMiss = []string{"audit", "fallback", "miss"}
|
||||
metricLabelAuditSinkSuccess = []string{"audit", "sink", "success"}
|
||||
metricLabelAuditSinkFailure = []string{"audit", "sink", "failure"}
|
||||
)
|
||||
|
||||
// metricLabelerAuditSink can be used to provide labels for the success or failure
|
||||
// of a sink node used for a normal audit device.
|
||||
type metricLabelerAuditSink struct{}
|
||||
|
||||
// metricLabelerAuditFallback can be used to provide labels for the success or failure
|
||||
// of a sink node used for an audit fallback device.
|
||||
type metricLabelerAuditFallback struct{}
|
||||
|
||||
// Labels provides the success and failure labels for an audit sink, based on the error supplied.
|
||||
// Success: 'vault.audit.sink.success'
|
||||
// Failure: 'vault.audit.sink.failure'
|
||||
@@ -38,20 +29,3 @@ func (m metricLabelerAuditSink) Labels(_ *eventlogger.Event, err error) []string
|
||||
|
||||
return metricLabelAuditSinkSuccess
|
||||
}
|
||||
|
||||
// Labels provides the success and failures labels for an audit fallback sink, based on the error supplied.
|
||||
// Success: 'vault.audit.fallback.success'
|
||||
// Failure: 'vault.audit.sink.failure'
|
||||
func (m metricLabelerAuditFallback) Labels(_ *eventlogger.Event, err error) []string {
|
||||
if err != nil {
|
||||
return metricLabelAuditSinkFailure
|
||||
}
|
||||
|
||||
return metricLabelAuditFallbackSuccess
|
||||
}
|
||||
|
||||
// MetricLabelsFallbackMiss returns the labels which indicate an audit entry was missed.
|
||||
// 'vault.audit.fallback.miss'
|
||||
func MetricLabelsFallbackMiss() []string {
|
||||
return metricLabelAuditFallbackMiss
|
||||
}
|
||||
|
||||
@@ -41,35 +41,3 @@ func TestMetricLabelerAuditSink_Label(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMetricLabelerAuditFallback_Label ensures we always get the right label based
|
||||
// on the input value of the error for fallback devices.
|
||||
func TestMetricLabelerAuditFallback_Label(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := map[string]struct {
|
||||
err error
|
||||
expected []string
|
||||
}{
|
||||
"nil": {
|
||||
err: nil,
|
||||
expected: []string{"audit", "fallback", "success"},
|
||||
},
|
||||
"error": {
|
||||
err: errors.New("I am an error"),
|
||||
expected: []string{"audit", "sink", "failure"},
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range tests {
|
||||
name := name
|
||||
tc := tc
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
m := &metricLabelerAuditFallback{}
|
||||
result := m.Labels(nil, tc.err)
|
||||
assert.Equal(t, tc.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user