diff --git a/README.md b/README.md index c6cfb64..37c9704 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,9 @@ name = "example-http" # TCP address to bind to, for HTTP server. bind-addr = "127.0.0.1:9096" +# Ping response code, default is 204 +default-ping-response = 200 + # Enable HTTPS requests. ssl-combined-pem = "/etc/ssl/influxdb-relay.pem" diff --git a/relay/config.go b/relay/config.go index 18131d9..bae7106 100644 --- a/relay/config.go +++ b/relay/config.go @@ -24,6 +24,9 @@ type HTTPConfig struct { // Default retention policy to set for forwarded requests DefaultRetentionPolicy string `toml:"default-retention-policy"` + // Default ping response + DefaultPingResponse int `toml:"default-ping-response"` + // Outputs is a list of backed servers where writes will be forwarded Outputs []HTTPOutputConfig `toml:"output"` } diff --git a/relay/http.go b/relay/http.go index 73d4f23..8ef9145 100644 --- a/relay/http.go +++ b/relay/http.go @@ -21,20 +21,24 @@ import ( // HTTP is a relay for HTTP influxdb writes type HTTP struct { - addr string - name string - schema string + addr string + name string + schema string - cert string - rp string + pingResponseCode int + pingResponseHeaders map[string]string - closing int64 - l net.Listener + cert string + rp string - backends []*httpBackend + closing int64 + l net.Listener + + backends []*httpBackend } const ( + DefaultHttpPingResponse = http.StatusNoContent DefaultHTTPTimeout = 10 * time.Second DefaultMaxDelayInterval = 10 * time.Second DefaultBatchSizeKB = 512 @@ -49,6 +53,16 @@ func NewHTTP(cfg HTTPConfig) (Relay, error) { h.addr = cfg.Addr h.name = cfg.Name + h.pingResponseCode = DefaultHttpPingResponse + if (cfg.DefaultPingResponse != 0) { + h.pingResponseCode = cfg.DefaultPingResponse + } + + h.pingResponseHeaders["X-InfluxDB-Version"] = "relay" + if (h.pingResponseCode != http.StatusNoContent) { + h.pingResponseHeaders["Content-Length"] = "0" + } + h.cert = cfg.SSLCombinedPem h.rp = cfg.DefaultRetentionPolicy @@ -114,9 +128,11 @@ func (h *HTTP) ServeHTTP(w http.ResponseWriter, r *http.Request) { start := time.Now() if r.URL.Path == "/ping" && (r.Method == "GET" || r.Method == "HEAD") { - w.Header().Add("X-InfluxDB-Version", "relay") - w.WriteHeader(http.StatusNoContent) - return + for key, value := range h.pingResponseHeaders { + w.Header().Add(key, value) + } + w.WriteHeader(h.pingResponseCode) + return } if r.URL.Path != "/write" { diff --git a/sample.toml b/sample.toml index 5152857..4518a33 100644 --- a/sample.toml +++ b/sample.toml @@ -3,6 +3,7 @@ [[http]] name = "example-http" bind-addr = "127.0.0.1:9096" +default-ping-response = 204 output = [ { name="local1", location = "http://127.0.0.1:8086/write" }, { name="local2", location = "http://127.0.0.1:7086/write" },