1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/metrics/client.go
Charles-Edouard Brétéché dfded5cc60
feat: propagate context to the metrics package (#5479)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2022-11-28 10:30:14 +00:00

39 lines
970 B
Go

package metrics
import "context"
type Recorder interface {
Record(clientQueryOperation ClientQueryOperation)
}
type clientQueryRecorder struct {
manager MetricsConfigManager
ns string
kind string
client ClientType
}
func NamespacedClientQueryRecorder(m MetricsConfigManager, ns, kind string, client ClientType) Recorder {
return &clientQueryRecorder{
manager: m,
ns: ns,
kind: kind,
client: client,
}
}
func ClusteredClientQueryRecorder(m MetricsConfigManager, kind string, client ClientType) Recorder {
return &clientQueryRecorder{
manager: m,
kind: kind,
client: client,
}
}
func (r *clientQueryRecorder) Record(clientQueryOperation ClientQueryOperation) {
r.RecordWithContext(context.TODO(), clientQueryOperation)
}
func (r *clientQueryRecorder) RecordWithContext(ctx context.Context, clientQueryOperation ClientQueryOperation) {
r.manager.RecordClientQueries(ctx, clientQueryOperation, r.client, r.kind, r.ns)
}