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

Querying for missing measurements should return a 200 #1813

Merged
merged 3 commits into from
Mar 3, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions httpd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,25 @@ func isAuthorizationError(err error) bool {
return ok
}

func isMeasurementNotFoundError(err error) bool {
return (err.Error() == "measurement not found")
}

func isFieldNotFoundError(err error) bool {
return (strings.HasPrefix(err.Error(), "field not found"))
}

// httpResult writes a Results array to the client.
func httpResults(w http.ResponseWriter, results influxdb.Results, pretty bool) {
if results.Error() != nil {
if isAuthorizationError(results.Error()) {
w.WriteHeader(http.StatusUnauthorized)
} else if isMeasurementNotFoundError(results.Error()) {
w.WriteHeader(http.StatusOK)
} else if isFieldNotFoundError(results.Error()) {
w.WriteHeader(http.StatusOK)
} else {
fmt.Println(results.Error())
w.WriteHeader(http.StatusInternalServerError)
}
}
Expand Down
51 changes: 50 additions & 1 deletion httpd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,55 @@ func TestHandler_DropDatabase_NotFound(t *testing.T) {
}
}

func TestHandler_SelectMeasurement_NotFound(t *testing.T) {
srvr := OpenAuthlessServer(NewMessagingClient())
srvr.CreateDatabase("foo")
s := NewHTTPServer(srvr)
defer s.Close()

query := map[string]string{"q": "CREATE RETENTION POLICY bar ON foo DURATION 1h REPLICATION 1 DEFAULT"}
status, body := MustHTTP("GET", s.URL+`/query`, query, nil, "")

if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
} else if body != `{"results":[{}]}` {
t.Fatalf("unexpected body: %s", body)
}

status, body = MustHTTP("GET", s.URL+`/query`, map[string]string{"q": "SELECT value FROM foobarbaz", "db": "foo"}, nil, "")
if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
} else if body != `{"results":[{"error":"measurement not found"}]}` {
t.Fatalf("unexpected body: %s", body)
}
}

func TestHandler_SelectField_NotFound(t *testing.T) {
srvr := OpenAuthlessServer(NewMessagingClient())
srvr.CreateDatabase("foo")
s := NewHTTPServer(srvr)
defer s.Close()

query := map[string]string{"q": "CREATE RETENTION POLICY bar ON foo DURATION 1h REPLICATION 1 DEFAULT"}
status, body := MustHTTP("GET", s.URL+`/query`, query, nil, "")

if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
} else if body != `{"results":[{}]}` {
t.Fatalf("unexpected body: %s", body)
}

// Write some data
_, _ = MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}}]}`)

status, body = MustHTTP("GET", s.URL+`/query`, map[string]string{"q": "SELECT abc FROM cpu", "db": "foo"}, nil, "")
if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
} else if body != `{"results":[{"error":"field not found: abc"}]}` {
t.Fatalf("unexpected body: %s", body)
}
}

func TestHandler_RetentionPolicies(t *testing.T) {
srvr := OpenAuthlessServer(NewMessagingClient())
srvr.CreateDatabase("foo")
Expand Down Expand Up @@ -1560,7 +1609,7 @@ func TestHandler_serveWriteSeriesInvalidQueryField(t *testing.T) {

query := map[string]string{"db": "foo", "q": "select bar from cpu"}
status, body := MustHTTP("GET", s.URL+`/query`, query, nil, "")
if status != http.StatusInternalServerError {
if status != http.StatusOK {
t.Logf("query %s\n", query)
t.Log(body)
t.Errorf("unexpected status: %d", status)
Expand Down