Merge pull request #2180 from influxdb/http-gzip-posts
Allow http write handler to decode gzipped bodypull/2187/head
commit
fadcef0bd3
|
@ -2,6 +2,7 @@
|
|||
|
||||
### Features
|
||||
- [#870](https://github.com/influxdb/influxdb/pull/870): Add support for OpenTSDB telnet input protocol. Thanks @tcolgate
|
||||
- [#2180](https://github.com/influxdb/influxdb/pull/2180): Allow http write handler to decode gzipped body
|
||||
- [#2175](https://github.com/influxdb/influxdb/pull/2175): Separate broker and data nodes
|
||||
|
||||
## v0.9.0-rc20 [2015-04-04]
|
||||
|
|
|
@ -439,11 +439,32 @@ func (h *Handler) serveDump(w http.ResponseWriter, r *http.Request, user *influx
|
|||
|
||||
// serveWrite receives incoming series data and writes it to the database.
|
||||
func (h *Handler) serveWrite(w http.ResponseWriter, r *http.Request, user *influxdb.User) {
|
||||
var writeError = func(result influxdb.Result, statusCode int) {
|
||||
w.Header().Add("content-type", "application/json")
|
||||
w.WriteHeader(statusCode)
|
||||
_ = json.NewEncoder(w).Encode(&result)
|
||||
return
|
||||
}
|
||||
|
||||
// Check to see if we have a gzip'd post
|
||||
var body io.ReadCloser
|
||||
if r.Header.Get("Content-encoding") == "gzip" {
|
||||
b, err := gzip.NewReader(r.Body)
|
||||
if err != nil {
|
||||
writeError(influxdb.Result{Err: err}, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
body = b
|
||||
defer r.Body.Close()
|
||||
} else {
|
||||
body = r.Body
|
||||
}
|
||||
|
||||
var bp client.BatchPoints
|
||||
var dec *json.Decoder
|
||||
|
||||
if h.WriteTrace {
|
||||
b, err := ioutil.ReadAll(r.Body)
|
||||
b, err := ioutil.ReadAll(body)
|
||||
if err != nil {
|
||||
h.Logger.Print("write handler failed to read bytes from request body")
|
||||
} else {
|
||||
|
@ -451,15 +472,8 @@ func (h *Handler) serveWrite(w http.ResponseWriter, r *http.Request, user *influ
|
|||
}
|
||||
dec = json.NewDecoder(strings.NewReader(string(b)))
|
||||
} else {
|
||||
dec = json.NewDecoder(r.Body)
|
||||
defer r.Body.Close()
|
||||
}
|
||||
|
||||
var writeError = func(result influxdb.Result, statusCode int) {
|
||||
w.Header().Add("content-type", "application/json")
|
||||
w.WriteHeader(statusCode)
|
||||
_ = json.NewEncoder(w).Encode(&result)
|
||||
return
|
||||
dec = json.NewDecoder(body)
|
||||
defer body.Close()
|
||||
}
|
||||
|
||||
if err := dec.Decode(&bp); err != nil {
|
||||
|
@ -501,6 +515,7 @@ func (h *Handler) serveWrite(w http.ResponseWriter, r *http.Request, user *influ
|
|||
writeError(influxdb.Result{Err: err}, http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Header().Add("X-InfluxDB-Index", fmt.Sprintf("%d", index))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,12 @@ curl -G http://localhost:8086/query --data-urlencode "q=CREATE DATABASE foo"
|
|||
echo "creating retention policy"
|
||||
curl -G http://localhost:8086/query --data-urlencode "q=CREATE RETENTION POLICY bar ON foo DURATION 1h REPLICATION 3 DEFAULT"
|
||||
|
||||
echo '{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2015-01-26T22:01:11.703Z","fields": {"value": 123}}]}' | gzip > ./foo.zip
|
||||
echo '{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2015-01-26T22:01:11.703Z","fields": {"value": 123}}]}' | gzip > foo.json.gz
|
||||
|
||||
echo "inserting data"
|
||||
curl -v -i --compressed -H "Content-encoding: gzip" -H "Content-Type: application/json" -X POST --data-binary ./foo.zip http://localhost:8086/write
|
||||
curl -v -i -H "Content-encoding: gzip" -H "Content-Type: application/json" -X POST -T foo.json.gz http://localhost:8086/write
|
||||
|
||||
rm ./foo.zip
|
||||
rm foo.json.gz
|
||||
|
||||
echo "querying data with gzip encoding"
|
||||
curl -v -G --compressed http://localhost:8086/query --data-urlencode "db=foo" --data-urlencode "q=SELECT sum(value) FROM \"foo\".\"bar\".cpu GROUP BY time(1h)"
|
||||
|
|
Loading…
Reference in New Issue