CodeScoring.Save Monitoring

CodeScoring.Save exports metrics in the Prometheus format. This page describes which component exports which metrics, how to set up metric collection in Kubernetes, and what the metrics mean. It also provides ready-made PromQL queries, a Grafana dashboard, and starter alerting rules.

Metrics endpoints

ComponentPortPathEnvironment variable
backend (Save API)9090/metricsMETRICS_PORT
worker8082/metricsHEALTH_PORT (the same listener as the /health/* probe endpoints)
scheduler——does not export metrics

The worker component runs only with REDIS_ENABLED: "true" and PostgreSQL. Scheduled cleanup policy runs are executed by worker, while a policy run started manually from the web interface or through the API is executed by backend. So the cleanup_* metrics can come from both components: collect metrics from both backend and worker.

Every series carries the otel_scope_name and otel_scope_version labels. Service attributes (service_name, service_version) are available in the target_info metric.

Kubernetes setup

Metrics Services

Create separate Services that expose the backend metrics port and the worker HEALTH_PORT. The Services select pods by the app=backend and app=worker labels:

apiVersion: v1
kind: Service
metadata:
  name: save-metrics
  namespace: codescoring-save
  labels:
    app.kubernetes.io/part-of: codescoring-save
spec:
  selector:
    app: backend
  ports:
    - name: metrics
      port: 9090
      targetPort: 9090
--- # worker
apiVersion: v1
kind: Service
metadata:
  name: save-worker-metrics
  namespace: codescoring-save
  labels:
    app.kubernetes.io/part-of: codescoring-save
spec:
  selector:
    app: worker
  ports:
    - name: health
      port: 8082
      targetPort: 8082

If you changed METRICS_PORT or HEALTH_PORT, use the same values in port and targetPort.

ServiceMonitor (Prometheus Operator)

One ServiceMonitor with two endpoints. Each endpoint applies only to the Services that have a port with that name:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: codescoring-save
  namespace: codescoring-save
spec:
  selector:
    matchLabels:
      app.kubernetes.io/part-of: codescoring-save
  endpoints:
    - port: metrics      # backend
      path: /metrics
      interval: 15s
    - port: health       # worker
      path: /metrics
      interval: 15s
  jobLabel: app.kubernetes.io/part-of

jobLabel takes the job name from the app.kubernetes.io/part-of label of the Services, so the series of both backend and worker get job="codescoring-save". The queries, alerting rules, and the dashboard on this page select Save metrics by this label.

Note

Prometheus Operator picks up only the ServiceMonitors that match serviceMonitorSelector and serviceMonitorNamespaceSelector of your Prometheus resource. If these selectors are set, add the required labels to the ServiceMonitor, for example release: kube-prometheus-stack.

Annotations (Prometheus without the Operator)

If Prometheus discovers targets by prometheus.io/* annotations, add them to the backend and worker pod templates:

# backend
metadata:
  annotations:
    prometheus.io/scrape: "true"
    prometheus.io/port: "9090"
    prometheus.io/path: "/metrics"
--- # worker
metadata:
  annotations:
    prometheus.io/scrape: "true"
    prometheus.io/port: "8082"
    prometheus.io/path: "/metrics"

The queries on this page select Save metrics by job="codescoring-save". Collect the Save pods in a separate scrape job with this name:

scrape_configs:
  - job_name: codescoring-save
    kubernetes_sd_configs:
      - role: pod
        namespaces:
          names: [codescoring-save]
    relabel_configs:
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        action: keep
        regex: "true"
      - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
        action: replace
        regex: ([^:]+)(?::\d+)?;(\d+)
        replacement: $1:$2
        target_label: __address__

If your generic job for annotated pods also scrapes the codescoring-save namespace, exclude this namespace from it so the metrics are not collected twice.

Verification

Check that both components export metrics:

kubectl -n codescoring-save port-forward svc/save-metrics 19090:9090
curl -s http://127.0.0.1:19090/metrics | grep '^# TYPE'

kubectl -n codescoring-save port-forward deploy/codescoring-save-worker 18082:8082
curl -s http://127.0.0.1:18082/metrics | grep '^# TYPE'

In Prometheus, up{job="codescoring-save"} must equal 1 for every backend and worker pod.

Metrics reference

A counter appears in /metrics only after its first increment. Right after startup backend exports only the http_* metrics.

HTTP (backend)

MetricTypeLabels
http_requests_totalcountermethod, path, status
http_request_duration_secondshistogrammethod, path, status
http_requests_activegauge—

The path label holds the route template, not the request URL: /api/v1/projects/:project, /v2/{name}/blobs/{digest}, /maven/:project/:repository/*path. Requests that match no route are counted with path="<unmatched>".

Histogram bucket boundaries in seconds: 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30.

Artifacts and storage (backend)

MetricTypeLabels
artifact_uploads_totalcounterartifact_type, repository
artifact_downloads_totalcounterartifact_type, repository
storage_operations_totalcounteroperation (read, write), backend, success

Proxy repositories (backend)

MetricTypeLabels
proxy_requests_totalcounterartifact_type, repository, cache_hit, success
proxy_blocked_totalcounterartifact_type, repository

proxy_requests_total counts requests to proxy repositories of all formats:

  • cache_hit="true" — the artifact was served from local storage;
  • cache_hit="false" — the artifact was fetched from the upstream repository; if the upstream fetch failed, success="false".

proxy_blocked_total counts requests blocked by CodeScoring OSA Proxy. A block is a policy verdict, not a failure, so it is not counted in proxy_requests_total.

Cleanup (backend or worker)

MetricTypeLabels
cleanup_operations_totalcounterpolicy_type, repository, success
cleanup_artifacts_deleted_totalcounterpolicy_type, repository, success

cleanup_operations_total grows by 1 every time a cleanup policy runs for a repository. cleanup_artifacts_deleted_total grows by the number of artifacts that run deleted.

PromQL queries

Request rate by route:

sum by (path) (rate(http_requests_total{job="codescoring-save"}[5m]))

Share of 5xx responses:

sum(rate(http_requests_total{job="codescoring-save", status=~"5.."}[5m]))
  / sum(rate(http_requests_total{job="codescoring-save"}[5m]))

p95 response time — overall and by route:

histogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket{job="codescoring-save"}[5m])))
histogram_quantile(0.95, sum by (le, path) (rate(http_request_duration_seconds_bucket{job="codescoring-save"}[5m])))

Proxy cache hit rate — overall and by repository:

sum(rate(proxy_requests_total{job="codescoring-save", cache_hit="true"}[5m]))
  / sum(rate(proxy_requests_total{job="codescoring-save"}[5m]))

sum by (repository) (rate(proxy_requests_total{job="codescoring-save", cache_hit="true"}[5m]))
  / sum by (repository) (rate(proxy_requests_total{job="codescoring-save"}[5m]))

Failed requests to upstream repositories:

sum by (repository) (rate(proxy_requests_total{job="codescoring-save", success="false"}[5m]))

Requests blocked by OSA Proxy in the last hour:

sum by (repository) (increase(proxy_blocked_total{job="codescoring-save"}[1h]))

Downloads by format:

sum by (artifact_type) (rate(artifact_downloads_total{job="codescoring-save"}[5m]))

Artifacts deleted by cleanup per day, and failed cleanup runs:

sum by (repository) (increase(cleanup_artifacts_deleted_total{job="codescoring-save"}[1d]))
sum by (repository, policy_type) (increase(cleanup_operations_total{job="codescoring-save", success="false"}[1d]))

Grafana dashboard

The ready-made dashboard contains panels for HTTP requests, response time (p95 and p99), artifact uploads and downloads, proxy cache hits, storage operations, and cleanup.

  1. Download the dashboard JSON file.
  2. In Grafana, open Dashboards → New → Import and upload the file.
  3. In the Prometheus field, select the data source that collects Save metrics, and click Import.

The job variable at the top of the dashboard selects Save metrics; its default value is codescoring-save.

Alerting rules

A starter set of Prometheus rules:

groups:
  - name: codescoring-save
    rules:
      - alert: SaveTargetDown
        expr: up{job="codescoring-save"} == 0
        for: 5m
        labels: {severity: critical}
        annotations:
          summary: "Save target {{ $labels.instance }} is down"

      - alert: SaveHighErrorRate
        expr: |
          sum(rate(http_requests_total{job="codescoring-save", status=~"5.."}[5m]))
            / sum(rate(http_requests_total{job="codescoring-save"}[5m])) > 0.05
        for: 10m
        labels: {severity: warning}
        annotations:
          summary: "More than 5% of Save responses are 5xx"

      - alert: SaveSlowRequests
        expr: |
          histogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket{job="codescoring-save"}[5m]))) > 5
        for: 15m
        labels: {severity: warning}
        annotations:
          summary: "Save p95 latency is above 5s"

      - alert: SaveUpstreamFailures
        expr: sum by (repository) (rate(proxy_requests_total{job="codescoring-save", success="false"}[10m])) > 0.1
        for: 15m
        labels: {severity: warning}
        annotations:
          summary: "Upstream fetches failing for proxy {{ $labels.repository }}"

      - alert: SaveCleanupFailed
        expr: |
          sum by (repository) (increase(cleanup_operations_total{job="codescoring-save", success="false"}[1h])) > 0
          or
          sum by (repository) (
            cleanup_operations_total{job="codescoring-save", success="false"}
              unless cleanup_operations_total{job="codescoring-save", success="false"} offset 1h
          ) > 0
        labels: {severity: warning}
        annotations:
          summary: "Cleanup failed for repository {{ $labels.repository }}"

SaveCleanupFailed also checks newly observed positive failure counters: the first failed run creates its series at 1, which increase() alone cannot detect. This fallback can also fire when Prometheus starts collecting an existing nonzero failure counter; it expires after one hour without further failures.

Note

The rules select Save metrics by job="codescoring-save", see ServiceMonitor and Annotations. If your Save metrics have a different job, change it in the queries, the rules, and the job dashboard variable. Tune the thresholds to the load of your installation.

Was this page helpful?