@cryptotaxi247 / netdata-1 / commits / 9dbdc6d61

improvement(go.d/httpcheck): add resp validation debug logging (#20392)

Ilya Mashchenko committed Jun 2, 2025 at 14:15 UTC 9dbdc6d6149b24eb7df5fb4c5c92205c239a9029
1 file changed +18 -3
src/go/plugin/go.d/collector/httpcheck/collect.go
+18 -3
@@ -6,12 +6,14 @@ import (
6 "errors"
7 "fmt"
8 "io"
9 + "log/slog"
10 "net"
11 "net/http"
12 "os"
13 "strings"
14 "time"
15
16 + "github.com/netdata/netdata/go/plugins/logger"
17 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/stm"
18 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
19 )
@@ -97,9 +99,22 @@ func (c *Collector) collectOKResponse(mx *metrics, resp *http.Response) {
99
100 mx.ResponseLength = len(bs)
101
100 - if c.reResponse != nil && !c.reResponse.Match(bs) {
101 - mx.Status.BadContent = true
102 - return
102 + if c.reResponse != nil {
103 + matched := c.reResponse.Match(bs)
104 +
105 + if logger.Level.Enabled(slog.LevelDebug) {
106 + c.Debugf("response validation: pattern=%s, matched=%v, bodySize=%d", c.reResponse, matched, len(bs))
107 + if len(bs) <= 1024 {
108 + c.Debugf("response body: %s", string(bs))
109 + } else {
110 + c.Debugf("response body (first 1024 bytes): %s...", string(bs[:1024]))
111 + }
112 + }
113 +
114 + if !matched {
115 + mx.Status.BadContent = true
116 + return
117 + }
118 }
119
120 if ok := c.checkHeader(resp); !ok {