Skip to content

Commit

Permalink
Merge pull request #1 from alex123012/new-version-0.5.0
Browse files Browse the repository at this point in the history
Version 0.5.0
  • Loading branch information
alex123012 authored Nov 2, 2022
2 parents 3cbea4a + 765ceef commit e997dc0
Show file tree
Hide file tree
Showing 14 changed files with 496 additions and 62 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Binaries for programs and plugins
test_*.yaml
charts/annotations-exporter/dashboards
bin
*.exe
*.exe~
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= 0.4.0
VERSION ?= 0.5.0

# Image URL to use all building/pushing image targets
IMG ?= ghcr.io/alex123012/annotations-exporter:v$(VERSION)
Expand Down
81 changes: 54 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,33 @@
Prometheus-exporter, which converts any Kubernetes resources annotations and labels to Prometheus samples.

## Usage
```
```text
Usage of annotations-exporter:
-h, --help
help for annotations-exporter
--kube.annotations strings
Annotations names to use in prometheus metric labels
--kube.labels strings
Labels names to use in prometheus metric labels
--kube.max-revisions int
Max revisions of resource labels to store (default 3)
--kube.namespaces strings
Specifies the namespace that the exporter will monitor resources in (default 'all namespaces')
--kube.resources strings
Resources (<resource>/<version>/<api> or <resource>/<api>) to export labels and annotations (default [deployments/apps,ingresses/v1/networking.k8s.io,statefulsets/apps,daemonsets/apps])
-v, --version
version for annotations-exporter
-h, --help help for annotations-exporter
--kube.annotations strings Annotations names to use in prometheus metric labels
--kube.config string Path to kubeconfig (optional)
--kube.labels strings Labels names to use in prometheus metric labels
--kube.max-revisions int Max revisions of resource labels to store (default 3)
--kube.namespaces strings Specifies the namespace that the exporter will monitor resources in (default 'all namespaces')
--kube.only-labels-and-annotations Export only labels and annotations defined by flags (default false)
--kube.reference-annotations strings Annotations names to use in prometheus metric labels and for count revisions (reference names)
--kube.reference-labels strings Labels names to use in prometheus metric labels and for count revisions (reference names)
--kube.resources strings Resources (<resource>/<version>/<api> or <resource>/<api>) to export labels and annotations (default [deployments/apps,ingresses/v1/networking.k8s.io,statefulsets/apps,daemonsets/apps])
--server.exporter-address string Address to export prometheus metrics (default ":8000")
--server.log-level string Log level
-v, --version version for annotations-exporter
```

## Install
Expand All @@ -42,18 +53,18 @@ The first version of helm chart is available.
## How it works

Exporter will create one metric `kube_annotations_exporter` with constant labels:
* api_version - kubernetes resource apiVersion
* kind - kubernetes resource Kind
* namespace - - kubernetes resource namespace
* name - kubernetes resource name
* annotations_exporter_api_version - kubernetes resource apiVersion
* annotations_exporter_kind - kubernetes resource Kind
* annotations_exporter_namespace - - kubernetes resource namespace
* annotations_exporter_name - kubernetes resource name

Other labels would be specified resource labels and annotations. For all specifeied kubernetes annotations and labels corresponding prometheus label would be lowercased and have replaced `/`, `-`, `.` symbols for `_`.

All kubernetes labels would have prefix `kube_label_` in corresponding prometheus label and all kubernetes annotations would have prefix `kube_annotation_`.
All kubernetes labels would have prefix `annotations_exporter_label_` in corresponding prometheus label and all kubernetes annotations would have prefix `annotations_exporter_annotation_`.
For example, if we run annotations exporter with flags:
`--kube.annotations=ci.werf.io/commit,gitlab.ci.werf.io/pipeline-url` and `--kube.labels=app`, it will create, for example for deployment, metrics like this:
```text
kube_annotations_exporter{api_version="apps/v1",kind="Deployment",kube_annotation_ci_werf_io_commit="<deployment-annotation-value>",kube_annotation_gitlab_ci_werf_io_pipeline_url="<deployment-annotation-value>",kube_label_app="<deployment-label-value>",name="<deployment-name>",namespace="<deployment-namespace>",revision="0"}
kube_annotations_exporter{annotations_exporter_api_version="apps/v1",annotations_exporter_kind="Deployment",annotations_exporter_annotation_ci_werf_io_commit="<deployment-annotation-value>",annotations_exporter_annotation_gitlab_ci_werf_io_pipeline_url="<deployment-annotation-value>",annotations_exporter_label_app="<deployment-label-value>",annotations_exporter_name="<deployment-name>",annotations_exporter_namespace="<deployment-namespace>",annotations_exporter_revision="0"}
```

Also, there is additional label `revision` - this label is for storing older values of annotation values.
Expand All @@ -66,25 +77,41 @@ If we update some resource and provided label or annotation changes - older metr
now metric for `nginx` deployment would be:

```text
kube_annotations_exporter{api_version="apps/v1",kind="Deployment",kube_label_app="nginx",name="nginx",namespace="default",revision="0"}
kube_annotations_exporter{annotations_exporter_api_version="apps/v1",annotations_exporter_kind="Deployment",annotations_exporter_label_app="nginx",annotations_exporter_name="nginx",annotations_exporter_namespace="default",revision="0"}
```

if we update label `app` to `nginx-external` in `nginx` deployment, there would be one more metric for this deployment:
```text
kube_annotations_exporter{api_version="apps/v1",kind="Deployment",kube_label_app="nginx",name="nginx",namespace="default",revision="1"}
kube_annotations_exporter{annotations_exporter_api_version="apps/v1",annotations_exporter_kind="Deployment",annotations_exporter_label_app="nginx",annotations_exporter_name="nginx",annotations_exporter_namespace="default",revision="1"}
kube_annotations_exporter{api_version="apps/v1",kind="Deployment",kube_label_app="nginx-external",name="nginx",namespace="default",revision="0"}
kube_annotations_exporter{annotations_exporter_api_version="apps/v1",annotations_exporter_kind="Deployment",annotations_exporter_label_app="nginx-external",annotations_exporter_name="nginx",annotations_exporter_namespace="default",annotations_exporter_revision="0"}
```

Now, if we another time update label `app`, for example, to `nginx-app`, metrics would be:
```text
kube_annotations_exporter{api_version="apps/v1",kind="Deployment",kube_label_app="nginx-app",name="nginx",namespace="default",revision="0"}
kube_annotations_exporter{annotations_exporter_api_version="apps/v1",annotations_exporter_kind="Deployment",annotations_exporter_label_app="nginx-app",annotations_exporter_name="nginx",annotations_exporter_namespace="default",revision="0"}
kube_annotations_exporter{api_version="apps/v1",kind="Deployment",kube_label_app="nginx-external",name="nginx",namespace="default",revision="1"}
kube_annotations_exporter{annotations_exporter_api_version="apps/v1",annotations_exporter_kind="Deployment",annotations_exporter_label_app="nginx-external",annotations_exporter_name="nginx",namespace="default",annotations_exporter_revision="1"}
```

etc.

### Only Labels And Annotations
if `--kube.only-labels-and-annotations` flag provided - exporter won't collect resource meta for metrics (`apiVersion`, `kind`, `name`, `namespace`) and will only expose collected annotations and labels. This is useful when combined with `--kube.reference-annotations` and `--kube.reference-labels` to expose, for example, helm release name and namespace:

```bash
./annotations-exporter --kube.annotations=gitlab.ci.werf.io/pipeline-url --kube.only-labels-and-annotations=true --kube.reference-annotations=meta.helm.sh/release-name,meta.helm.sh/release-namespace
```
This will track revisions for `meta.helm.sh/release-name` and `meta.helm.sh/release-namespace` kubernetes resource labels. For example you deployed release from `https://gitlab.com/project/project/pipelines/1` and then from `https://gitlab.com/project/project/pipelines/2`, so the metrics would be:
```text
kube_annotations_exporter{annotations_exporter_annotation_gitlab_ci_werf_io_pipeline_url="https://gitlab.com/project/project/pipelines/1", annotations_exporter_annotation_meta_helm_sh_release_name="project-dev", annotations_exporter_annotation_meta_helm_sh_release_namespace="dev", annotations_exporter_revision="1"}
kube_annotations_exporter{annotations_exporter_annotation_gitlab_ci_werf_io_pipeline_url="https://gitlab.com/project/project/pipelines/2", annotations_exporter_annotation_meta_helm_sh_release_name="project-dev", annotations_exporter_annotation_meta_helm_sh_release_namespace="dev", annotations_exporter_revision="0"}
```
## Dashboards

TBA
Now there is only one [summary dashboard](charts/annotations-exporter/templates/dashboard.yaml), that will be autogenerated for helm-chart to ConfigMap. It is simple table that summarises all information about exported annotations and labels

<!--
helm upgrade --install annotations-exporter charts/annotations-exporter/ -n default -f test_values.yaml
-->
2 changes: 1 addition & 1 deletion charts/annotations-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
type: application
name: annotations-exporter
version: 0.4.0
version: 0.5.0
kubeVersion: ">=1.10.0-0"
description: "Prometheus-exporter, which converts any Kubernetes resources annotations and labels to Prometheus samples."
12 changes: 8 additions & 4 deletions charts/annotations-exporter/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# annotations-exporter

![Version: 0.4.0](https://img.shields.io/badge/Version-0.4.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
![Version: 0.5.0](https://img.shields.io/badge/Version-0.5.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)

Prometheus-exporter, which converts any Kubernetes resources annotations and labels to Prometheus samples.

Expand All @@ -15,13 +15,16 @@ Kubernetes: `>=1.10.0-0`
| replicaCount | int | `1` | Number of replicas (pods) to launch. |
| image.repository | string | `"ghcr.io/alex123012/annotations-exporter"` | Name of the image repository to pull the container image from. |
| image.pullPolicy | string | `"IfNotPresent"` | [Image pull policy](https://kubernetes.io/docs/concepts/containers/images/#updating-images) for updating already existing images on a node. |
| image.tag | string | `"v0.4.0"` | Image tag override for the default value (chart appVersion). |
| image.tag | string | `"v0.5.0"` | Image tag override for the default value (chart appVersion). |
| cmdArgs."kube.resources" | list | `["deployments/apps","ingresses/v1/networking.k8s.io","statefulsets/apps","daemonsets/apps"]` | Kubernetes resources for annotations and labels to export. |
| cmdArgs."kube.annotations" | list | `["ci.werf.io/commit","gitlab.ci.werf.io/pipeline-url"]` | Kubernetes resources annotations to export. |
| cmdArgs."kube.labels" | list | `["app"]` | Kubernetes resources labels to export. |
| cmdArgs."kube.annotations" | list | `[]` | Kubernetes resources annotations to export. |
| cmdArgs."kube.labels" | list | `[]` | Kubernetes resources labels to export. |
| cmdArgs."kube.namespaces" | list | `[""]` | Kubernetes namespaces to watch. |
| cmdArgs."kube.max-revisions" | int | `3` | Max revisions of resource labels to store. |
| cmdArgs."server.log-level" | string | `"debug"` | Log level. |
| cmdArgs."kube.only-labels-and-annotations" | bool | `false` | Export only labels and annotations defined by flags (usefull for exposing ) |
| cmdArgs."kube.reference-labels" | list | `[]` | Labels names to use in prometheus metric labels and for count revisions (reference name) |
| cmdArgs."kube.reference-annotations" | list | `[]` | Annotations names to use in prometheus metric labels and for count revisions (reference name) |
| imagePullSecrets | list | `[]` | Reference to one or more secrets to be used when [pulling images](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-pod-that-uses-your-secret) (from private registries). |
| nameOverride | string | `""` | A name in place of the chart name for `app:` labels. |
| fullnameOverride | string | `""` | A name to substitute for the full names of resources. |
Expand All @@ -42,6 +45,7 @@ Kubernetes: `>=1.10.0-0`
| affinity | object | `{}` | [Affinity](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity) configuration. See the [API reference](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#scheduling) for details. |
| strategy | object | `{}` | Deployment [strategy](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy) configuration. |
| service.annotations | object | `{}` | Annotations to be added to the service. |
| service.labels | object | `{}` | Labels to be added to the service. |
| service.type | string | `"ClusterIP"` | Kubernetes [service type](https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types). |
| service.clusterIP | string | `""` | Internal cluster service IP (when applicable) |
| service.ports.port | int | `8000` | HTTP service port |
Expand Down
8 changes: 8 additions & 0 deletions charts/annotations-exporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@ app.kubernetes.io/instance: {{ .Release.Name }}
{{- fail ( printf "Can't parse resource string %s" $arg ) }}
{{- end }}
{{- end }}

{{- define "format.prom.label" }}
{{- $arg := . }}
{{- $result := replace "/" "_" $arg }}
{{- $result = replace "." "_" $result }}
{{- $result = replace "-" "_" $result }}
{{- lower $result }}
{{- end }}
Loading

0 comments on commit e997dc0

Please sign in to comment.