Respect path prefix in influx output uri (#3224)
This commit is contained in:
parent
eebee9759f
commit
9c8f4afa37
|
@ -84,9 +84,7 @@
|
||||||
|
|
||||||
# Configuration for influxdb server to send metrics to
|
# Configuration for influxdb server to send metrics to
|
||||||
[[outputs.influxdb]]
|
[[outputs.influxdb]]
|
||||||
## The HTTP or UDP URL for your InfluxDB instance. Each item should be
|
## The full HTTP or UDP URL for your InfluxDB instance.
|
||||||
## of the form:
|
|
||||||
## scheme "://" host [ ":" port]
|
|
||||||
##
|
##
|
||||||
## Multiple urls can be specified as part of the same cluster,
|
## Multiple urls can be specified as part of the same cluster,
|
||||||
## this means that only ONE of the urls will be written to each interval.
|
## this means that only ONE of the urls will be written to each interval.
|
||||||
|
|
|
@ -7,9 +7,7 @@ This plugin writes to [InfluxDB](https://www.influxdb.com) via HTTP or UDP.
|
||||||
```toml
|
```toml
|
||||||
# Configuration for influxdb server to send metrics to
|
# Configuration for influxdb server to send metrics to
|
||||||
[[outputs.influxdb]]
|
[[outputs.influxdb]]
|
||||||
## The HTTP or UDP URL for your InfluxDB instance. Each item should be
|
## The full HTTP or UDP URL for your InfluxDB instance.
|
||||||
## of the form:
|
|
||||||
## scheme "://" host [ ":" port]
|
|
||||||
##
|
##
|
||||||
## Multiple urls can be specified as part of the same cluster,
|
## Multiple urls can be specified as part of the same cluster,
|
||||||
## this means that only ONE of the urls will be written to each interval.
|
## this means that only ONE of the urls will be written to each interval.
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"path"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -305,8 +306,11 @@ func writeURL(u *url.URL, wp WriteParams) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
u.RawQuery = params.Encode()
|
u.RawQuery = params.Encode()
|
||||||
u.Path = "write"
|
p := u.Path
|
||||||
return u.String()
|
u.Path = path.Join(p, "write")
|
||||||
|
s := u.String()
|
||||||
|
u.Path = p
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func queryURL(u *url.URL, command string) string {
|
func queryURL(u *url.URL, command string) string {
|
||||||
|
@ -314,6 +318,9 @@ func queryURL(u *url.URL, command string) string {
|
||||||
params.Set("q", command)
|
params.Set("q", command)
|
||||||
|
|
||||||
u.RawQuery = params.Encode()
|
u.RawQuery = params.Encode()
|
||||||
u.Path = "query"
|
p := u.Path
|
||||||
return u.String()
|
u.Path = path.Join(p, "query")
|
||||||
|
s := u.String()
|
||||||
|
u.Path = p
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
|
|
@ -373,3 +373,39 @@ func TestGzipCompression(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, []byte(influxLine), uncompressed.Bytes())
|
assert.Equal(t, []byte(influxLine), uncompressed.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHTTPClient_PathPrefix(t *testing.T) {
|
||||||
|
prefix := "/some/random/prefix"
|
||||||
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch r.URL.Path {
|
||||||
|
case prefix + "/write":
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
case prefix + "/query":
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
fmt.Fprintln(w, `{"results":[{}]}`)
|
||||||
|
default:
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
msg := fmt.Sprintf("Path not found: %s", r.URL.Path)
|
||||||
|
fmt.Fprintln(w, msg)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
config := HTTPConfig{
|
||||||
|
URL: ts.URL + prefix,
|
||||||
|
}
|
||||||
|
wp := WriteParams{
|
||||||
|
Database: "test",
|
||||||
|
}
|
||||||
|
client, err := NewHTTP(config, wp)
|
||||||
|
defer client.Close()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
err = client.Query("CREATE DATABASE test")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
_, err = client.Write([]byte("cpu value=99\n"))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
_, err = client.WriteStream(bytes.NewReader([]byte("cpu value=99\n")), 13)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
|
@ -53,9 +53,7 @@ type InfluxDB struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var sampleConfig = `
|
var sampleConfig = `
|
||||||
## The HTTP or UDP URL for your InfluxDB instance. Each item should be
|
## The full HTTP or UDP URL for your InfluxDB instance.
|
||||||
## of the form:
|
|
||||||
## scheme "://" host [ ":" port]
|
|
||||||
##
|
##
|
||||||
## Multiple urls can be specified as part of the same cluster,
|
## Multiple urls can be specified as part of the same cluster,
|
||||||
## this means that only ONE of the urls will be written to each interval.
|
## this means that only ONE of the urls will be written to each interval.
|
||||||
|
|
Loading…
Reference in New Issue