carvel-dev / carvel-dev/kapp-controller
[Doc] Add example of Custom Metrics via Kube-state-metrics CustomResourceStateMetrics
- Dominant language
- Go
- Stars
- 323
- Forks
- 127
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 6
Description
**Describe the problem/challenge you have**
The controller it self has a small number of Metrics available. This should be extended for proper Monitoring/Alerting.
I mostly use the APP resource and there a only some total counter, which does not represent the proper state of the app.
One solution would be to add them to the controller library, but that would need some coding and testing.
There is a easy solution to add metrics on CustomResources via the [kube-state-metrics CustomResourceStateMetrics ](https://github.com/kubernetes/kube-state-metrics/blob/main/docs/customresourcestate-metrics.md) project.
The kube-state-metrics is a K8S addons that is widely installed and already used for a lot of standard components like Deployments or Satefullsets.
**Describe the solution you'd like**
So the easies way would be to provide a predefined CustomResourceStateMetrics file for the controller.
bsp for app.kappctrl.k14s.io:
```
kind: CustomResourceStateMetrics
spec:
resources:
- groupVersionKind:
group: kappctrl.k14s.io
kind: App
version: v1alpha1
labelsFromPath:
name:
- metadata
- name
namespace:
- metadata
- namespace
metricNamePrefix: kappctrl_app
metrics:
- name: spec_paused
help: Whether the App is paused and any of its resources will not be processed by the controllers.
each:
gauge:
nilIsZero: true
path:
- spec
- paused
type: Gauge
- name: status
help: The app current status.
each:
type: Gauge
gauge:
nilIsZero: true
path: [ status, conditions ]
labelsFromPath:
type: [ "type" ]
valueFrom: [ "status" ]
```
This will result in two different Metrics per APP.
```
kappctrl_app_spec_paused{customresource_group="kappctrl.k14s.io",customresource_kind="App",customresource_version="v1alpha1",name="",namespace=""} 0
```
`0` unpaused `1` paused
```
kappctrl_app_status{customresource_group="kappctrl.k14s.io",customresource_kind="App",customresource_version="v1alpha1",name="",namespace="",type="ReconcileSucceeded"} 1
```
Will add all the valid types from [api definition](https://github.com/carvel-dev/kapp-controller/blob/develop/pkg/apis/kappctrl/v1alpha1/status.go#L28-L35)
Or a `0` if no `status.condition.type` is set
```
kappctrl_app_status{customresource_group="kappctrl.k14s.io",customresource_kind="App",customresource_version="v1alpha1",name="",namespace=""} 0
```
The spec file can be extended to all possible metrics some one need and all used resources f.e. package, packageRepositoy can be added.
For Adding it to any cluster use the [kube-state-metrics documentation](https://github.com/kubernetes/kube-state-metrics/blob/main/docs/customresourcestate-metrics.md)
Contributor guide
Research direction
Start with the kube-state-metrics CustomResourceStateMetrics documentation and pkg/apis/kappctrl/v1alpha1/status.go to verify the App metrics and valid condition types. Done means providing a predefined CustomResourceStateMetrics example for the agreed metrics, with any additional resources explicitly scoped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kubernetes
- Domain
- documentation, observability
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100