Skip to content

Commit

Permalink
Continue after non-connectable address
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan committed Feb 20, 2024
1 parent d912d58 commit 63537f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
27 changes: 11 additions & 16 deletions plugins/inputs/phpfpm/phpfpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,21 @@ type phpfpm struct {
Format string `toml:"format"`
Timeout config.Duration `toml:"timeout"`
Urls []string `toml:"urls"`

Log telegraf.Logger `toml:"-"`
tls.ClientConfig

client *http.Client
Log telegraf.Logger
}

func (*phpfpm) SampleConfig() string {
return sampleConfig
}

func (p *phpfpm) Init() error {
if len(p.Urls) == 0 {
p.Urls = []string{"http://127.0.0.1/status"}
}

tlsCfg, err := p.ClientConfig.TLSConfig()
if err != nil {
return err
Expand All @@ -117,18 +121,8 @@ func (p *phpfpm) Init() error {
// Reads stats from all configured servers accumulates stats.
// Returns one of the errors encountered while gather stats (if any).
func (p *phpfpm) Gather(acc telegraf.Accumulator) error {
if len(p.Urls) == 0 {
return p.gatherServer("http://127.0.0.1/status", acc)
}

var wg sync.WaitGroup

urls, err := expandUrls(p.Urls)
if err != nil {
return err
}

for _, serv := range urls {
for _, serv := range expandUrls(acc, p.Urls) {
wg.Add(1)
go func(serv string) {
defer wg.Done()
Expand Down Expand Up @@ -347,7 +341,7 @@ func (p *phpfpm) parseJSON(r io.Reader, acc telegraf.Accumulator, addr string) {
}
}

func expandUrls(urls []string) ([]string, error) {
func expandUrls(acc telegraf.Accumulator, urls []string) []string {
addrs := make([]string, 0, len(urls))
for _, address := range urls {
if isNetworkURL(address) {
Expand All @@ -356,11 +350,12 @@ func expandUrls(urls []string) ([]string, error) {
}
paths, err := globUnixSocket(address)
if err != nil {
return nil, err
acc.AddError(err)
continue
}
addrs = append(addrs, paths...)
}
return addrs, nil
return addrs
}

func globUnixSocket(address string) ([]string, error) {
Expand Down
3 changes: 1 addition & 2 deletions plugins/inputs/phpfpm/phpfpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ func TestPhpFpmGeneratesMetrics_Throw_Error_When_Fpm_Status_Is_Not_Responding(t
require.NoError(t, r.Init())

var acc testutil.Accumulator

err := acc.GatherError(r.Gather)
require.ErrorContains(t, err, `unable to connect to phpfpm status page 'http://aninvalidone'`)
require.ErrorContains(t, err, `lookup aninvalidone`)
Expand Down Expand Up @@ -392,7 +391,7 @@ func TestGatherDespiteUnavailable(t *testing.T) {
defer tcp.Close()

s := statServer{}
go fcgi.Serve(tcp, s)
go fcgi.Serve(tcp, s) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway

//Now we tested again above server
r := &phpfpm{
Expand Down

0 comments on commit 63537f2

Please sign in to comment.