From 228c0a0fcb7ccea78b8c621e60ff535d7fd2d551 Mon Sep 17 00:00:00 2001 From: Scott Trent Date: Tue, 30 Apr 2024 13:18:36 +0900 Subject: [PATCH] more diagnostic logging Signed-off-by: Scott Trent --- internal/controller/labelgroup_controller.go | 2 +- internal/controller/prometheus_manager.go | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/controller/labelgroup_controller.go b/internal/controller/labelgroup_controller.go index 176a5d7..de582e6 100644 --- a/internal/controller/labelgroup_controller.go +++ b/internal/controller/labelgroup_controller.go @@ -254,7 +254,7 @@ func (r *LabelGroupReconciler) SetupWithManager(mgr ctrl.Manager) error { For(&susqlv1.LabelGroup{}). Complete(r) - r.Logger.V(2).Info("[SetupWithmManager] Initializing Metrics Exporter.") + r.Logger.V(2).Info("[SetupWithManager] Initializing Metrics Exporter.") // Start server to export metrics r.InitializeMetricsExporter() diff --git a/internal/controller/prometheus_manager.go b/internal/controller/prometheus_manager.go index f29a3af..7efe8d6 100644 --- a/internal/controller/prometheus_manager.go +++ b/internal/controller/prometheus_manager.go @@ -164,6 +164,7 @@ var ( func (r *LabelGroupReconciler) InitializeMetricsExporter() { // Initiate the exporting of prometheus metrics for the energy + r.Logger.V(2).Info("Entering InitializeMetricsExporter().") if prometheusRegistry == nil { prometheusRegistry = prometheus.NewRegistry() prometheusRegistry.MustRegister(susqlMetrics.totalEnergy) @@ -172,19 +173,19 @@ func (r *LabelGroupReconciler) InitializeMetricsExporter() { http.Handle("/metrics", prometheusHandler) if metricsUrl, parseErr := url.Parse(r.SusQLPrometheusMetricsUrl); parseErr == nil { - r.Logger.V(2).Info(fmt.Sprintf("Serving metrics at '%s:%s'...\n", metricsUrl.Hostname(), metricsUrl.Port())) + r.Logger.V(2).Info(fmt.Sprintf("[InitializeMetricsExporter] Serving metrics at '%s:%s'...\n", metricsUrl.Hostname(), metricsUrl.Port())) go func() { err := http.ListenAndServe(metricsUrl.Hostname()+":"+metricsUrl.Port(), nil) if err != nil { - r.Logger.V(0).Error(err, "PANIC [SetAggregatedEnergyForLabels] ListenAndServe") - panic("PANIC [SetAggregatedEnergyForLabels]: ListenAndServe: " + err.Error()) + r.Logger.V(0).Error(err, "PANIC InitializeMetricsExporterSetAggregatedEnergyForLabels] ListenAndServe") + panic("PANIC [InitializeMetricsExporter]: ListenAndServe: " + err.Error()) } }() } else { - r.Logger.V(0).Error(parseErr, fmt.Sprintf("PANIC [SetAggregatedEnergyForLabels] Parsing the URL '%s' to set the metrics address didn't work.", r.SusQLPrometheusMetricsUrl)) - panic(fmt.Sprintf("PANIC [SetAggregatedEnergyForLabels]: Parsing the URL '%s' to set the metrics address didn't work (%v)", r.SusQLPrometheusMetricsUrl, parseErr)) + r.Logger.V(0).Error(parseErr, fmt.Sprintf("PANIC [InitializeMetricsExporter] Parsing the URL '%s' to set the metrics address didn't work.", r.SusQLPrometheusMetricsUrl)) + panic(fmt.Sprintf("PANIC [InitializeMetricsExporter]: Parsing the URL '%s' to set the metrics address didn't work (%v)", r.SusQLPrometheusMetricsUrl, parseErr)) } } }