sonarqube-exporter

by tina.junold

Helm chartv0.3.1App 1.1.1Verified publisher

Exports the measures of every SonarQube project as Prometheus gauges, with the ideaplexus/sonarqube-exporter image. One instance per SonarQube, scraped through annotations or a ServiceMonitor.

About this chart

sonarqube-exporter

Exports the measures of every SonarQube project as Prometheus gauges, with the ideaplexus/sonarqube-exporter image. One instance per SonarQube, scraped through annotations or a ServiceMonitor.

Homepage: https://gitlab.com/ideaplexus/charts

Maintainers

NameEmailUrl
Tina Junold[email protected]https://ideaplexus.com

Source Code

Requirements

Kubernetes: >=1.29.0-0

RepositoryNameVersion
https://charts.ideaplexus.comcommon1.1.0

Quick start

sonarqube:
  url: https://sonarqube.example.com
  existingSecret: sonarqube-exporter-token

The exporter reads every project of that SonarQube, exports its measures on /metrics and imports them again every scrapeInterval. The exporter's README lists every metric and its labels. sonar_scrape_success tells whether the last import worked; on a failure the previous values stay exported.

Run one release per SonarQube. Every further exporter of the same instance duplicates every series, which is why the chart has no replicaCount.

Token

The exporter authenticates with a SonarQube user token. It needs Browse on the projects; Administer System additionally enables sonar_last_analysis_timestamp_seconds. Without a token it only sees the projects that are visible anonymously.

Keep the token out of your values and reference a secret you manage, for example one filled by External Secrets:

kubectl create secret generic sonarqube-exporter-token --from-literal=token=squ_...
sonarqube:
  existingSecret: sonarqube-exporter-token
  existingSecretTokenKey: token

sonarqube.token also works; the chart then keeps it in a secret of its own. Either way it reaches the pod as a secretKeyRef, never as a plain value.

Selecting metrics

Every metric key costs one series per project, so a large instance quickly adds up to tens of thousands of series. Both lists accept shell style wildcards and are applied as "include, then exclude":

metrics:
  # only the ratings, the quality gate and the size
  included: [alert_status, ncloc, coverage, software_quality_*_rating]
  # without the new code period
  excluded: [new_*]

An empty included exports every supported key. Keys that are not selected are not even requested from SonarQube, so the lists also reduce the API load.

Scraping

WayValuesFor
Pod annotations (default)metrics.annotations: truean annotation based discovery, such as the Grafana Alloy annotation autodiscovery or the Prometheus kubernetes-pods job
ServiceMonitormetrics.annotations: false, metrics.serviceMonitor.enabled: truethe Prometheus Operator, or Alloy reading its objects

Use one of them. With both, a cluster that honours both scrapes the exporter twice and stores every series twice.

metrics:
  annotations: false
  serviceMonitor:
    enabled: true
    labels:
      release: prometheus

The exporter only changes its values every scrapeInterval (default five minutes), so scraping it more often costs storage without adding anything.

SonarQube behind a private CA

The image is built from scratch and only carries the public CA certificates. Mount your CA bundle over them:

extraVolumes:
  - name: ca
    configMap:
      name: internal-ca
extraVolumeMounts:
  - name: ca
    mountPath: /etc/ssl/certs/ca-certificates.crt
    subPath: ca-certificates.crt
    readOnly: true

The bundle replaces the public certificates, so it has to contain every CA the exporter needs.

Values

KeyTypeDefaultDescription
affinityobject{}Affinity rules for the pod
commonAnnotationsobject{}Annotations added to every resource
commonLabelsobject{}Labels added to every resource
containerPorts.metricsint9103Port of /metrics and /healthz, LISTEN_ADDR
containerSecurityContext.allowPrivilegeEscalationboolfalseDisallow privilege escalation
containerSecurityContext.capabilitiesobject{"drop":["ALL"]}Linux capabilities
containerSecurityContext.enabledbooltrueEnable the container security context
containerSecurityContext.readOnlyRootFilesystembooltrueMount the root filesystem read-only. The exporter writes nothing.
containerSecurityContext.runAsGroupint65532Group id to run as
containerSecurityContext.runAsNonRootbooltrueRun as a non-root user
containerSecurityContext.runAsUserint65532User id to run as
customLivenessProbeobject{}A complete probe replacing the built-in liveness probe. Only used when livenessProbe.enabled is false.
customReadinessProbeobject{}A complete probe replacing the built-in readiness probe. Only used when readinessProbe.enabled is false.
extraDeploylist[]Extra objects to deploy with the release. Evaluated as templates.
extraEnvVarslist[]Extra environment variables
extraEnvVarsCMlist[]ConfigMaps to take environment variables from
extraEnvVarsSecretlist[]Secrets to take environment variables from
extraVolumeMountslist[]Extra volume mounts for the container
extraVolumeslist[]Extra volumes for the pod, eg. a CA bundle for a SonarQube behind a private CA
fullnameOverridestring""Override the fully generated object names
global.imagePullSecretslist[]Global Docker registry secret names
global.imageRegistrystring""Global Docker image registry
httpTimeoutstring"1m"Timeout of a single SonarQube request, HTTP_TIMEOUT, as a Go duration
image.digeststring""Image digest in the form sha256:aa.... Overrides the tag when set.
image.pullPolicystring"IfNotPresent"Image pull policy
image.pullSecretslist[]Image pull secrets, as names or - name: my-secret
image.registrystring"docker.io"Image registry
image.repositorystring"ideaplexus/sonarqube-exporter"Image repository
image.tagstring""Image tag. Defaults to the chart appVersion.
livenessProbe.enabledbooltrueEnable the liveness probe
livenessProbe.failureThresholdint3Consecutive failures tolerated
livenessProbe.initialDelaySecondsint5Seconds before the first check
livenessProbe.periodSecondsint15Seconds between checks
livenessProbe.successThresholdint1Consecutive successes needed after a failure. Must be 1 for a liveness probe.
livenessProbe.timeoutSecondsint5Seconds after which a check times out
log.formatstring"json"Log format, LOG_FORMAT
log.levelstring"info"Log level, LOG_LEVEL
metrics.annotationsbooltrueAdd prometheus.io/scrape, prometheus.io/port and prometheus.io/path to the pod, for an annotation based discovery such as Grafana Alloy or the Prometheus kubernetes-pods job. Turn it off with a ServiceMonitor.
metrics.excludedlist[]Metric keys never to export, SONAR_EXCLUDED_METRICS. Applied after included and always wins, eg. new_*.
metrics.includedlist[]Metric keys to export, SONAR_INCLUDED_METRICS. Shell style wildcards, eg. software_quality_*_rating. Empty exports every supported key.
metrics.serviceMonitor.annotationsobject{}Annotations of the ServiceMonitor
metrics.serviceMonitor.enabledboolfalseCreate a ServiceMonitor. Needs the monitoring.coreos.com CRDs. Turn metrics.annotations off with it.
metrics.serviceMonitor.honorLabelsboolfalseKeep the labels of the scraped series when they collide with the target labels
metrics.serviceMonitor.intervalstring""Scrape interval. Empty uses the Prometheus default. More often than scrapeInterval only repeats the same values.
metrics.serviceMonitor.labelsobject{}Labels of the ServiceMonitor, eg. the one a Prometheus selects on
metrics.serviceMonitor.metricRelabelingslist[]Relabelings applied to the scraped series
metrics.serviceMonitor.namespacestring""Namespace of the ServiceMonitor. Empty uses the release namespace.
metrics.serviceMonitor.relabelingslist[]Relabelings applied to the target before scraping
metrics.serviceMonitor.scrapeTimeoutstring""Scrape timeout. Empty uses the Prometheus default.
nameOverridestring""Override the chart name used to construct object names
namespaceOverridestring""Override the namespace the objects are created in
nodeSelectorobject{}Node labels the pod is scheduled on
podAnnotationsobject{}Annotations for the pod
podLabelsobject{}Labels for the pod
podSecurityContext.enabledbooltrueEnable the pod security context
podSecurityContext.fsGroupint65532Group of the pod's volumes
podSecurityContext.seccompProfileobject{"type":"RuntimeDefault"}Seccomp profile
priorityClassNamestring""Priority class for the pod
readinessProbe.enabledbooltrueEnable the readiness probe
readinessProbe.failureThresholdint3Consecutive failures tolerated
readinessProbe.initialDelaySecondsint5Seconds before the first check
readinessProbe.periodSecondsint15Seconds between checks
readinessProbe.successThresholdint1Consecutive successes needed after a failure
readinessProbe.timeoutSecondsint5Seconds after which a check times out
resourcesobject{}Explicit container resources, which win over the preset
resourcesPresetstring"nano"Container resources preset, used when resources is empty (none, nano, micro, small, medium, large, xlarge, 2xlarge)
revisionHistoryLimitint10Number of old ReplicaSets to retain
scrapeIntervalstring"5m"Interval between two imports from SonarQube, SCRAPE_INTERVAL, as a Go duration
service.annotationsobject{}Annotations for the Service. Do not add prometheus.io annotations here when metrics.annotations is on, a discovery of both would scrape twice.
service.ports.metricsint9103Metrics port
service.typestring"ClusterIP"Service type
serviceAccount.annotationsobject{}Annotations for the ServiceAccount
serviceAccount.automountServiceAccountTokenboolfalseAutomount the API token. The exporter does not talk to the Kubernetes API.
serviceAccount.createbooltrueCreate a ServiceAccount
serviceAccount.namestring""Name of the ServiceAccount. Generated when empty and create is true.
sonarqube.existingSecretstring""Name of an existing secret holding the token, instead of letting the chart manage one. Evaluated as a template.
sonarqube.existingSecretTokenKeystring"token"Key inside that secret
sonarqube.tokenstring""User token, SONAR_TOKEN, stored in a secret this chart creates. Prefer existingSecret, eg. filled by External Secrets. Needs Browse on the projects; Administer System additionally enables sonar_last_analysis_timestamp_seconds. Mutually exclusive with sonarqube.existingSecret.
sonarqube.urlstring""Base URL of the SonarQube instance, SONAR_URL, eg. https://sonarqube.example.com. Required: without it the exporter refuses to start. Evaluated as a template.
tolerationslist[]Tolerations for the pod
updateStrategyobject{"type":"RollingUpdate"}Update strategy. A rolling update has no gap in the metrics; old and new pod overlap for a few seconds.
updateStrategy.typestring"RollingUpdate"Strategy type. Recreate avoids the overlap at the price of a short gap.

Autogenerated from chart metadata using helm-docs v1.14.2

Deploy sonarqube-exporter with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has sonarqube-exporter on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartsonarqube-exporter is pinned at v0.3.1 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply