remove debug output and add empty post body test
This commit is contained in:
parent
e9d3870778
commit
cf08b56460
|
@ -106,16 +106,10 @@ func (t *HttpListener) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
||||||
var path = req.URL.Path[1:]
|
var path = req.URL.Path[1:]
|
||||||
|
|
||||||
if path == "write" {
|
if path == "write" {
|
||||||
log.Printf("Received write request: [%s]\n", string(body))
|
|
||||||
|
|
||||||
var metrics []telegraf.Metric
|
var metrics []telegraf.Metric
|
||||||
if len(body) == 0 {
|
|
||||||
log.Printf("No metrics to parse\n")
|
|
||||||
} else {
|
|
||||||
metrics, err = t.parser.Parse(body)
|
metrics, err = t.parser.Parse(body)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.storeMetrics(metrics)
|
t.storeMetrics(metrics)
|
||||||
log.Printf("Persisted %d metrics\n", len(metrics))
|
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Problem parsing body: [%s], Error: %s\n", string(body), err)
|
log.Printf("Problem parsing body: [%s], Error: %s\n", string(body), err)
|
||||||
res.WriteHeader(500)
|
res.WriteHeader(500)
|
||||||
|
@ -123,17 +117,14 @@ func (t *HttpListener) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
res.WriteHeader(204)
|
res.WriteHeader(204)
|
||||||
res.Write([]byte(""))
|
res.Write([]byte(""))
|
||||||
}
|
|
||||||
} else if path == "query" {
|
} else if path == "query" {
|
||||||
// Deliver a dummy response to the query endpoint, as some InfluxDB clients test endpoint availability with a query
|
// Deliver a dummy response to the query endpoint, as some InfluxDB clients test endpoint availability with a query
|
||||||
log.Printf("Received query request: [%s]\n", string(body))
|
|
||||||
res.Header().Set("Content-Type", "application/json")
|
res.Header().Set("Content-Type", "application/json")
|
||||||
res.Header().Set("X-Influxdb-Version", "1.0")
|
res.Header().Set("X-Influxdb-Version", "1.0")
|
||||||
res.WriteHeader(200)
|
res.WriteHeader(200)
|
||||||
res.Write([]byte("{\"results\":[]}"))
|
res.Write([]byte("{\"results\":[]}"))
|
||||||
} else {
|
} else {
|
||||||
// Don't know how to respond to calls to other endpoints
|
// Don't know how to respond to calls to other endpoints
|
||||||
log.Printf("Received unknown %s request: [%s]\n", path, string(body))
|
|
||||||
res.WriteHeader(404)
|
res.WriteHeader(404)
|
||||||
res.Write([]byte("Not Found"))
|
res.Write([]byte("Not Found"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ cpu_load_short,host=server05 value=12.0 1422568543702900257
|
||||||
cpu_load_short,host=server06 value=12.0 1422568543702900257
|
cpu_load_short,host=server06 value=12.0 1422568543702900257
|
||||||
`
|
`
|
||||||
badMsg = "blahblahblah: 42\n"
|
badMsg = "blahblahblah: 42\n"
|
||||||
|
|
||||||
|
emptyMsg = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestHttpListener() (*HttpListener) {
|
func newTestHttpListener() (*HttpListener) {
|
||||||
|
@ -46,7 +48,7 @@ func TestWriteHTTP(t *testing.T) {
|
||||||
// post single message to listener
|
// post single message to listener
|
||||||
var resp, err = http.Post("http://localhost:8186/write?db=mydb", "", bytes.NewBuffer([]byte(testMsg)))
|
var resp, err = http.Post("http://localhost:8186/write?db=mydb", "", bytes.NewBuffer([]byte(testMsg)))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.EqualValues(t, resp.StatusCode, 204)
|
require.EqualValues(t, 204, resp.StatusCode)
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * 15)
|
time.Sleep(time.Millisecond * 15)
|
||||||
acc.AssertContainsTaggedFields(t, "cpu_load_short",
|
acc.AssertContainsTaggedFields(t, "cpu_load_short",
|
||||||
|
@ -57,7 +59,7 @@ func TestWriteHTTP(t *testing.T) {
|
||||||
// post multiple message to listener
|
// post multiple message to listener
|
||||||
resp, err = http.Post("http://localhost:8186/write?db=mydb", "", bytes.NewBuffer([]byte(testMsgs)))
|
resp, err = http.Post("http://localhost:8186/write?db=mydb", "", bytes.NewBuffer([]byte(testMsgs)))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.EqualValues(t, resp.StatusCode, 204)
|
require.EqualValues(t, 204, resp.StatusCode)
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * 15)
|
time.Sleep(time.Millisecond * 15)
|
||||||
hostTags := []string{"server02", "server03",
|
hostTags := []string{"server02", "server03",
|
||||||
|
@ -85,7 +87,25 @@ func TestWriteHTTPInvalid(t *testing.T) {
|
||||||
// post single message to listener
|
// post single message to listener
|
||||||
var resp, err = http.Post("http://localhost:8186/write?db=mydb", "", bytes.NewBuffer([]byte(badMsg)))
|
var resp, err = http.Post("http://localhost:8186/write?db=mydb", "", bytes.NewBuffer([]byte(badMsg)))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.EqualValues(t, resp.StatusCode, 500)
|
require.EqualValues(t, 500, resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWriteHTTPEmpty(t *testing.T) {
|
||||||
|
time.Sleep(time.Millisecond * 250)
|
||||||
|
|
||||||
|
listener := newTestHttpListener()
|
||||||
|
listener.parser, _ = parsers.NewInfluxParser()
|
||||||
|
|
||||||
|
acc := &testutil.Accumulator{}
|
||||||
|
require.NoError(t, listener.Start(acc))
|
||||||
|
defer listener.Stop()
|
||||||
|
|
||||||
|
time.Sleep(time.Millisecond * 25)
|
||||||
|
|
||||||
|
// post single message to listener
|
||||||
|
var resp, err = http.Post("http://localhost:8186/write?db=mydb", "", bytes.NewBuffer([]byte(emptyMsg)))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.EqualValues(t, 204, resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQueryHTTP(t *testing.T) {
|
func TestQueryHTTP(t *testing.T) {
|
||||||
|
@ -103,6 +123,6 @@ func TestQueryHTTP(t *testing.T) {
|
||||||
// post query to listener
|
// post query to listener
|
||||||
var resp, err = http.Post("http://localhost:8186/query?db=&q=CREATE+DATABASE+IF+NOT+EXISTS+%22mydb%22", "", nil)
|
var resp, err = http.Post("http://localhost:8186/query?db=&q=CREATE+DATABASE+IF+NOT+EXISTS+%22mydb%22", "", nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.EqualValues(t, resp.StatusCode, 200)
|
require.EqualValues(t, 200, resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue