fix #1717: all points must have at least one field
parent
42ad52deca
commit
95a5f2588e
|
@ -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) {
|
func TestHandler_serveWriteSeriesWithAuthNilUser(t *testing.T) {
|
||||||
srvr := OpenAuthenticatedServer(NewMessagingClient())
|
srvr := OpenAuthenticatedServer(NewMessagingClient())
|
||||||
srvr.CreateDatabase("foo")
|
srvr.CreateDatabase("foo")
|
||||||
|
|
|
@ -1369,6 +1369,13 @@ type Point struct {
|
||||||
// WriteSeries writes series data to the database.
|
// WriteSeries writes series data to the database.
|
||||||
// Returns the messaging index the data was written to.
|
// Returns the messaging index the data was written to.
|
||||||
func (s *Server) WriteSeries(database, retentionPolicy string, points []Point) (uint64, error) {
|
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 the retention policy is not set, use the default for this database.
|
||||||
if retentionPolicy == "" {
|
if retentionPolicy == "" {
|
||||||
rp, err := s.DefaultRetentionPolicy(database)
|
rp, err := s.DefaultRetentionPolicy(database)
|
||||||
|
|
Loading…
Reference in New Issue