diff options
| author | Paul Buetow <paul@buetow.org> | 2025-12-30 23:00:27 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-12-30 23:00:27 +0200 |
| commit | 873957d4e818a6117836486d6ea7258c3f79e1d2 (patch) | |
| tree | 17c6409bfd7ad3527ab11c5ccf6273543da8a530 /f3s/prometheus-pusher/internal | |
| parent | 9716cd2b6847b78891958de14ac5d8e1032c485b (diff) | |
Rename test metrics with clear prefix and add Grafana dashboard
Renamed all test metrics with "prometheus_pusher_test_" prefix to clearly
indicate they are generated by the prometheus-pusher testing/demo functionality.
Metric renaming:
- app_requests_total → prometheus_pusher_test_requests_total
- app_active_connections → prometheus_pusher_test_active_connections
- app_temperature_celsius → prometheus_pusher_test_temperature_celsius
- app_request_duration_seconds → prometheus_pusher_test_request_duration_seconds
- app_jobs_processed_total → prometheus_pusher_test_jobs_processed_total
Grafana Dashboard:
- Created comprehensive dashboard with 8 panels
- Request rate and total requests visualization
- Active connections gauge (0-100 with thresholds)
- Temperature gauge (0-50°C with thresholds)
- Request duration percentiles (p50, p90, p99)
- Average request duration stat
- Jobs processed by type (bar gauge)
- Jobs status breakdown table
- Auto-refresh every 10s, 15-minute default time range
Files added:
- grafana-dashboard.json: Dashboard definition
- deploy-dashboard.sh: Automated deployment script
- DASHBOARD.md: Complete dashboard documentation
Updated:
- internal/metrics/generator.go: Renamed metric names
- internal/ingester/remotewrite.go: Updated historic metric names
- internal/ingester/remotewrite_test.go: Updated test expectations
Tests updated and passing with 63.9% coverage maintained.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'f3s/prometheus-pusher/internal')
3 files changed, 28 insertions, 26 deletions
diff --git a/f3s/prometheus-pusher/internal/ingester/remotewrite.go b/f3s/prometheus-pusher/internal/ingester/remotewrite.go index ee5bd65..c88cff6 100644 --- a/f3s/prometheus-pusher/internal/ingester/remotewrite.go +++ b/f3s/prometheus-pusher/internal/ingester/remotewrite.go @@ -164,9 +164,9 @@ func generateHistoricTimeSeries(timestamp time.Time) []prompb.TimeSeries { {Name: "job", Value: "historic_data"}, } - timeSeries = append(timeSeries, createCounterSeries("app_requests_total", baseLabels, float64(rand.Intn(100)+1), timestampMs)) - timeSeries = append(timeSeries, createGaugeSeries("app_active_connections", baseLabels, float64(rand.Intn(100)), timestampMs)) - timeSeries = append(timeSeries, createGaugeSeries("app_temperature_celsius", baseLabels, 15+rand.Float64()*20, timestampMs)) + timeSeries = append(timeSeries, createCounterSeries("prometheus_pusher_test_requests_total", baseLabels, float64(rand.Intn(100)+1), timestampMs)) + timeSeries = append(timeSeries, createGaugeSeries("prometheus_pusher_test_active_connections", baseLabels, float64(rand.Intn(100)), timestampMs)) + timeSeries = append(timeSeries, createGaugeSeries("prometheus_pusher_test_temperature_celsius", baseLabels, 15+rand.Float64()*20, timestampMs)) timeSeries = append(timeSeries, generateHistogramSeries(baseLabels, timestampMs)...) timeSeries = append(timeSeries, generateLabeledCounterSeries(baseLabels, timestampMs)...) @@ -199,7 +199,7 @@ func generateHistogramSeries(baseLabels []prompb.Label, timestamp int64) []promp for _, bucket := range buckets { cumulativeCount += rand.Intn(5) labels := []prompb.Label{ - {Name: "__name__", Value: "app_request_duration_seconds_bucket"}, + {Name: "__name__", Value: "prometheus_pusher_test_request_duration_seconds_bucket"}, {Name: "le", Value: fmt.Sprintf("%g", bucket)}, } labels = append(labels, baseLabels...) @@ -211,7 +211,7 @@ func generateHistogramSeries(baseLabels []prompb.Label, timestamp int64) []promp } infLabels := []prompb.Label{ - {Name: "__name__", Value: "app_request_duration_seconds_bucket"}, + {Name: "__name__", Value: "prometheus_pusher_test_request_duration_seconds_bucket"}, {Name: "le", Value: "+Inf"}, } infLabels = append(infLabels, baseLabels...) @@ -220,8 +220,8 @@ func generateHistogramSeries(baseLabels []prompb.Label, timestamp int64) []promp Samples: []prompb.Sample{{Value: float64(cumulativeCount), Timestamp: timestamp}}, }) - series = append(series, createCounterSeries("app_request_duration_seconds_sum", baseLabels, rand.Float64()*100, timestamp)) - series = append(series, createCounterSeries("app_request_duration_seconds_count", baseLabels, float64(cumulativeCount), timestamp)) + series = append(series, createCounterSeries("prometheus_pusher_test_request_duration_seconds_sum", baseLabels, rand.Float64()*100, timestamp)) + series = append(series, createCounterSeries("prometheus_pusher_test_request_duration_seconds_count", baseLabels, float64(cumulativeCount), timestamp)) return series } @@ -235,7 +235,7 @@ func generateLabeledCounterSeries(baseLabels []prompb.Label, timestamp int64) [] for _, jobType := range jobTypes { for _, status := range statuses { labels := []prompb.Label{ - {Name: "__name__", Value: "app_jobs_processed_total"}, + {Name: "__name__", Value: "prometheus_pusher_test_jobs_processed_total"}, {Name: "job_type", Value: jobType}, {Name: "status", Value: status}, } diff --git a/f3s/prometheus-pusher/internal/ingester/remotewrite_test.go b/f3s/prometheus-pusher/internal/ingester/remotewrite_test.go index 5d386ef..2f375dc 100644 --- a/f3s/prometheus-pusher/internal/ingester/remotewrite_test.go +++ b/f3s/prometheus-pusher/internal/ingester/remotewrite_test.go @@ -83,10 +83,10 @@ func TestGenerateHistoricTimeSeries(t *testing.T) { } expectedMetrics := []string{ - "app_requests_total", - "app_active_connections", - "app_temperature_celsius", - "app_jobs_processed_total", + "prometheus_pusher_test_requests_total", + "prometheus_pusher_test_active_connections", + "prometheus_pusher_test_temperature_celsius", + "prometheus_pusher_test_jobs_processed_total", } for _, expected := range expectedMetrics { @@ -159,13 +159,13 @@ func TestGenerateHistogramSeries(t *testing.T) { } } - if metricTypes["app_request_duration_seconds_bucket"] == 0 { + if metricTypes["prometheus_pusher_test_request_duration_seconds_bucket"] == 0 { t.Error("Expected histogram buckets") } - if metricTypes["app_request_duration_seconds_sum"] != 1 { + if metricTypes["prometheus_pusher_test_request_duration_seconds_sum"] != 1 { t.Error("Expected histogram sum") } - if metricTypes["app_request_duration_seconds_count"] != 1 { + if metricTypes["prometheus_pusher_test_request_duration_seconds_count"] != 1 { t.Error("Expected histogram count") } } diff --git a/f3s/prometheus-pusher/internal/metrics/generator.go b/f3s/prometheus-pusher/internal/metrics/generator.go index 2b5c739..3ad7fe4 100644 --- a/f3s/prometheus-pusher/internal/metrics/generator.go +++ b/f3s/prometheus-pusher/internal/metrics/generator.go @@ -27,38 +27,40 @@ type Collectors struct { JobsProcessed *prometheus.CounterVec } -// NewCollectors creates new Prometheus metric collectors +// NewCollectors creates new Prometheus metric collectors for testing. +// All metrics are prefixed with "prometheus_pusher_test_" to clearly indicate +// they are generated by the prometheus-pusher test/demo functionality. func NewCollectors() Collectors { return Collectors{ RequestsTotal: prometheus.NewCounter( prometheus.CounterOpts{ - Name: "app_requests_total", - Help: "Total number of requests processed", + Name: "prometheus_pusher_test_requests_total", + Help: "Total number of requests processed (test metric)", }, ), ActiveConnections: prometheus.NewGauge( prometheus.GaugeOpts{ - Name: "app_active_connections", - Help: "Number of currently active connections", + Name: "prometheus_pusher_test_active_connections", + Help: "Number of currently active connections (test metric)", }, ), TemperatureCelsius: prometheus.NewGauge( prometheus.GaugeOpts{ - Name: "app_temperature_celsius", - Help: "Current temperature in Celsius", + Name: "prometheus_pusher_test_temperature_celsius", + Help: "Current temperature in Celsius (test metric)", }, ), RequestDuration: prometheus.NewHistogram( prometheus.HistogramOpts{ - Name: "app_request_duration_seconds", - Help: "Histogram of request duration in seconds", + Name: "prometheus_pusher_test_request_duration_seconds", + Help: "Histogram of request duration in seconds (test metric)", Buckets: prometheus.DefBuckets, }, ), JobsProcessed: prometheus.NewCounterVec( prometheus.CounterOpts{ - Name: "app_jobs_processed_total", - Help: "Total number of jobs processed by type", + Name: "prometheus_pusher_test_jobs_processed_total", + Help: "Total number of jobs processed by type (test metric)", }, []string{"job_type", "status"}, ), |
