Skip to content

Add custom Prometheus metrics#124

Open
iakmc wants to merge 1 commit intoplatform-mesh:mainfrom
iakmc:prometheus-custom-metrics
Open

Add custom Prometheus metrics#124
iakmc wants to merge 1 commit intoplatform-mesh:mainfrom
iakmc:prometheus-custom-metrics

Conversation

@iakmc
Copy link
Copy Markdown

@iakmc iakmc commented Apr 20, 2026

Summary

  • Added five custom Prometheus metrics
  • Added internal/metrics/metrics_test.go for direct metric verification
  • Added metric assertions to the existing HttpBinReconciler controller test

Metrics added

  • httpbin_operator_httpbin_reconciled_total - counter, label: result (created/success/error). Incremented on every HttpBin reconcile call.
  • httpbin_operator_deployments_total - counter, label: operation (created/updated/deleted). Tracks local Deployment lifecycle operations.
  • httpbin_operator_services_total - counter, label: operation (created/updated). Tracks local Service lifecycle operations.
  • httpbin_operator_deployment_ready - gauge, label: name. Set to 1 when the HttpBinDeployment has ready replicas, 0 otherwise. Removed when the HttpBinDeployment is deleted.
  • httpbin_operator_ready_replicas - gauge, label: name. Tracks the current number of ready replicas per HttpBinDeployment. Removed when the HttpBinDeployment is deleted.

Testing

Unit test

go test ./internal/metrics/... -v -run TestMetricsManual

Manual test against a local kind cluster

kind create cluster --name httpbin-example

kubectl apply -f config/crd/gateway-api/
kubectl apply -f config/crd/bases/
go run cmd/main.go \
  --metrics-bind-address=:8080 \
  --metrics-secure=false \
  --health-probe-bind-address=:8082
Create a resource and check metrics:
kubectl apply -f - <<EOF
apiVersion: orchestrate.platform-mesh.io/v1alpha1
kind: HttpBin
metadata:
  name: demo
  namespace: default
spec:
  region: eu-west-1
EOF
curl -s http://localhost:8080/metrics | grep httpbin_operator
# HELP httpbin_operator_deployments_total Total number of local Deployment operations performed.
# TYPE httpbin_operator_deployments_total counter
httpbin_operator_deployments_total{operation="created"} 1
# HELP httpbin_operator_httpbin_reconciled_total Total number of HttpBin reconcile calls by result.
# TYPE httpbin_operator_httpbin_reconciled_total counter
httpbin_operator_httpbin_reconciled_total{result="created"} 1
httpbin_operator_httpbin_reconciled_total{result="success"} 3
# HELP httpbin_operator_services_total Total number of local Service operations performed.
# TYPE httpbin_operator_services_total counter
httpbin_operator_services_total{operation="created"} 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant