@cryptotaxi247 / netdata-1 / commits / b3e206c27

go.d phpfpm: debug log the response on decoding error (#17870)

Ilya Mashchenko committed Jun 13, 2024 at 13:42 UTC b3e206c271b37238d5d91d350e7f118efc5d42a2
2 files changed +26 -12
src/go/collectors/go.d.plugin/modules/phpfpm/client.go
+21 -2
@@ -11,6 +11,7 @@ import (
11 "strconv"
12 "time"
13
14 + "github.com/netdata/netdata/go/go.d.plugin/logger"
15 "github.com/netdata/netdata/go/go.d.plugin/pkg/web"
16
17 fcgiclient "github.com/kanocz/fcgi_client"
@@ -96,17 +97,21 @@ func (c *httpClient) getStatus() (*status, error) {
97 if err := c.dec(resp.Body, st); err != nil {
98 return nil, fmt.Errorf("error parsing HTTP response from '%s': %v", req.URL, err)
99 }
100 +
101 return st, nil
102 }
103
104 type socketClient struct {
105 + *logger.Logger
106 +
107 socket string
108 timeout time.Duration
109 env map[string]string
110 }
111
108 -func newSocketClient(socket string, timeout time.Duration, fcgiPath string) *socketClient {
112 +func newSocketClient(log *logger.Logger, socket string, timeout time.Duration, fcgiPath string) *socketClient {
113 return &socketClient{
114 + Logger: log,
115 socket: socket,
116 timeout: timeout,
117 env: map[string]string{
@@ -142,8 +147,13 @@ func (c *socketClient) getStatus() (*status, error) {
147 return nil, fmt.Errorf("error on reading response from socket '%s': %v", c.socket, err)
148 }
149
150 + if len(content) == 0 {
151 + return nil, fmt.Errorf("no data returned from socket '%s'", c.socket)
152 + }
153 +
154 st := &status{}
155 if err := json.Unmarshal(content, st); err != nil {
156 + c.Debugf("failed to JSON decode data: %s", string(content))
157 return nil, fmt.Errorf("error on decoding response from socket '%s': %v", c.socket, err)
158 }
159
@@ -151,13 +161,16 @@ func (c *socketClient) getStatus() (*status, error) {
161 }
162
163 type tcpClient struct {
164 + *logger.Logger
165 +
166 address string
167 timeout time.Duration
168 env map[string]string
169 }
170
159 -func newTcpClient(address string, timeout time.Duration, fcgiPath string) *tcpClient {
171 +func newTcpClient(log *logger.Logger, address string, timeout time.Duration, fcgiPath string) *tcpClient {
172 return &tcpClient{
173 + Logger: log,
174 address: address,
175 timeout: timeout,
176 env: map[string]string{
@@ -189,9 +202,15 @@ func (c *tcpClient) getStatus() (*status, error) {
202 return nil, fmt.Errorf("error on reading response from address '%s': %v", c.address, err)
203 }
204
205 + if len(content) == 0 {
206 + return nil, fmt.Errorf("no data returned from address '%s'", c.address)
207 + }
208 +
209 st := &status{}
210 if err := json.Unmarshal(content, st); err != nil {
211 + c.Debugf("failed to JSON decode data: %s", string(content))
212 return nil, fmt.Errorf("error on decoding response from address '%s': %v", c.address, err)
213 }
214 +
215 return st, nil
216 }
src/go/collectors/go.d.plugin/modules/phpfpm/init.go
+5 -10
@@ -30,8 +30,7 @@ func (p *Phpfpm) initHTTPClient() (*httpClient, error) {
30 return nil, fmt.Errorf("create HTTP client: %v", err)
31 }
32
33 - p.Debugf("using HTTP client, URL: %s", p.URL)
34 - p.Debugf("using timeout: %s", p.Timeout)
33 + p.Debugf("using HTTP client: url='%s', timeout='%s'", p.URL, p.Timeout)
34
35 return newHTTPClient(c, p.Request)
36 }
@@ -41,17 +40,13 @@ func (p *Phpfpm) initSocketClient() (*socketClient, error) {
40 return nil, fmt.Errorf("the socket '%s' does not exist: %v", p.Socket, err)
41 }
42
44 - p.Debugf("using socket client: %s", p.Socket)
45 - p.Debugf("using timeout: %s", p.Timeout)
46 - p.Debugf("using fcgi path: %s", p.FcgiPath)
43 + p.Debugf("using socket client: socket='%s', timeout='%s', fcgi_path='%s'", p.Socket, p.Timeout, p.FcgiPath)
44
48 - return newSocketClient(p.Socket, p.Timeout.Duration(), p.FcgiPath), nil
45 + return newSocketClient(p.Logger, p.Socket, p.Timeout.Duration(), p.FcgiPath), nil
46 }
47
48 func (p *Phpfpm) initTcpClient() (*tcpClient, error) {
52 - p.Debugf("using tcp client: %s", p.Address)
53 - p.Debugf("using timeout: %s", p.Timeout)
54 - p.Debugf("using fcgi path: %s", p.FcgiPath)
49 + p.Debugf("using tcp client: address='%s', timeout='%s', fcgi_path='%s'", p.Address, p.Timeout, p.FcgiPath)
50
56 - return newTcpClient(p.Address, p.Timeout.Duration(), p.FcgiPath), nil
51 + return newTcpClient(p.Logger, p.Address, p.Timeout.Duration(), p.FcgiPath), nil
52 }