Skip to content

Commit

Permalink
fix: weird data is coming through, rebuild and etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
kashalls committed Feb 11, 2024
1 parent ebf9558 commit a7f1258
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func main() {
}

// Run the Prometheus query
result, _, err := v1api.Query(r.Context(), metric.Query, time.Now())
result, warnings, err := v1api.Query(r.Context(), metric.Query, time.Now())
if err != nil {
slog.Error(
"error executing query",
Expand All @@ -143,6 +143,10 @@ func main() {
return
}

if len(warnings) > 0 {
fmt.Println("Warnings while executing query:", warnings)
}

// Convert the result to JSON
jsonResult, err := json.Marshal(result)
slog.Debug(
Expand Down Expand Up @@ -182,12 +186,14 @@ func main() {

if (len(metric.Label) > 0) {
matrix, ok := result.(model.Matrix)
fmt.Printf("result a: '%s'", matrix)
if (!ok) {
slog.Error(
"unexpected result type",
slog.String("ip", r.RemoteAddr),
slog.String("metric", metric.Name),
"error", result,
"what we got", matrix,
)
http.Error(w, "Unexpected result from server.", http.StatusBadGateway)
return
Expand Down

0 comments on commit a7f1258

Please sign in to comment.