feat(httpd): Add config to specify availability of the Flux query API

pull/10403/head
Stuart Carnie 2018-10-18 15:33:34 -07:00
parent 39011702e3
commit a4dc81902a
2 changed files with 17 additions and 8 deletions

View File

@ -33,6 +33,7 @@ type Config struct {
LogEnabled bool `toml:"log-enabled"`
SuppressWriteLog bool `toml:"suppress-write-log"`
WriteTracing bool `toml:"write-tracing"`
FluxEnabled bool `toml:"flux-enabled"`
PprofEnabled bool `toml:"pprof-enabled"`
DebugPprofEnabled bool `toml:"debug-pprof-enabled"`
HTTPSEnabled bool `toml:"https-enabled"`
@ -58,6 +59,7 @@ type Config struct {
func NewConfig() Config {
return Config{
Enabled: true,
FluxEnabled: false,
BindAddress: DefaultBindAddress,
LogEnabled: true,
PprofEnabled: true,

View File

@ -179,10 +179,6 @@ func NewHandler(c Config) *Handler {
"prometheus-read", // Prometheus remote read
"POST", "/api/v1/prom/read", true, true, h.servePromRead,
},
Route{
"flux-read",
"POST", "/api/v2/query", true, true, h.serveFluxQuery,
},
Route{ // Ping
"ping",
"GET", "/ping", false, true, h.servePing,
@ -205,6 +201,20 @@ func NewHandler(c Config) *Handler {
},
}...)
fluxRoute := Route{
"flux-read",
"POST", "/api/v2/query", true, true, nil,
}
if !c.FluxEnabled {
fluxRoute.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Flux query service disabled. Verify flux-enabled=true in the [http] section of the InfluxDB config.", http.StatusNotFound)
}
} else {
fluxRoute.HandlerFunc = h.serveFluxQuery
}
h.AddRoutes(fluxRoute)
return h
}
@ -1112,8 +1122,6 @@ func (h *Handler) servePromRead(w http.ResponseWriter, r *http.Request, user met
}
func (h *Handler) serveFluxQuery(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
req, err := decodeQueryRequest(r)
if err != nil {
h.httpError(w, err.Error(), http.StatusBadRequest)
@ -1121,7 +1129,7 @@ func (h *Handler) serveFluxQuery(w http.ResponseWriter, r *http.Request) {
}
pr := req.ProxyRequest()
q, err := h.Controller.Query(ctx, pr.Compiler)
q, err := h.Controller.Query(r.Context(), pr.Compiler)
if err != nil {
h.httpError(w, err.Error(), http.StatusInternalServerError)
return
@ -1148,7 +1156,6 @@ func (h *Handler) serveFluxQuery(w http.ResponseWriter, r *http.Request) {
case "text/csv":
fallthrough
default:
if hd, ok := pr.Dialect.(httpDialect); !ok {
h.httpError(w, fmt.Sprintf("unsupported dialect over HTTP %T", req.Dialect), http.StatusBadRequest)
return