1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-15 17:51:20 +00:00
kyverno/pkg/metrics/client.go
Charles-Edouard Brétéché 39b72eefb9
feat: add http clients tracing (#5630)
* feat: add http clients tracing

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* check we are in a span before creating one and and context to metrics recording calls

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Co-authored-by: shuting <shuting@nirmata.com>
2022-12-09 09:09:11 +00:00

40 lines
1,007 B
Go

package metrics
import "context"
type Recorder interface {
Record(ClientQueryOperation)
RecordWithContext(context.Context, 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)
}