Skip to content

Commit eb3bdbc

Browse files
committed
Add metrics for CustomResourceConfig file
1 parent 143f94d commit eb3bdbc

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,15 @@ please check the blog post [here](https://www.robustperception.io/exposing-the-s
165165
Sharding metrics expose `--shard` and `--total-shards` flags and can be used to validate
166166
run-time configuration, see [`/examples/prometheus-alerting-rules`](./examples/prometheus-alerting-rules).
167167

168-
kube-state-metrics also exposes metrics about it config file:
168+
kube-state-metrics also exposes metrics about it config file and the Custom Resource State config file:
169169

170170
```
171-
kube_state_metrics_config_hash{type="config", filename="config.yml"} 4.0061079457904e+13
172-
kube_state_metrics_config_last_reload_success_timestamp_seconds{type="config", filename="config.yml"} 1.6697483049487052e+09
173-
kube_state_metrics_config_last_reload_successful{type="config", filename="config.yml"} 1
171+
kube_state_metrics_config_hash{filename="crs.yml",type="customresourceconfig"} 2.38272279311849e+14
172+
kube_state_metrics_config_hash{filename="config.yml",type="config"} 2.65285922340846e+14
173+
kube_state_metrics_last_config_reload_success_timestamp_seconds{filename="crs.yml",type="customresourceconfig"} 1.6704882592037103e+09
174+
kube_state_metrics_last_config_reload_success_timestamp_seconds{filename="config.yml",type="config"} 1.6704882592035313e+09
175+
kube_state_metrics_last_config_reload_successful{filename="crs.yml",type="customresourceconfig"} 1
176+
kube_state_metrics_last_config_reload_successful{filename="config.yml",type="config"} 1
174177
```
175178

176179
### Scaling kube-state-metrics

pkg/app/server.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,19 @@ func RunKubeStateMetrics(ctx context.Context, opts *options.Options, factories .
143143
configHash.WithLabelValues("config", filepath.Clean(got)).Set(hash)
144144
}
145145
}
146+
147+
if opts.CustomResourceConfigFile != "" {
148+
crcFile, err := os.ReadFile(filepath.Clean(opts.CustomResourceConfigFile))
149+
if err != nil {
150+
return fmt.Errorf("failed to read custom resource config file: %v", err)
151+
}
152+
configSuccess.WithLabelValues("customresourceconfig", filepath.Clean(opts.CustomResourceConfigFile)).Set(1)
153+
configSuccessTime.WithLabelValues("customresourceconfig", filepath.Clean(opts.CustomResourceConfigFile)).SetToCurrentTime()
154+
hash := md5HashAsMetricValue(crcFile)
155+
configHash.WithLabelValues("customresourceconfig", filepath.Clean(opts.CustomResourceConfigFile)).Set(hash)
156+
157+
}
158+
146159
var resources []string
147160
switch {
148161
case len(opts.Resources) == 0 && !opts.CustomResourcesOnly:

0 commit comments

Comments
 (0)