Git Product home page Git Product logo

mercedes-benz / cluster-api-state-metrics Goto Github PK

View Code? Open in Web Editor NEW
60.0 11.0 7.0 116 KB

THIS PROJECT IS NO LONGER MAINTAINED AND IS ARCHIVED. cluster-api-state-metrics (CASM) is a service that listens to the Kubernetes API server and generates metrics about the state of custom resource objects related of Kubernetes Cluster API.

License: MIT License

Dockerfile 0.32% Makefile 7.47% Shell 7.20% Go 82.90% Smarty 2.11%

cluster-api-state-metrics's Introduction

CI FOSS Scan

This project is no longer maintained and is archived

A new feature in kube-state-metrics that allows the generation of metrics for custom resources and the integration of that in core CAPI has made the present cluster-api-state-metrics project obsolete. For more information see following:

We thank all contributors for their awesome work and @chrischdi for starting this as a whole.

Overview

cluster-api-state-metrics (CASM) is a service that listens to the Kubernetes API server and generates metrics about the state of custom resource objects related of Kubernetes Cluster API. This project is highly inspired by kube-state-metrics and shares some codebase with it and resources which are in scope for kube-state-metrics are not scope of cluster-api-state-metrics.

The metrics are exported on the HTTP endpoint /metrics via http (default port 8080) and are served as plaintext. The endpoint is designed to get consumed by Prometheus or a scraper which is compatible with a Prometheus client endpoint. Kubernetes custom resource objects which get deleted are no longer visible to the /metrics endpoint.

Versioning

Kubernetes Version

cluster-api-state-metrics uses the client of controller-runtime to talk with Kubernetes clusters. Because of that the supported Kubernetes cluster version is determined by controller-runtime.

Kubernetes Cluster API Version

Resources of Cluster API can evolve, i.e. the group version for a resource may change from alpha to beta and finally GA in a more recent Cluster API version.

Cluster API provides conversion webhooks for its custom resource definitions. By that cluster-api-state-metrics may be compatible to different versions of Cluster API.

casm \ capi v1alpha3 v1alpha4 v1beta1
v0.1.0 - (✓)
main - (✓)
  • Imported version used
  • (✓) Version supported via conversion webhooks.
  • - Not supported

Usage Documentation

CLI Arguments

cluster-api-state-metrics -h
Usage of ./bin/cluster-api-state-metrics:
      --add_dir_header                        If true, adds the file directory to the header of the log messages
      --alsologtostderr                       log to standard error as well as files
      --apiserver string                      The URL of the apiserver to use as a master
      --enable-gzip-encoding                  Gzip responses when requested by clients via 'Accept-Encoding: gzip' header.
  -h, --help                                  Print Help text
      --host string                           Host to expose metrics on. (default "::")
      --kubeconfig string                     Absolute path to the kubeconfig file
      --log_backtrace_at traceLocation        when logging hits line file:N, emit a stack trace (default :0)
      --log_dir string                        If non-empty, write log files in this directory
      --log_file string                       If non-empty, use this log file
      --log_file_max_size uint                Defines the maximum size a log file can grow to. Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
      --logtostderr                           log to standard error instead of files (default true)
      --metric-allowlist string               Comma-separated list of metrics to be exposed. This list comprises of exact metric names and/or regex patterns. The allowlist and denylist are mutually exclusive.
      --metric-annotations-allowlist string   Comma-separated list of Kubernetes annotations keys that will be used in the resource' labels metric. By default the metric contains only name and namespace labels. To include additional annotations provide a list of resource names in their plural form and Kubernetes annotation keys you would like to allow for them (Example: '=namespaces=[kubernetes.io/team,...],pods=[kubernetes.io/team],...)'. A single '*' can be provided per resource instead to allow any annotations, but that has severe performance implications (Example: '=pods=[*]').
      --metric-denylist string                Comma-separated list of metrics not to be enabled. This list comprises of exact metric names and/or regex patterns. The allowlist and denylist are mutually exclusive.
      --metric-labels-allowlist string        Comma-separated list of additional Kubernetes label keys that will be used in the resource' labels metric. By default the metric contains only name and namespace labels. To include additional labels provide a list of resource names in their plural form and Kubernetes label keys you would like to allow for them (Example: '=namespaces=[k8s-label-1,k8s-label-n,...],pods=[app],...)'. A single '*' can be provided per resource instead to allow any labels, but that has severe performance implications (Example: '=pods=[*]').
      --metric-opt-in-list string             Comma-separated list of metrics which are opt-in and not enabled by default. This is in addition to the metric allow- and denylists
      --namespaces string                     Comma-separated list of namespaces to be enabled. Defaults to ""
      --namespaces-denylist string            Comma-separated list of namespaces not to be enabled. If namespaces and namespaces-denylist are both set, only namespaces that are excluded in namespaces-denylist will be used.
      --one_output                            If true, only write logs to their native severity level (vs also writing to each lower severity level)
      --pod string                            Name of the pod that contains the kube-state-metrics container. When set, it is expected that --pod and --pod-namespace are both set. Most likely this should be passed via the downward API. This is used for auto-detecting sharding. If set, this has preference over statically configured sharding. This is experimental, it may be removed without notice.
      --pod-namespace string                  Name of the namespace of the pod specified by --pod. When set, it is expected that --pod and --pod-namespace are both set. Most likely this should be passed via the downward API. This is used for auto-detecting sharding. If set, this has preference over statically configured sharding. This is experimental, it may be removed without notice.
      --port int                              Port to expose metrics on. (default 8080)
      --resources string                      Comma-separated list of Resources to be enabled. Defaults to "clusters,kubeadmcontrolplanes,machinedeployments,machines,machinesets"
      --shard int32                           The instances shard nominal (zero indexed) within the total number of shards. (default 0)
      --skip_headers                          If true, avoid header prefixes in the log messages
      --skip_log_headers                      If true, avoid headers when opening log files
      --stderrthreshold severity              logs at or above this threshold go to stderr (default 2)
      --telemetry-host string                 Host to expose kube-state-metrics self metrics on. (default "::")
      --telemetry-port int                    Port to expose kube-state-metrics self metrics on. (default 8081)
      --tls-config string                     Path to the TLS configuration file
      --total-shards int                      The total number of shards. Sharding is disabled when total shards is set to 1. (default 1)
      --use-apiserver-cache                   Sets resourceVersion=0 for ListWatch requests, using cached resources from the apiserver instead of an etcd quorum read.
  -v, --v Level                               number for the log level verbosity
      --version                               kube-state-metrics build version information
      --vmodule moduleSpec                    comma-separated list of pattern=N settings for file-filtered logging

Building binary from source

To build cluster-api-state-metrics from the source code yourself you need to have a working Go environment with version 1.17 or greater installed.

git clone https://github.com/daimler/cluster-api-state-metrics.git
cd cluster-api-state-metrics
make build

The Makefile provides several targets:

Usage:
  make <target>

General
  help             Display this help.

Development
  manifests        Generate WebhookConfiguration, ClusterRole objects, and role templates for the helm chart.
  generate         Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
  fmt              Run go fmt against code.
  vet              Run go vet against code.
  lint             Run golangci-lint against code.
  spdxcheck        Run spdx check against all files.
  doccheck         Run docs specific checks
  test             Run tests.

Build
  docs             Regenerate docs
  build            Build manager binary.
  image            Build container image
  push             Push container image
  run              Run a controller from your host.

Deployment
  template         Create kustomized deployment yaml.
  deploy           Deploy controller to the K8s cluster specified in ~/.kube/config.
  helm-deploy      Deploy cluster-api-state-metrics chart to the K8s cluster specified in ~/.kube/config.
  undeploy         Undeploy controller from the K8s cluster specified in ~/.kube/config.
  helm-undeploy    Uninstall the cluster-api-state-metrics chart from the K8s cluster specified in ~/.kube/config.

Metrics Documentation

Metrics will be made available on port 8080 by default. Alternatively it is possible to pass the commandline flag -addr to override the port. An overview of all metrics can be found in metrics.md.

Contributing

We welcome any contributions. If you want to contribute to this project, please read the contributing guide.

License

Full information on the license for this software is available in the LICENSE file.

Parts of the software are marked to be licensed under Apache 2.0 which is due to this files got copied and modified from kube-state-metrics. Changes to this files are noted at the top of the file.

The latest artifacts of the foss-scan which includes the notices file for third party licenses and risk report are available at the artifacts section of the last FOSS Scan workflow.

Provider Information

Please visit https://www.daimler-tss.com/en/imprint/ for information on the provider.

Notice: Before you use the program in productive use, please take all necessary precautions, e.g. testing and verifying the program with regard to your specific use. The program was tested solely for our own use cases, which might differ from yours.

cluster-api-state-metrics's People

Contributors

chrischdi avatar dependabot[bot] avatar johannesfrey avatar mehyedes avatar tobiasgiese avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cluster-api-state-metrics's Issues

Add kubeadmControlPlane status.condition metric

Just like for machines, where we have the metric capi_machine_status_condition, I believe it might be useful to add a similar metric capi_kubeadmcontrolplane_status_condition for kubeadmControlPlanes as it provides more visibility about the actual state of the CP and would be really handy when configuring related alerts.

What do you think?

Add helm chart

At the moment, the only way to deploy is to use make deploy(or kubectl apply). However, it would be really great if there was a helm chart available for the project.

Since we have been using the project for some time, we have already built a helm chart internally. So, I would be happy to work on this.

Let me know your thoughts about this 🙂

Remove deprecated klog flags

With K8s v1.23 many klog flags are deprecated.
Reference: https://kubernetes.io/docs/concepts/cluster-administration/system-logs/#klog

We should consider to replace the following:

{{- if .Values.config.addDirHeader }}
- --add_dir_header
{{- end }}
{{- if .Values.config.alsoLogtoStderr }}
- --alsologtostderr
{{- end }}
{{- if .Values.config.enableGzipEncoding }}
- --enable-gzip-encoding
{{- end }}
{{- if .Values.config.logBacktraceAt }}
- --log_backtrace_at
- {{ .Values.config.logBacktraceAt | quote }}
{{- end }}
{{- if .Values.config.logDir }}
- --log_dir
- {{ .Values.config.logDir }}
{{- end }}
{{- if .Values.config.logFile }}
- --log_file
- {{ .Values.config.logFile }}
{{- end }}
{{- if .Values.config.logFileMaxSize }}
- --log_file_max_size
- {{ .Values.config.logFileMaxSize | quote }}
{{- end }}
{{- if .Values.config.logLevel }}
- --v
- {{ .Values.config.logLevel | quote }}
{{- end }}
- --logtostderr
- {{ .Values.config.logToStderr | quote }}

Implement e2e test using CAPD and kind

CI currently only executes unit tests.

Similar to Cluster API another github action could:

  • create a kind cluster
  • deploy capd to kind cluster
  • deploy casm to kind cluster
  • deploy a cluster using capd
  • check if entries for all metrics exist
Christian Schlotter , Daimler TSS GmbH, Provider Information

Find a proper destination registry

Pulling images from githubs package registry requires authentication.

Because of that make deploy does not work out of the box.

Alternatives would be for example:

  • quay.io
  • hub.docker.com

We have to first determine Daimler internally what would be okay to use for us as team.

Workaround:

REGISTRY=my-registry/repository make image
REGISTRY=my-registry/repository make push
sed -i '[email protected]/daimler/[email protected]/schloc@g' config/default/kustomization.yaml
sed -i "s/latest/$(git describe --tags --exact-match 2>/dev/null || git rev-parse HEAD)/" config/default/kustomization.yaml
make deploy
Christian Schlotter , Daimler TSS GmbH, Provider Information

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.