Skip to content

Commit

Permalink
chore: deprecate metrics code
Browse files Browse the repository at this point in the history
  • Loading branch information
shvgn committed May 19, 2021
1 parent 9a4c281 commit 5295207
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 44 deletions.
15 changes: 5 additions & 10 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,11 @@ func (c *client) Init() error {
}

if c.metricStorage != nil {
metrics.Register(
NewRequestLatencyMetric(c.metricStorage, c.metricLabels),
NewRequestResultMetric(c.metricStorage, c.metricLabels),
)
// client-go supports more metrics in v0.18.* versions
// metrics.Register(metrics.RegisterOpts{
// RequestLatency: NewRequestLatencyMetric(c.metricStorage, c.metricLabels),
// RateLimiterLatency: NewRateLimiterLatencyMetric(c.metricStorage, c.metricLabels),
// RequestResult: NewRequestResultMetric(c.metricStorage, c.metricLabels),
// })
metrics.Register(metrics.RegisterOpts{
RateLimiterLatency: NewRateLimiterLatencyMetric(c.metricStorage),
RequestLatency: NewRequestLatencyMetric(c.metricStorage, c.metricLabels),
RequestResult: NewRequestResultMetric(c.metricStorage, c.metricLabels),
})
}

cacheDiscoveryDir, err := ioutil.TempDir("", "kube-cache-discovery-*")
Expand Down
76 changes: 42 additions & 34 deletions client/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (
// Backends are used to send metrics from client-go to a Prometheus client.
// Backends are implemented interfaces from https:// github.com/kubernetes/client-go/blob/master/tools/metrics/metrics.go

// Extraction of methods from metric_storage.go to prevent cycle dependencies.
// Deprecated: MetricStorage contains methods from flant/shell-operator metric storage.
// The metrics support is to be deleted from this library. It is left for the time being.
type MetricStorage interface {
RegisterCounter(metric string, labels map[string]string) *prometheus.CounterVec
CounterAdd(metric string, value float64, labels map[string]string)
Expand All @@ -26,7 +27,7 @@ type MetricStorage interface {
HistogramObserve(metric string, value float64, labels map[string]string)
}

// RegisterMetrics defines metrics in Prometheus client.
// Deprecated: to be removed since it is not a part of the client to support
func RegisterMetrics(metricStorage MetricStorage, metricLabels map[string]string) {
labels := map[string]string{}
for k := range metricLabels {
Expand All @@ -46,20 +47,19 @@ func RegisterMetrics(metricStorage MetricStorage, metricLabels map[string]string
10, // 10 seconds
})

// TODO update client-go to v.0.18.*
// metricStorage.RegisterHistogramWithBuckets("{PREFIX}kubernetes_client_rate_limiter_latency_seconds",
// map[string]string{
// "verb": "",
// "url": "",
// },
// []float64{
// 0.0,
// 0.001, 0.002, 0.005, // 1,2,5 milliseconds
// 0.01, 0.02, 0.05, // 10,20,50 milliseconds
// 0.1, 0.2, 0.5, // 100,200,500 milliseconds
// 1, 2, 5, // 1,2,5 seconds
// 10, // 10 seconds
// })
metricStorage.RegisterHistogramWithBuckets("{PREFIX}kubernetes_client_rate_limiter_latency_seconds",
map[string]string{
"verb": "",
"url": "",
},
[]float64{
0.0,
0.001, 0.002, 0.005, // 1,2,5 milliseconds
0.01, 0.02, 0.05, // 10,20,50 milliseconds
0.1, 0.2, 0.5, // 100,200,500 milliseconds
1, 2, 5, // 1,2,5 seconds
10, // 10 seconds
})

labels = map[string]string{}
for k := range metricLabels {
Expand All @@ -72,15 +72,18 @@ func RegisterMetrics(metricStorage MetricStorage, metricLabels map[string]string
metricStorage.RegisterCounter("{PREFIX}kubernetes_client_request_result_total", labels)
}

// Deprecated: to be removed since it is not a part of the client to support
func NewRequestLatencyMetric(metricStorage MetricStorage, labels map[string]string) metrics.LatencyMetric {
return ClientRequestLatencyMetric{metricStorage, labels}
}

// Deprecated: to be removed since it is not a part of the client to support
type ClientRequestLatencyMetric struct {
metricStorage MetricStorage
labels map[string]string
}

// Deprecated: to be removed since it is not a part of the client to support
func (c ClientRequestLatencyMetric) Observe(verb string, u url.URL, latency time.Duration) {
labels := map[string]string{}
for k, v := range c.labels {
Expand All @@ -96,34 +99,39 @@ func (c ClientRequestLatencyMetric) Observe(verb string, u url.URL, latency time
)
}

// RateLimiterLAtenct metric for versions v0.18.*
// func NewRateLimiterLatencyMetric(metricStorage *metric_storage.MetricStorage) metrics.LatencyMetric {
// return ClientRateLimiterLatencyMetric{metricStorage}
// }
//
// type ClientRateLimiterLatencyMetric struct {
// metricStorage *metric_storage.MetricStorage
// }
//
// func (c ClientRateLimiterLatencyMetric) Observe(verb string, u url.URL, latency time.Duration) {
// c.metricStorage.HistogramObserve(
// "{PREFIX}kubernetes_client_rate_limiter_latency_seconds",
// latency.Seconds(),
// map[string]string{
// "verb": verb,
// "url": u.String(),
// })
// }
// Deprecated: to be removed since it is not a part of the client to support
func NewRateLimiterLatencyMetric(metricStorage MetricStorage) metrics.LatencyMetric {
return ClientRateLimiterLatencyMetric{metricStorage}
}

// Deprecated: to be removed since it is not a part of the client to support
type ClientRateLimiterLatencyMetric struct {
metricStorage MetricStorage
}

// Deprecated: to be removed since it is not a part of the client to support
func (c ClientRateLimiterLatencyMetric) Observe(verb string, u url.URL, latency time.Duration) {
c.metricStorage.HistogramObserve(
"{PREFIX}kubernetes_client_rate_limiter_latency_seconds",
latency.Seconds(),
map[string]string{
"verb": verb,
"url": u.String(),
})
}

// Deprecated: to be removed since it is not a part of the client to support
func NewRequestResultMetric(metricStorage MetricStorage, labels map[string]string) metrics.ResultMetric {
return ClientRequestResultMetric{metricStorage, labels}
}

// Deprecated: to be removed since it is not a part of the client to support
type ClientRequestResultMetric struct {
metricStorage MetricStorage
labels map[string]string
}

// Deprecated: to be removed since it is not a part of the client to support
func (c ClientRequestResultMetric) Increment(code, method, host string) {
labels := map[string]string{}
for k, v := range c.labels {
Expand Down

0 comments on commit 5295207

Please sign in to comment.