diff --git a/internal/prober/multihttp/script.tmpl b/internal/prober/multihttp/script.tmpl index 1f018e802..7cbe357af 100644 --- a/internal/prober/multihttp/script.tmpl +++ b/internal/prober/multihttp/script.tmpl @@ -72,6 +72,7 @@ export default function() { let url; let currentCheck; let match; + const logResponse = {{ .LogResponses }} const vars = {}; {{ range $idx, $entry := .Entries }} @@ -97,7 +98,11 @@ export default function() { redirects: 0{{ if gt (len $headers) 0 }}, headers: {{ $headers }}{{ end }} }); - console.log("Response received from {{.Request.Url}}, status", response.status); + console.log("Response received from {{ .Request.Url }}, status", response.status); + if(logResponse) { + const body = response.body || '' + console.log("Response body received from {{ .Request.Url }}:", body.slice(0, 1000)); + } if(response.error) { console.error("Request error:" + url.toString() + ": " + response.error) } diff --git a/internal/prober/multihttp/script_test.go b/internal/prober/multihttp/script_test.go index d8f502d70..c99a37634 100644 --- a/internal/prober/multihttp/script_test.go +++ b/internal/prober/multihttp/script_test.go @@ -653,6 +653,7 @@ func TestSettingsToScript(t *testing.T) { t.Cleanup(testServer.Close) settings := &sm.MultiHttpSettings{ + LogResponses: true, Entries: []*sm.MultiHttpEntry{ { Request: &sm.MultiHttpEntryRequest{ diff --git a/pkg/pb/synthetic_monitoring/checks.pb.go b/pkg/pb/synthetic_monitoring/checks.pb.go index 21ef19f35..2ecf541f4 100644 --- a/pkg/pb/synthetic_monitoring/checks.pb.go +++ b/pkg/pb/synthetic_monitoring/checks.pb.go @@ -7,15 +7,14 @@ import ( context "context" encoding_binary "encoding/binary" fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -1755,7 +1754,8 @@ var xxx_messageInfo_K6Settings proto.InternalMessageInfo // MultiHttpSettings represents the settings for the MultiHttp check type. type MultiHttpSettings struct { - Entries []*MultiHttpEntry `protobuf:"bytes,1,rep,name=entries,proto3" json:"entries"` + Entries []*MultiHttpEntry `protobuf:"bytes,1,rep,name=entries,proto3" json:"entries"` + LogResponses bool `protobuf:"varint,2,opt,name=logResponses,proto3" json:"logResponseBodies,omitempty"` } func (m *MultiHttpSettings) Reset() { *m = MultiHttpSettings{} } @@ -4910,6 +4910,16 @@ func (m *MultiHttpSettings) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.LogResponses { + i-- + if m.LogResponses { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } if len(m.Entries) > 0 { for iNdEx := len(m.Entries) - 1; iNdEx >= 0; iNdEx-- { { @@ -6216,6 +6226,9 @@ func (m *MultiHttpSettings) Size() (n int) { n += 1 + l + sovChecks(uint64(l)) } } + if m.LogResponses { + n += 2 + } return n } @@ -12269,6 +12282,26 @@ func (m *MultiHttpSettings) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LogResponses", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowChecks + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.LogResponses = bool(v != 0) default: iNdEx = preIndex skippy, err := skipChecks(dAtA[iNdEx:]) diff --git a/pkg/pb/synthetic_monitoring/checks.proto b/pkg/pb/synthetic_monitoring/checks.proto index 575c54fc6..b267702c7 100644 --- a/pkg/pb/synthetic_monitoring/checks.proto +++ b/pkg/pb/synthetic_monitoring/checks.proto @@ -458,14 +458,15 @@ message K6Settings { // MultiHttpSettings represents the settings for the MultiHttp check type. message MultiHttpSettings { - repeated MultiHttpEntry entries = 1 [(gogoproto.jsontag) = "entries"]; // One or more entries in the MultiHttp check + repeated MultiHttpEntry entries = 1 [(gogoproto.jsontag) = "entries"]; // One or more entries in the MultiHttp check + bool logResponses = 2 [(gogoproto.jsontag) = "logResponseBodies,omitempty"]; // Whether to log the response bodies in the output. } // MultiHttpEntry represents a single entry in a MultiHttp check. message MultiHttpEntry { - MultiHttpEntryRequest request = 1 [(gogoproto.jsontag) = "request,omitempty"]; // The request parameters. - repeated MultiHttpEntryAssertion assertions = 2 [(gogoproto.jsontag) = "checks,omitempty"]; // Zero or more assertions to be made on the response. - repeated MultiHttpEntryVariable variables = 3 [(gogoproto.jsontag) = "variables,omitempty"]; // Zero or more variables to be used in the request. + MultiHttpEntryRequest request = 1 [(gogoproto.jsontag) = "request,omitempty"]; // The request parameters. + repeated MultiHttpEntryAssertion assertions = 2 [(gogoproto.jsontag) = "checks,omitempty"]; // Zero or more assertions to be made on the response. + repeated MultiHttpEntryVariable variables = 3 [(gogoproto.jsontag) = "variables,omitempty"]; // Zero or more variables to be used in the request. } // HttpHeader represents a single HTTP header key-value pair.