Skip to content

Commit

Permalink
Format httpQuery inner values as arrays (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfeldbaum authored Apr 12, 2022
1 parent 9b60b65 commit 2fe6b76
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions emitter/gkelog/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,14 @@ func jsonHTTPRequest(ctx context.Context, w *bytes.Buffer) {
}
jsonKey(w, q)
v := query[q]
if len(v) > 1 {
w.WriteByte('[')
}
w.WriteByte('[')
for j, v0 := range v {
if j > 0 {
w.WriteString(", ")
}
jsonString(w, v0)
}
if len(v) > 1 {
w.WriteByte(']')
}
w.WriteByte(']')
}
w.WriteByte('}')
w.WriteString(", ")
Expand Down
4 changes: 2 additions & 2 deletions emitter/gkelog/emitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestRequest(t *testing.T) {
ctx := context.Background()
l := alog.New(alog.WithEmitter(Emitter(WithWriter(b))), zeroTimeOpt)

req := httptest.NewRequest(http.MethodGet, "/test/endpoint?q=1&c=pink", strings.NewReader("this is a test"))
req := httptest.NewRequest(http.MethodGet, "/test/endpoint?q=1&c=pink&c=red", strings.NewReader("this is a test"))
req.Header.Set("User-Agent", "curl/7.54.0")
req.Header.Set("Referer", "https://vimeo.com")
req.Header.Set("X-Cloud-Trace-Context", "a2fbf27a2ed90077e0d4af0e40a241f9/12690385211238481741")
Expand All @@ -106,7 +106,7 @@ func TestRequest(t *testing.T) {

l.Print(ctx, "test")

want := `{"time":"0001-01-01T00:00:00Z", "httpRequest":{"requestMethod":"GET", "requestUrl":"/test/endpoint?q=1&c=pink", "userAgent":"curl/7.54.0", "referer":"https://vimeo.com"}, "httpHeaders":{"Content-Type":["text/plain"], "Dnt":["1"], "X-Varnish":["731698977", "4193052513"]}, "httpQuery":{"c":"pink", "q":"1"}, "logging.googleapis.com/trace":"a2fbf27a2ed90077e0d4af0e40a241f9", "logging.googleapis.com/spanId":"b01d4e1cf2bd7f4d", "logging.googleapis.com/trace_sampled":true, "message":"test"}` + "\n"
want := `{"time":"0001-01-01T00:00:00Z", "httpRequest":{"requestMethod":"GET", "requestUrl":"/test/endpoint?q=1&c=pink&c=red", "userAgent":"curl/7.54.0", "referer":"https://vimeo.com"}, "httpHeaders":{"Content-Type":["text/plain"], "Dnt":["1"], "X-Varnish":["731698977", "4193052513"]}, "httpQuery":{"c":["pink", "red"], "q":["1"]}, "logging.googleapis.com/trace":"a2fbf27a2ed90077e0d4af0e40a241f9", "logging.googleapis.com/spanId":"b01d4e1cf2bd7f4d", "logging.googleapis.com/trace_sampled":true, "message":"test"}` + "\n"
got := b.String()
if got != want {
t.Errorf("got:\n%s\nwant:\n%s", got, want)
Expand Down

0 comments on commit 2fe6b76

Please sign in to comment.