@@ -56,6 +56,7 @@ import (
56
56
" k8s.io/metrics/pkg/apis/custom_metrics"
57
57
58
58
" sigs.k8s.io/custom-metrics-apiserver/pkg/provider"
59
+ " sigs.k8s.io/custom-metrics-apiserver/pkg/provider/defaults"
59
60
" sigs.k8s.io/custom-metrics-apiserver/pkg/provider/helpers"
60
61
)
61
62
```
@@ -76,35 +77,14 @@ type CustomMetricsProvider interface {
76
77
First, there's a method for listing all metrics available at any point in
77
78
time. It's used to populate the discovery information in the API, so that
78
79
clients 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.
81
81
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)
108
88
109
89
Next, you'll need to implement the methods that actually fetch the
110
90
metrics. There are methods for fetching metrics describing arbitrary Kubernetes
@@ -189,6 +169,8 @@ already have sufficient information in your metrics pipeline:
189
169
190
170
``` go
191
171
type yourProvider struct {
172
+ defaults.DefaultCustomMetricsProvider
173
+ defaults.DefaultExternalMetricsProvider
192
174
client dynamic.Interface
193
175
mapper apimeta.RESTMapper
194
176
0 commit comments