Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to log multihttp responses #550

Merged
merged 7 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion internal/prober/multihttp/script.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default function() {
let url;
let currentCheck;
let match;
const logResponse = {{ .LogResponses }}
const vars = {};

{{ range $idx, $entry := .Entries }}
Expand All @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions internal/prober/multihttp/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ func TestSettingsToScript(t *testing.T) {
t.Cleanup(testServer.Close)

settings := &sm.MultiHttpSettings{
LogResponses: true,
Entries: []*sm.MultiHttpEntry{
{
Request: &sm.MultiHttpEntryRequest{
Expand Down
43 changes: 38 additions & 5 deletions pkg/pb/synthetic_monitoring/checks.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions pkg/pb/synthetic_monitoring/checks.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading