mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-06 17:57:51 +00:00
feat: use Default metric providers
Signed-off-by: Jorge Turrado <jorge_turrado@hotmail.es>
This commit is contained in:
parent
27eb607509
commit
37f6ffb4b5
8 changed files with 271 additions and 598 deletions
|
|
@ -37,6 +37,7 @@ import (
|
|||
"k8s.io/metrics/pkg/apis/custom_metrics"
|
||||
|
||||
"sigs.k8s.io/custom-metrics-apiserver/pkg/provider"
|
||||
"sigs.k8s.io/custom-metrics-apiserver/pkg/provider/defaults"
|
||||
"sigs.k8s.io/custom-metrics-apiserver/pkg/provider/helpers"
|
||||
|
||||
prom "sigs.k8s.io/prometheus-adapter/pkg/client"
|
||||
|
|
@ -56,6 +57,7 @@ type prometheusProvider struct {
|
|||
kubeClient dynamic.Interface
|
||||
promClient prom.Client
|
||||
|
||||
defaults.DefaultCustomMetricsProvider
|
||||
SeriesRegistry
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,8 +84,10 @@ var _ = Describe("Custom Metrics Provider", func() {
|
|||
By("setting up the provider")
|
||||
prov, fakeProm := setupPrometheusProvider()
|
||||
|
||||
By("ensuring that no metrics are present before we start listing")
|
||||
Expect(prov.ListAllMetrics()).To(BeEmpty())
|
||||
expected := provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: ""}, Namespaced: false, Metric: "custom_metric"}
|
||||
|
||||
By("listing all metrics, and checking that they contain the expected results")
|
||||
Expect(prov.ListAllMetrics()).To(ConsistOf(expected))
|
||||
|
||||
By("setting the acceptable interval to now until the next update, with a bit of wiggle room")
|
||||
startTime := pmodel.Now().Add(-1*fakeProviderUpdateInterval - fakeProviderUpdateInterval/10)
|
||||
|
|
@ -97,17 +99,6 @@ var _ = Describe("Custom Metrics Provider", func() {
|
|||
Expect(lister.updateMetrics()).To(Succeed())
|
||||
|
||||
By("listing all metrics, and checking that they contain the expected results")
|
||||
Expect(prov.ListAllMetrics()).To(ConsistOf(
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "services"}, Namespaced: true, Metric: "ingress_hits"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Group: "extensions", Resource: "ingresses"}, Namespaced: true, Metric: "ingress_hits"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "pods"}, Namespaced: true, Metric: "ingress_hits"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "namespaces"}, Namespaced: false, Metric: "ingress_hits"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "services"}, Namespaced: true, Metric: "service_proxy_packets"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "namespaces"}, Namespaced: false, Metric: "service_proxy_packets"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Group: "extensions", Resource: "deployments"}, Namespaced: true, Metric: "work_queue_wait"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "namespaces"}, Namespaced: false, Metric: "work_queue_wait"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "namespaces"}, Namespaced: false, Metric: "some_usage"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "pods"}, Namespaced: true, Metric: "some_usage"},
|
||||
))
|
||||
Expect(prov.ListAllMetrics()).To(ConsistOf(expected))
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -50,8 +50,6 @@ type SeriesRegistry interface {
|
|||
// SetSeries replaces the known series in this registry.
|
||||
// Each slice in series should correspond to a MetricNamer in namers.
|
||||
SetSeries(series [][]prom.Series, namers []naming.MetricNamer) error
|
||||
// ListAllMetrics lists all metrics known to this registry
|
||||
ListAllMetrics() []provider.CustomMetricInfo
|
||||
// SeriesForMetric looks up the minimum required series information to make a query for the given metric
|
||||
// against the given resource (namespace may be empty for non-namespaced resources)
|
||||
QueryForMetric(info provider.CustomMetricInfo, namespace string, metricSelector labels.Selector, resourceNames ...string) (query prom.Selector, found bool)
|
||||
|
|
@ -131,13 +129,6 @@ func (r *basicSeriesRegistry) SetSeries(newSeriesSlices [][]prom.Series, namers
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *basicSeriesRegistry) ListAllMetrics() []provider.CustomMetricInfo {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
|
||||
return r.metrics
|
||||
}
|
||||
|
||||
func (r *basicSeriesRegistry) QueryForMetric(metricInfo provider.CustomMetricInfo, namespace string, metricSelector labels.Selector, resourceNames ...string) (prom.Selector, bool) {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
|
|
|
|||
|
|
@ -278,27 +278,5 @@ var _ = Describe("Series Registry", func() {
|
|||
Expect(outputQuery).To(Equal(prom.Selector(tc.expectedQuery)))
|
||||
})
|
||||
}
|
||||
|
||||
It("should list all metrics", func() {
|
||||
Expect(registry.ListAllMetrics()).To(ConsistOf(
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "pods"}, Namespaced: true, Metric: "some_count"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "namespaces"}, Namespaced: false, Metric: "some_count"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "pods"}, Namespaced: true, Metric: "some_time"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "namespaces"}, Namespaced: false, Metric: "some_time"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "pods"}, Namespaced: true, Metric: "some_usage"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "namespaces"}, Namespaced: false, Metric: "some_usage"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "services"}, Namespaced: true, Metric: "ingress_hits"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Group: "extensions", Resource: "ingresses"}, Namespaced: true, Metric: "ingress_hits"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "pods"}, Namespaced: true, Metric: "ingress_hits"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "namespaces"}, Namespaced: false, Metric: "ingress_hits"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "services"}, Namespaced: true, Metric: "service_proxy_packets"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "namespaces"}, Namespaced: false, Metric: "service_proxy_packets"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Group: "extensions", Resource: "deployments"}, Namespaced: true, Metric: "work_queue_wait"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "namespaces"}, Namespaced: false, Metric: "work_queue_wait"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "nodes"}, Namespaced: false, Metric: "node_gigawatts"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "persistentvolumes"}, Namespaced: false, Metric: "volume_claims"},
|
||||
provider.CustomMetricInfo{GroupResource: schema.GroupResource{Resource: "nodes"}, Namespaced: false, Metric: "node_fan"},
|
||||
))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue