Skip to content

Commit

Permalink
Merge pull request #1926 from mrueg/crs-config-metrics
Browse files Browse the repository at this point in the history
Add metrics for CustomResource State Config file
  • Loading branch information
k8s-ci-robot committed Dec 8, 2022
2 parents 143f94d + eb3bdbc commit 448becb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,15 @@ please check the blog post [here](https://www.robustperception.io/exposing-the-s
Sharding metrics expose `--shard` and `--total-shards` flags and can be used to validate
run-time configuration, see [`/examples/prometheus-alerting-rules`](./examples/prometheus-alerting-rules).

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

```
kube_state_metrics_config_hash{type="config", filename="config.yml"} 4.0061079457904e+13
kube_state_metrics_config_last_reload_success_timestamp_seconds{type="config", filename="config.yml"} 1.6697483049487052e+09
kube_state_metrics_config_last_reload_successful{type="config", filename="config.yml"} 1
kube_state_metrics_config_hash{filename="crs.yml",type="customresourceconfig"} 2.38272279311849e+14
kube_state_metrics_config_hash{filename="config.yml",type="config"} 2.65285922340846e+14
kube_state_metrics_last_config_reload_success_timestamp_seconds{filename="crs.yml",type="customresourceconfig"} 1.6704882592037103e+09
kube_state_metrics_last_config_reload_success_timestamp_seconds{filename="config.yml",type="config"} 1.6704882592035313e+09
kube_state_metrics_last_config_reload_successful{filename="crs.yml",type="customresourceconfig"} 1
kube_state_metrics_last_config_reload_successful{filename="config.yml",type="config"} 1
```

### Scaling kube-state-metrics
Expand Down
13 changes: 13 additions & 0 deletions pkg/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ func RunKubeStateMetrics(ctx context.Context, opts *options.Options, factories .
configHash.WithLabelValues("config", filepath.Clean(got)).Set(hash)
}
}

if opts.CustomResourceConfigFile != "" {
crcFile, err := os.ReadFile(filepath.Clean(opts.CustomResourceConfigFile))
if err != nil {
return fmt.Errorf("failed to read custom resource config file: %v", err)
}
configSuccess.WithLabelValues("customresourceconfig", filepath.Clean(opts.CustomResourceConfigFile)).Set(1)
configSuccessTime.WithLabelValues("customresourceconfig", filepath.Clean(opts.CustomResourceConfigFile)).SetToCurrentTime()
hash := md5HashAsMetricValue(crcFile)
configHash.WithLabelValues("customresourceconfig", filepath.Clean(opts.CustomResourceConfigFile)).Set(hash)

}

var resources []string
switch {
case len(opts.Resources) == 0 && !opts.CustomResourcesOnly:
Expand Down

0 comments on commit 448becb

Please sign in to comment.