Skip to content

Commit

Permalink
more diagnostic logging
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Trent <[email protected]>
  • Loading branch information
trent-s committed Apr 30, 2024
1 parent af31129 commit 228c0a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/controller/labelgroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 6 additions & 5 deletions internal/controller/prometheus_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
}
}
}
Expand Down

0 comments on commit 228c0a0

Please sign in to comment.