-
Notifications
You must be signed in to change notification settings - Fork 344
Feature/ping response code #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
cert string | ||
rp string | ||
|
@@ -35,6 +36,7 @@ type HTTP struct { | |
} | ||
|
||
const ( | ||
DefaultHttpPingResponse = http.StatusNoContent | ||
DefaultHTTPTimeout = 10 * time.Second | ||
DefaultMaxDelayInterval = 10 * time.Second | ||
DefaultBatchSizeKB = 512 | ||
|
@@ -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 | ||
|
@@ -113,10 +116,15 @@ func (h *HTTP) Stop() error { | |
func (h *HTTP) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
start := time.Now() | ||
|
||
pingStatusResponse := DefaultHttpPingResponse | ||
|
||
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") | ||
|
||
w.WriteHeader(pingStatusResponse) | ||
return | ||
} | ||
|
||
if r.URL.Path != "/write" { | ||
|
There was a problem hiding this comment.
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.