@@ -56,6 +56,7 @@ import (
5656 " k8s.io/metrics/pkg/apis/custom_metrics"
5757
5858 " sigs.k8s.io/custom-metrics-apiserver/pkg/provider"
59+ " sigs.k8s.io/custom-metrics-apiserver/pkg/provider/defaults"
5960 " sigs.k8s.io/custom-metrics-apiserver/pkg/provider/helpers"
6061)
6162```
@@ -76,35 +77,14 @@ type CustomMetricsProvider interface {
7677First, there's a method for listing all metrics available at any point in
7778time. It's used to populate the discovery information in the API, so that
7879clients can know what metrics are available. It's not allowed to fail (it
79- doesn't return any error), and it should return quickly, so it's suggested
80- that you update it asynchronously in real-world code.
80+ doesn't return any error), and it should return quickly.
8181
82- For this walkthrough, you can just return a few statically-named metrics,
83- two that are namespaced, and one that's on namespaces themselves, and thus
84- root-scoped:
85-
86- ``` go
87- func (p *yourProvider ) ListAllMetrics () []provider .CustomMetricInfo {
88- return []provider.CustomMetricInfo {
89- // these are mostly arbitrary examples
90- {
91- GroupResource: schema.GroupResource {Group: " " , Resource: " pods" },
92- Metric: " packets-per-second" ,
93- Namespaced: true ,
94- },
95- {
96- GroupResource: schema.GroupResource {Group: " " , Resource: " services" },
97- Metric: " connections-per-second" ,
98- Namespaced: true ,
99- },
100- {
101- GroupResource: schema.GroupResource {Group: " " , Resource: " namespaces" },
102- Metric: " work-queue-length" ,
103- Namespaced: false ,
104- },
105- }
106- }
107- ```
82+ You can list your metrics (asynchronously) and return them on every request.
83+ This is not mandatory because kubernetes can request metric values without
84+ listing them before, but maybe there are some cases where is useful. To
85+ provide a unified solution, a default implementation is provided thanks to
86+ ` DefaultCustomMetricsProvider ` (and ` DefaultExternalMetricsProvider ` for
87+ external metrics)
10888
10989Next, you'll need to implement the methods that actually fetch the
11090metrics. There are methods for fetching metrics describing arbitrary Kubernetes
@@ -189,6 +169,8 @@ already have sufficient information in your metrics pipeline:
189169
190170``` go
191171type yourProvider struct {
172+ defaults.DefaultCustomMetricsProvider
173+ defaults.DefaultExternalMetricsProvider
192174 client dynamic.Interface
193175 mapper apimeta.RESTMapper
194176
0 commit comments