Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
20 changes: 14 additions & 6 deletions relay/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (

// HTTP is a relay for HTTP influxdb writes
type HTTP struct {
addr string
name string
schema string
addr string
name string
schema string
response int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather see a name like pingResponseCode and have it separated by a newline so that it's visually separate from the above group of related fields.


cert string
rp string
Expand All @@ -35,6 +36,7 @@ type HTTP struct {
}

const (
DefaultHttpPingResponse = http.StatusNoContent
DefaultHTTPTimeout = 10 * time.Second
DefaultMaxDelayInterval = 10 * time.Second
DefaultBatchSizeKB = 512
Expand All @@ -48,6 +50,7 @@ func NewHTTP(cfg HTTPConfig) (Relay, error) {

h.addr = cfg.Addr
h.name = cfg.Name
h.response = cfg.DefaultPingResponse

h.cert = cfg.SSLCombinedPem
h.rp = cfg.DefaultRetentionPolicy
Expand Down Expand Up @@ -113,10 +116,15 @@ func (h *HTTP) Stop() error {
func (h *HTTP) ServeHTTP(w http.ResponseWriter, r *http.Request) {
start := time.Now()

pingStatusResponse := DefaultHttpPingResponse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole block should only happen once, and not on every request.

if (h.response != 0) {
pingStatusResponse = h.response
}

if r.URL.Path == "/ping" && (r.Method == "GET" || r.Method == "HEAD") {
w.Header().Add("X-InfluxDB-Version", "relay")
w.WriteHeader(http.StatusNoContent)
return
w.Header().Add("X-InfluxDB-Version", "relay")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is going to return codes other than 204, Content-Length should also be set to 0.

w.WriteHeader(pingStatusResponse)
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