fix issue with phpfpm url usage (#8292)

This commit is contained in:
Steven Soroka 2020-10-20 11:45:30 -04:00 committed by GitHub
parent 5a5f6fbd47
commit 01230889b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -201,7 +201,7 @@ func (p *phpfpm) gatherHttp(addr string, acc telegraf.Accumulator) error {
return fmt.Errorf("unable parse server address '%s': %v", addr, err)
}
req, err := http.NewRequest("GET", fmt.Sprintf("%s://%s%s", u.Scheme, u.Host, u.Path), nil)
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
return fmt.Errorf("unable to create new request '%s': %v", addr, err)
}

View File

@ -25,12 +25,17 @@ func (s statServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
func TestPhpFpmGeneratesMetrics_From_Http(t *testing.T) {
sv := statServer{}
ts := httptest.NewServer(sv)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, "ok", r.URL.Query().Get("test"))
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Content-Length", fmt.Sprint(len(outputSample)))
fmt.Fprint(w, outputSample)
}))
defer ts.Close()
url := ts.URL + "?test=ok"
r := &phpfpm{
Urls: []string{ts.URL},
Urls: []string{url},
}
err := r.Init()
@ -43,7 +48,7 @@ func TestPhpFpmGeneratesMetrics_From_Http(t *testing.T) {
tags := map[string]string{
"pool": "www",
"url": ts.URL,
"url": url,
}
fields := map[string]interface{}{