Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc] Add example of Custom Metrics via Kube-state-metrics CustomResourceStateMetrics #1159

Open
qeqar opened this issue Apr 5, 2023 · 2 comments · May be fixed by #1282
Open

[Doc] Add example of Custom Metrics via Kube-state-metrics CustomResourceStateMetrics #1159

qeqar opened this issue Apr 5, 2023 · 2 comments · May be fixed by #1282
Labels
carvel-accepted This issue should be considered for future work and that the triage process has been completed documentation This issue indicates a change to the docs should be considered enhancement This issue is a feature request good first issue An issue that will be a good candidate for a new contributor

Comments

@qeqar
Copy link

qeqar commented Apr 5, 2023

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 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="<metadata.name>",namespace="<metadata.namespace>"} 0

0 unpaused 1 paused

kappctrl_app_status{customresource_group="kappctrl.k14s.io",customresource_kind="App",customresource_version="v1alpha1",name="<metadata.name>",namespace="<metadata.namespace>",type="ReconcileSucceeded"} 1

Will add all the valid types from api definition

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="<metadata.name>",namespace="<metadata.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

@qeqar qeqar added carvel-triage This issue has not yet been reviewed for validity enhancement This issue is a feature request labels Apr 5, 2023
@100mik 100mik added documentation This issue indicates a change to the docs should be considered carvel-accepted This issue should be considered for future work and that the triage process has been completed and removed carvel-triage This issue has not yet been reviewed for validity labels Apr 5, 2023
@100mik
Copy link
Contributor

100mik commented Apr 5, 2023

Dragging some context here from our thread. We cannot reliably say that folks will have kube-state-metrics on their clusters. This is not something we can have out of the box with our releases.

However, we can point folks towards it in our docs and also tell users how they can update existing configuration to accommodate Apps as well!

Also marking this as a good first issue in case someone wants to take a swing at it.

@100mik 100mik added the good first issue An issue that will be a good candidate for a new contributor label Apr 5, 2023
@100mik 100mik changed the title Add Custom Metrics via Kube-state-metrics CustomResourceStateMetrics [Doc] Add example of Custom Metrics via Kube-state-metrics CustomResourceStateMetrics Apr 5, 2023
@AHB102
Copy link

AHB102 commented Aug 22, 2023

I am new to open source, can I try to solve this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
carvel-accepted This issue should be considered for future work and that the triage process has been completed documentation This issue indicates a change to the docs should be considered enhancement This issue is a feature request good first issue An issue that will be a good candidate for a new contributor
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

3 participants