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:]
|
||||
|
||||
if path == "write" {
|
||||
log.Printf("Received write request: [%s]\n", string(body))
|
||||
|
||||
var metrics []telegraf.Metric
|
||||
if len(body) == 0 {
|
||||
log.Printf("No metrics to parse\n")
|
||||
} else {
|
||||
metrics, err = t.parser.Parse(body)
|
||||
if err == nil {
|
||||
t.storeMetrics(metrics)
|
||||
log.Printf("Persisted %d metrics\n", len(metrics))
|
||||
} else {
|
||||
log.Printf("Problem parsing body: [%s], Error: %s\n", string(body), err)
|
||||
res.WriteHeader(500)
|
||||
|
@ -123,17 +117,14 @@ func (t *HttpListener) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
res.WriteHeader(204)
|
||||
res.Write([]byte(""))
|
||||
}
|
||||
} else if path == "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("X-Influxdb-Version", "1.0")
|
||||
res.WriteHeader(200)
|
||||
res.Write([]byte("{\"results\":[]}"))
|
||||
} else {
|
||||
// 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.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
|
||||
`
|
||||
badMsg = "blahblahblah: 42\n"
|
||||
|
||||
emptyMsg = ""
|
||||
)
|
||||
|
||||
func newTestHttpListener() (*HttpListener) {
|
||||
|
@ -46,7 +48,7 @@ func TestWriteHTTP(t *testing.T) {
|
|||
// post single message to listener
|
||||
var resp, err = http.Post("http://localhost:8186/write?db=mydb", "", bytes.NewBuffer([]byte(testMsg)))
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, resp.StatusCode, 204)
|
||||
require.EqualValues(t, 204, resp.StatusCode)
|
||||
|
||||
time.Sleep(time.Millisecond * 15)
|
||||
acc.AssertContainsTaggedFields(t, "cpu_load_short",
|
||||
|
@ -57,7 +59,7 @@ func TestWriteHTTP(t *testing.T) {
|
|||
// post multiple message to listener
|
||||
resp, err = http.Post("http://localhost:8186/write?db=mydb", "", bytes.NewBuffer([]byte(testMsgs)))
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, resp.StatusCode, 204)
|
||||
require.EqualValues(t, 204, resp.StatusCode)
|
||||
|
||||
time.Sleep(time.Millisecond * 15)
|
||||
hostTags := []string{"server02", "server03",
|
||||
|
@ -85,7 +87,25 @@ func TestWriteHTTPInvalid(t *testing.T) {
|
|||
// post single message to listener
|
||||
var resp, err = http.Post("http://localhost:8186/write?db=mydb", "", bytes.NewBuffer([]byte(badMsg)))
|
||||
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) {
|
||||
|
@ -103,6 +123,6 @@ func TestQueryHTTP(t *testing.T) {
|
|||
// post query to listener
|
||||
var resp, err = http.Post("http://localhost:8186/query?db=&q=CREATE+DATABASE+IF+NOT+EXISTS+%22mydb%22", "", nil)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, resp.StatusCode, 200)
|
||||
require.EqualValues(t, 200, resp.StatusCode)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue