From e1472257b0399e9b3fa8e217039d34b267d1b7e3 Mon Sep 17 00:00:00 2001 From: Todd Persen Date: Tue, 7 Apr 2015 12:28:38 -0700 Subject: [PATCH 1/2] Make sure that we return a `200 OK` when querying for a tag that doesn't exist. --- httpd/handler.go | 6 ++++++ httpd/handler_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/httpd/handler.go b/httpd/handler.go index 5788d234710..d11066b3205 100644 --- a/httpd/handler.go +++ b/httpd/handler.go @@ -230,6 +230,8 @@ func (h *Handler) serveQuery(w http.ResponseWriter, r *http.Request, user *influ w.WriteHeader(http.StatusUnauthorized) } else if isMeasurementNotFoundError(r.Err) { w.WriteHeader(http.StatusOK) + } else if isTagNotFoundError(r.Err) { + w.WriteHeader(http.StatusOK) } else if isFieldNotFoundError(r.Err) { w.WriteHeader(http.StatusOK) } else { @@ -713,6 +715,10 @@ func isMeasurementNotFoundError(err error) bool { return strings.HasPrefix(s, "measurement") && strings.HasSuffix(s, "not found") || strings.Contains(s, "measurement not found") } +func isTagNotFoundError(err error) bool { + return (strings.HasPrefix(err.Error(), "unknown field or tag name")) +} + func isFieldNotFoundError(err error) bool { return (strings.HasPrefix(err.Error(), "field not found")) } diff --git a/httpd/handler_test.go b/httpd/handler_test.go index d44473e2579..60c0dd209ca 100644 --- a/httpd/handler_test.go +++ b/httpd/handler_test.go @@ -162,6 +162,30 @@ func TestHandler_ShowMeasurementsNotFound(t *testing.T) { } } +// Ensure that if a tag is not found, that the status code is 200 +func TestHandler_SelectTagNotFound(t *testing.T) { + c := test.NewDefaultMessagingClient() + defer c.Close() + srvr := OpenAuthlessServer(c) + srvr.CreateDatabase("foo") + s := NewAPIServer(srvr) + defer s.Close() + + // Write some data + status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "default", "points": [{"name": "bin", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}}]}`) + if status != http.StatusOK { + t.Fatalf("unexpected status: %d", status) + } + + status, body := MustHTTP("GET", s.URL+`/query`, map[string]string{"q": "SELECT * FROM bin WHERE region='regionA'", "db": "foo"}, nil, "") + if status != http.StatusOK { + t.Fatalf("unexpected status: %d", status) + } + if body != `{"results":[{"error":"unknown field or tag name in where clause: region"}]}` { + t.Fatalf("unexpected body: %s", body) + } +} + func TestHandler_CreateDatabase(t *testing.T) { c := test.NewDefaultMessagingClient() defer c.Close() From 59fc8b92159bcd0521dcae088545866a71d406a4 Mon Sep 17 00:00:00 2001 From: Todd Persen Date: Tue, 7 Apr 2015 13:43:37 -0700 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d2d3efcb4a..d680e4d7a45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Bugfixes - [#2181](https://github.com/influxdb/influxdb/pull/2181): Fix panic on "SHOW DIAGNOSTICS". +- [#2170](https://github.com/influxdb/influxdb/pull/2170): Make sure queries on missing tags return 200 status. ## v0.9.0-rc20 [2015-04-04]