Skip to content

Commit 4a0d2bf

Browse files
Add detailed logging for responses in each handler (#110)
* Update probe_metrics_list.go * Update probe_metrics_resource.go with detailed logging for responses * Update probe_metrics_resourcegraph.go with detailed logging for responses * Update probe_metrics_scrape.go with detailed logging for responses * Update probe_metrics_subscription.go with detailed logging for responses
1 parent 1d499ab commit 4a0d2bf

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

probe_metrics_list.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212

1313
"github.com/webdevops/azure-metrics-exporter/config"
1414
"github.com/webdevops/azure-metrics-exporter/metrics"
15+
16+
"go.uber.org/zap"
1517
)
1618

1719
func probeMetricsListHandler(w http.ResponseWriter, r *http.Request) {
@@ -90,4 +92,11 @@ func probeMetricsListHandler(w http.ResponseWriter, r *http.Request) {
9092

9193
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
9294
h.ServeHTTP(w, r)
95+
96+
latency := time.Since(startTime)
97+
contextLogger.With(
98+
zap.String("method", r.Method),
99+
zap.Int("status", http.StatusOK),
100+
zap.String("latency", latency.String()),
101+
).Info("Request handled for /probe/metrics/list")
93102
}

probe_metrics_resource.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212

1313
"github.com/webdevops/azure-metrics-exporter/config"
1414
"github.com/webdevops/azure-metrics-exporter/metrics"
15+
16+
"go.uber.org/zap"
1517
)
1618

1719
func probeMetricsResourceHandler(w http.ResponseWriter, r *http.Request) {
@@ -101,4 +103,11 @@ func probeMetricsResourceHandler(w http.ResponseWriter, r *http.Request) {
101103

102104
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
103105
h.ServeHTTP(w, r)
106+
107+
latency := time.Since(startTime)
108+
contextLogger.With(
109+
zap.String("method", r.Method),
110+
zap.Int("status", http.StatusOK),
111+
zap.String("latency", latency.String()),
112+
).Info("Request handled for /probe/metrics/resource")
104113
}

probe_metrics_resourcegraph.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212

1313
"github.com/webdevops/azure-metrics-exporter/config"
1414
"github.com/webdevops/azure-metrics-exporter/metrics"
15+
16+
"go.uber.org/zap"
1517
)
1618

1719
func probeMetricsResourceGraphHandler(w http.ResponseWriter, r *http.Request) {
@@ -100,4 +102,11 @@ func probeMetricsResourceGraphHandler(w http.ResponseWriter, r *http.Request) {
100102

101103
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
102104
h.ServeHTTP(w, r)
105+
106+
latency := time.Since(startTime)
107+
contextLogger.With(
108+
zap.String("method", r.Method),
109+
zap.Int("status", http.StatusOK),
110+
zap.String("latency", latency.String()),
111+
).Info("Request handled for /probe/metrics/resourcegraph")
103112
}

probe_metrics_scrape.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212

1313
"github.com/webdevops/azure-metrics-exporter/config"
1414
"github.com/webdevops/azure-metrics-exporter/metrics"
15+
16+
"go.uber.org/zap"
1517
)
1618

1719
func probeMetricsScrapeHandler(w http.ResponseWriter, r *http.Request) {
@@ -102,4 +104,11 @@ func probeMetricsScrapeHandler(w http.ResponseWriter, r *http.Request) {
102104

103105
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
104106
h.ServeHTTP(w, r)
107+
108+
latency := time.Since(startTime)
109+
contextLogger.With(
110+
zap.String("method", r.Method),
111+
zap.Int("status", http.StatusOK),
112+
zap.String("latency", latency.String()),
113+
).Info("Request handled for /probe/metrics/scrape")
105114
}

probe_metrics_subscription.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212

1313
"github.com/webdevops/azure-metrics-exporter/config"
1414
"github.com/webdevops/azure-metrics-exporter/metrics"
15+
16+
"go.uber.org/zap"
1517
)
1618

1719
func probeMetricsSubscriptionHandler(w http.ResponseWriter, r *http.Request) {
@@ -82,4 +84,11 @@ func probeMetricsSubscriptionHandler(w http.ResponseWriter, r *http.Request) {
8284

8385
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
8486
h.ServeHTTP(w, r)
87+
88+
latency := time.Since(startTime)
89+
contextLogger.With(
90+
zap.String("method", r.Method),
91+
zap.Int("status", http.StatusOK),
92+
zap.String("latency", latency.String()),
93+
).Info("Request handled for /probe/metrics/subscription")
8594
}

0 commit comments

Comments
 (0)