Skip to content

Commit

Permalink
fix issue with phpfpm url usage (influxdata#8292)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssoroka authored Oct 20, 2020
1 parent 73dd32e commit c3b6d12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion plugins/inputs/phpfpm/phpfpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 9 additions & 4 deletions plugins/inputs/phpfpm/phpfpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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{}{
Expand Down

0 comments on commit c3b6d12

Please sign in to comment.