Skip to content

Commit

Permalink
Make sure that we return a 200 OK when querying for a tag that does…
Browse files Browse the repository at this point in the history
…n't exist.
  • Loading branch information
toddboom committed Apr 7, 2015
1 parent 214b405 commit e147225
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
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 e147225

Please sign in to comment.