diff --git a/httpd/handler_test.go b/httpd/handler_test.go index 85ae611761..a04558a746 100644 --- a/httpd/handler_test.go +++ b/httpd/handler_test.go @@ -1191,6 +1191,24 @@ func TestHandler_serveWriteSeries(t *testing.T) { } } +func TestHandler_serveWriteSeriesWithNoFields(t *testing.T) { + srvr := OpenAuthenticatedServer(NewMessagingClient()) + srvr.CreateDatabase("foo") + srvr.CreateRetentionPolicy("foo", influxdb.NewRetentionPolicy("bar")) + s := NewHTTPServer(srvr) + defer s.Close() + + status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z"}]}`) + + expected := `{"error":"point cpu has no fields"}` + + if status != http.StatusInternalServerError { + t.Fatalf("unexpected status: %d", status) + } else if body != expected { + t.Fatalf("result mismatch:\n\texp=%s\n\tgot=%s\n", expected, body) + } +} + func TestHandler_serveWriteSeriesWithAuthNilUser(t *testing.T) { srvr := OpenAuthenticatedServer(NewMessagingClient()) srvr.CreateDatabase("foo") diff --git a/server.go b/server.go index 1f78fb8cdd..b856ed8762 100644 --- a/server.go +++ b/server.go @@ -1369,6 +1369,13 @@ type Point struct { // WriteSeries writes series data to the database. // Returns the messaging index the data was written to. func (s *Server) WriteSeries(database, retentionPolicy string, points []Point) (uint64, error) { + // Make sure every point has at least one field. + for _, p := range points { + if len(p.Fields) == 0 { + return 0, fmt.Errorf("point %s has no fields", p.Name) + } + } + // If the retention policy is not set, use the default for this database. if retentionPolicy == "" { rp, err := s.DefaultRetentionPolicy(database)