Escape PromQL query

Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis
2017-12-29 16:34:17 +00:00
parent 9f876ba94b
commit 979e44bf8c

View File

@ -7,6 +7,7 @@ import (
"log" "log"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url"
"strconv" "strconv"
"github.com/openfaas/faas/gateway/requests" "github.com/openfaas/faas/gateway/requests"
@ -56,8 +57,8 @@ func AddMetricsHandler(handler http.HandlerFunc, prometheusQuery PrometheusQuery
} }
// log.Printf("Querying Prometheus API\n") // log.Printf("Querying Prometheus API\n")
// `sum(gateway_function_invocation_total{function_name=~".*", code=~".*"}) by (function_name, code)`) expr := url.QueryEscape(`sum(gateway_function_invocation_total{function_name=~".*", code=~".*"}) by (function_name, code)`)
expr := "sum(gateway_function_invocation_total%7Bfunction_name%3D~%22.*%22%2C+code%3D~%22.*%22%7D)+by+(function_name%2C+code)" // expr := "sum(gateway_function_invocation_total%7Bfunction_name%3D~%22.*%22%2C+code%3D~%22.*%22%7D)+by+(function_name%2C+code)"
results, fetchErr := prometheusQuery.Fetch(expr) results, fetchErr := prometheusQuery.Fetch(expr)
if fetchErr != nil { if fetchErr != nil {
log.Printf("Error querying Prometheus API: %s\n", fetchErr.Error()) log.Printf("Error querying Prometheus API: %s\n", fetchErr.Error())