Skip to content

Commit cf18bd5

Browse files
authored
Make logger goroutine safe (#478)
* Make logger goroutine safe Improve performance of JSON logging. Change text format to be consistent with default Go format. * Add back cleanup
1 parent 11f7e88 commit cf18bd5

File tree

14 files changed

+653
-1711
lines changed

14 files changed

+653
-1711
lines changed

clue/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import (
1616
tracenoop "go.opentelemetry.io/otel/trace/noop"
1717

1818
"goa.design/clue/log"
19+
20+
// Force dependency on main module to ensure it is unambiguous during
21+
// module resolution.
22+
// See: https://github.com/googleapis/google-api-go-client/issues/2559.
23+
_ "google.golang.org/genproto/googleapis/type/datetime"
1924
)
2025

2126
type (

debug/debug_test.go

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"net/http/httptest"
1010
"testing"
1111

12+
"github.com/stretchr/testify/assert"
13+
"github.com/stretchr/testify/require"
1214
"goa.design/clue/internal/testsvc"
1315
"goa.design/clue/internal/testsvc/gen/test"
1416
"goa.design/clue/log"
@@ -66,12 +68,8 @@ func TestMountDebugLogEnabler(t *testing.T) {
6668

6769
status, resp := makeRequest(t, ts.URL+c.url)
6870

69-
if status != http.StatusOK {
70-
t.Errorf("%s: got status %d, expected %d", c.name, status, http.StatusOK)
71-
}
72-
if resp != c.expectedResp {
73-
t.Errorf("%s: got body %q, expected %q", c.name, resp, c.expectedResp)
74-
}
71+
assert.Equal(t, http.StatusOK, status)
72+
assert.Equal(t, c.expectedResp, resp)
7573
})
7674
}
7775
}
@@ -93,12 +91,8 @@ func TestMountPprofHandlers(t *testing.T) {
9391
defer ts.Close()
9492

9593
status, resp := makeRequest(t, ts.URL)
96-
if status != http.StatusOK {
97-
t.Errorf("got status %d, expected %d", status, http.StatusOK)
98-
}
99-
if resp != "OK" {
100-
t.Errorf("got body %q, expected %q", resp, "OK")
101-
}
94+
assert.Equal(t, http.StatusOK, status)
95+
assert.Equal(t, "OK", resp)
10296

10397
paths := []string{
10498
"/debug/pprof/",
@@ -116,12 +110,8 @@ func TestMountPprofHandlers(t *testing.T) {
116110
}
117111
for _, path := range paths {
118112
status, resp = makeRequest(t, ts.URL+path)
119-
if status != http.StatusOK {
120-
t.Errorf("got status %d, expected %d", status, http.StatusOK)
121-
}
122-
if resp == "" {
123-
t.Errorf("got body %q, expected non-empty", resp)
124-
}
113+
assert.Equal(t, http.StatusOK, status)
114+
assert.NotEmpty(t, resp)
125115
}
126116
}
127117

@@ -169,24 +159,14 @@ func TestDebugPayloads(t *testing.T) {
169159
endpoint := test.NewHTTPMethodEndpoint(&svc)
170160
endpoint = LogPayloads(c.option)(endpoint)
171161
res, err := endpoint(c.ctx, payload)
172-
if buf.String() != c.expectedLogs {
173-
t.Errorf("got unexpected logs %q", buf.String())
174-
}
162+
assert.Equal(t, c.expectedLogs, buf.String())
175163
if err != nil {
176-
if err.Error() != c.expectedErr {
177-
t.Errorf("got unexpected error %v", err)
178-
}
164+
assert.Equal(t, c.expectedErr, err.Error())
179165
return
180166
}
181-
if c.expectedErr != "" {
182-
t.Fatalf("expected error %q", c.expectedErr)
183-
}
184-
if res == nil {
185-
t.Fatal("got nil response")
186-
}
187-
if *(res.(*test.Fields)) != *payload {
188-
t.Errorf("got unexpected response %v", res)
189-
}
167+
require.Empty(t, c.expectedErr)
168+
require.NotNil(t, res)
169+
assert.Equal(t, payload, res)
190170
})
191171
}
192172
}

example/weather/go.mod

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,51 @@ go 1.22.0
44

55
require (
66
github.com/stretchr/testify v1.9.0
7-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0
8-
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.52.0
9-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0
10-
go.opentelemetry.io/otel v1.27.0
11-
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.27.0
12-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0
13-
go.opentelemetry.io/otel/trace v1.27.0
14-
goa.design/clue v1.0.3
15-
goa.design/goa/v3 v3.16.2
7+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0
8+
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.56.0
9+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0
10+
go.opentelemetry.io/otel v1.31.0
11+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.31.0
12+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.31.0
13+
go.opentelemetry.io/otel/trace v1.31.0
14+
goa.design/clue v1.0.6
15+
goa.design/goa/v3 v3.19.1
1616
goa.design/model v1.9.8
17-
goa.design/plugins/v3 v3.16.2
18-
google.golang.org/grpc v1.64.1
19-
google.golang.org/protobuf v1.34.1
17+
goa.design/plugins/v3 v3.19.1
18+
google.golang.org/grpc v1.67.1
19+
google.golang.org/protobuf v1.35.1
2020
)
2121

2222
require (
23-
github.com/aws/smithy-go v1.20.2 // indirect
23+
github.com/aws/smithy-go v1.22.0 // indirect
2424
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
2525
github.com/davecgh/go-spew v1.1.1 // indirect
2626
github.com/dimfeld/httppath v0.0.0-20170720192232-ee938bf73598 // indirect
2727
github.com/felixge/httpsnoop v1.0.4 // indirect
28-
github.com/go-chi/chi/v5 v5.0.12 // indirect
28+
github.com/go-chi/chi/v5 v5.1.0 // indirect
2929
github.com/go-logfmt/logfmt v0.6.0 // indirect
3030
github.com/go-logr/logr v1.4.2 // indirect
3131
github.com/go-logr/stdr v1.2.2 // indirect
3232
github.com/google/uuid v1.6.0 // indirect
33-
github.com/gorilla/websocket v1.5.1 // indirect
34-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
33+
github.com/gorilla/websocket v1.5.3 // indirect
34+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
3535
github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d // indirect
3636
github.com/pmezard/go-difflib v1.0.0 // indirect
37-
github.com/sergi/go-diff v1.3.1 // indirect
38-
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0 // indirect
39-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect
40-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 // indirect
41-
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.26.0 // indirect
42-
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.26.0 // indirect
43-
go.opentelemetry.io/otel/metric v1.27.0 // indirect
44-
go.opentelemetry.io/otel/sdk v1.27.0 // indirect
45-
go.opentelemetry.io/otel/sdk/metric v1.27.0 // indirect
46-
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
47-
golang.org/x/mod v0.17.0 // indirect
48-
golang.org/x/net v0.26.0 // indirect
49-
golang.org/x/sync v0.7.0 // indirect
50-
golang.org/x/sys v0.21.0 // indirect
51-
golang.org/x/term v0.21.0 // indirect
52-
golang.org/x/text v0.16.0 // indirect
53-
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
54-
google.golang.org/genproto/googleapis/api v0.0.0-20240528155852-a33235495d66 // indirect
55-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528155852-a33235495d66 // indirect
37+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.31.0 // indirect
38+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 // indirect
39+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0 // indirect
40+
go.opentelemetry.io/otel/metric v1.31.0 // indirect
41+
go.opentelemetry.io/otel/sdk v1.31.0 // indirect
42+
go.opentelemetry.io/otel/sdk/metric v1.31.0 // indirect
43+
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
44+
golang.org/x/mod v0.21.0 // indirect
45+
golang.org/x/net v0.30.0 // indirect
46+
golang.org/x/sync v0.8.0 // indirect
47+
golang.org/x/sys v0.26.0 // indirect
48+
golang.org/x/term v0.25.0 // indirect
49+
golang.org/x/text v0.19.0 // indirect
50+
golang.org/x/tools v0.26.0 // indirect
51+
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 // indirect
52+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
5653
gopkg.in/yaml.v3 v3.0.1 // indirect
5754
)

0 commit comments

Comments
 (0)