Skip to content

feat: add Prometheus metrics#18

Draft
veerendra2 wants to merge 2 commits intomainfrom
14-add-metrics
Draft

feat: add Prometheus metrics#18
veerendra2 wants to merge 2 commits intomainfrom
14-add-metrics

Conversation

@veerendra2
Copy link
Copy Markdown
Owner

Summary

  • Adds 5 Prometheus counter metrics: composeflux_deployments_total, composeflux_deployment_failures_total, composeflux_image_updates_total, composeflux_image_update_failures_total, composeflux_stacks_pruned_total
  • Exposes /metrics endpoint on --metrics-addr (default :9090, empty to disable) for the run command only
  • Graceful HTTP server shutdown on SIGINT/SIGTERM

Metrics

Metric Type Labels Description
composeflux_deployments_total Counter stack_name Stack deployment attempts
composeflux_deployment_failures_total Counter stack_name Failed stack deployments
composeflux_image_updates_total Counter stack_name Image update attempts
composeflux_image_update_failures_total Counter stack_name Failed image updates
composeflux_stacks_pruned_total Counter stack_name Managed stacks removed during pruning

Test plan

  • Run daemon with --metrics-addr :9090 and verify curl localhost:9090/metrics returns all 5 metrics
  • Trigger a git change that causes a stack deploy, verify composeflux_deployments_total increments
  • Trigger an image update cycle, verify composeflux_image_updates_total increments
  • Remove a stack from git, verify composeflux_stacks_pruned_total increments
  • Run with --metrics-addr "" and verify no HTTP server starts
  • Send SIGTERM and verify graceful shutdown logs for metrics server

🤖 Generated with Claude Code

Expose Prometheus counters for the run (daemon) command:
- composeflux_deployments_total / composeflux_deployment_failures_total
- composeflux_image_updates_total / composeflux_image_update_failures_total
- composeflux_stacks_pruned_total

Adds --metrics-addr flag (default :9090) with graceful HTTP server shutdown.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@veerendra2 veerendra2 linked an issue Apr 14, 2026 that may be closed by this pull request
@veerendra2 veerendra2 requested a review from Copilot April 14, 2026 13:42
@veerendra2 veerendra2 added the build Builds dev docker image label Apr 14, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Prometheus instrumentation to ComposeFlux by introducing counter metrics for key reconciliation actions and exposing them via a dedicated /metrics HTTP endpoint on the run command.

Changes:

  • Add Prometheus counter metrics for deployments, image updates, failures, and pruning.
  • Increment those metrics from the reconciler’s Sync, SyncImages, and Prune paths.
  • Add a --metrics-addr flag to run to optionally start a /metrics server with graceful shutdown.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/reconcile/sync.go Increments deployment and image update counters (and failure counters) during reconciliation.
internal/reconcile/prune.go Increments a counter when managed stacks are successfully pruned.
internal/metrics/metrics.go Defines and registers the Prometheus CounterVec metrics.
cmd/composeflux/run.go Adds --metrics-addr and starts/stops a Prometheus /metrics HTTP server in daemon mode.
go.mod Promotes github.com/prometheus/client_golang to a direct dependency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/composeflux/run.go
Comment on lines +33 to +37
go func() {
slog.Info("Starting metrics server", "addr", r.MetricsAddr)
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
slog.Error("Metrics server failed", "error", err)
}
Comment thread cmd/composeflux/run.go

type RunCmd struct {
CommonConfig `embed:""`
MetricsAddr string `name:"metrics-addr" help:"Prometheus metrics listen address. Empty to disable." env:"METRICS_ADDR" default:":9090" group:"Metrics Options:"`
Comment thread cmd/composeflux/run.go
if r.MetricsAddr != "" {
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
srv := &http.Server{Addr: r.MetricsAddr, Handler: mux}
Update README, docs site, and Getting Started with metrics feature:
- Add Prometheus Metrics to features list
- Add METRICS_ADDR env var to configuration reference
- Add metrics port and env var to sample compose.yml
- Update compose-dev.yml with metrics port and dev config

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Builds dev docker image

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add metrics

2 participants