Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused /validate_expr endpoint. #2152

Merged
merged 2 commits into from Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@
* `--querier.query-store-after` has been added in it's place.
* [CHANGE] Experimental Memberlist KV store can now be used in single-binary Cortex. Attempts to use it previously would fail with panic. This change also breaks existing binary protocol used to exchange gossip messages, so this version will not be able to understand gossiped Ring when used in combination with the previous version of Cortex. Easiest way to upgrade is to shutdown old Cortex installation, and restart it with new version. Incremental rollout works too, but with reduced functionality until all components run the same version. #2016
* [CHANGE] Renamed the cache configuration setting `defaul_validity` to `default_validity`. #2140
* [CHANGE] Removed unused /validate_expr endpoint. #2152
* [FEATURE] Added a read-only local alertmanager config store using files named corresponding to their tenant id. #2125
* [FEATURE] Added user sub rings to distribute users to a subset of ingesters. #1947
* `--experimental.distributor.user-subring-size`
Expand Down
1 change: 0 additions & 1 deletion pkg/cortex/modules.go
Expand Up @@ -262,7 +262,6 @@ func (t *Cortex) initQuerier(cfg *Config) (err error) {
subrouter := t.server.HTTP.PathPrefix("/api/prom").Subrouter()
subrouter.PathPrefix("/api/v1").Handler(t.httpAuthMiddleware.Wrap(promRouter))
subrouter.Path("/read").Handler(t.httpAuthMiddleware.Wrap(querier.RemoteReadHandler(queryable)))
subrouter.Path("/validate_expr").Handler(t.httpAuthMiddleware.Wrap(http.HandlerFunc(t.distributor.ValidateExprHandler)))
subrouter.Path("/chunks").Handler(t.httpAuthMiddleware.Wrap(querier.ChunksHandler(queryable)))
subrouter.Path("/user_stats").Handler(middleware.AuthenticateUser.Wrap(http.HandlerFunc(t.distributor.UserStatsHandler)))

Expand Down
42 changes: 0 additions & 42 deletions pkg/distributor/http_server.go
@@ -1,11 +1,9 @@
package distributor

import (
"fmt"
"net/http"

"github.com/go-kit/kit/log/level"
"github.com/prometheus/prometheus/promql"
"github.com/weaveworks/common/httpgrpc"

"github.com/cortexproject/cortex/pkg/ingester/client"
Expand Down Expand Up @@ -66,43 +64,3 @@ func (d *Distributor) UserStatsHandler(w http.ResponseWriter, r *http.Request) {

util.WriteJSONResponse(w, stats)
}

// ValidateExprHandler validates a PromQL expression.
func (d *Distributor) ValidateExprHandler(w http.ResponseWriter, r *http.Request) {
_, err := promql.ParseExpr(r.FormValue("expr"))

// We mimick the response format of Prometheus's official API here for
// consistency, but unfortunately its private types (string consts etc.)
// aren't reusable.
if err == nil {
util.WriteJSONResponse(w, map[string]string{
"status": "success",
})
return
}

parseErr, ok := err.(*promql.ParseErr)
if !ok {
// This should always be a promql.ParseErr.
http.Error(w, fmt.Sprintf("unexpected error returned from PromQL parser: %v", err), http.StatusInternalServerError)
return
}

// If the parsing input was a single line, parseErr.Line is 0
// and the generated error string omits the line entirely. But we
// want to report line numbers consistently, no matter how many
// lines there are (starting at 1).
if parseErr.Line == 0 {
parseErr.Line = 1
}
w.WriteHeader(http.StatusBadRequest)
util.WriteJSONResponse(w, map[string]interface{}{
"status": "error",
"errorType": "bad_data",
"error": err.Error(),
"location": map[string]int{
"line": parseErr.Line,
"pos": parseErr.Pos,
},
})
}