Skip to content

Commit

Permalink
Merge pull request #2170 from influxdb/fix-2170-return-200-on-missing…
Browse files Browse the repository at this point in the history
…-tag

SELECT on tag that doesn't exist should return 200
  • Loading branch information
toddboom committed Apr 7, 2015
2 parents 622e3b2 + 59fc8b9 commit 40c21c1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
6 changes: 6 additions & 0 deletions httpd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"))
}
Expand Down
24 changes: 24 additions & 0 deletions httpd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 40c21c1

Please sign in to comment.