Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 3 additions & 0 deletions relay/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
38 changes: 27 additions & 11 deletions relay/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down