Skip to content

Commit

Permalink
Make logger goroutine safe (#478)
Browse files Browse the repository at this point in the history
* Make logger goroutine safe

Improve performance of JSON logging.
Change text format to be consistent with default Go format.

* Add back cleanup
  • Loading branch information
raphael authored Oct 16, 2024
1 parent 11f7e88 commit cf18bd5
Show file tree
Hide file tree
Showing 14 changed files with 653 additions and 1,711 deletions.
5 changes: 5 additions & 0 deletions clue/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import (
tracenoop "go.opentelemetry.io/otel/trace/noop"

"goa.design/clue/log"

// Force dependency on main module to ensure it is unambiguous during
// module resolution.
// See: https://github.com/googleapis/google-api-go-client/issues/2559.
_ "google.golang.org/genproto/googleapis/type/datetime"
)

type (
Expand Down
46 changes: 13 additions & 33 deletions debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"net/http/httptest"
"testing"

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

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

if status != http.StatusOK {
t.Errorf("%s: got status %d, expected %d", c.name, status, http.StatusOK)
}
if resp != c.expectedResp {
t.Errorf("%s: got body %q, expected %q", c.name, resp, c.expectedResp)
}
assert.Equal(t, http.StatusOK, status)
assert.Equal(t, c.expectedResp, resp)
})
}
}
Expand All @@ -93,12 +91,8 @@ func TestMountPprofHandlers(t *testing.T) {
defer ts.Close()

status, resp := makeRequest(t, ts.URL)
if status != http.StatusOK {
t.Errorf("got status %d, expected %d", status, http.StatusOK)
}
if resp != "OK" {
t.Errorf("got body %q, expected %q", resp, "OK")
}
assert.Equal(t, http.StatusOK, status)
assert.Equal(t, "OK", resp)

paths := []string{
"/debug/pprof/",
Expand All @@ -116,12 +110,8 @@ func TestMountPprofHandlers(t *testing.T) {
}
for _, path := range paths {
status, resp = makeRequest(t, ts.URL+path)
if status != http.StatusOK {
t.Errorf("got status %d, expected %d", status, http.StatusOK)
}
if resp == "" {
t.Errorf("got body %q, expected non-empty", resp)
}
assert.Equal(t, http.StatusOK, status)
assert.NotEmpty(t, resp)
}
}

Expand Down Expand Up @@ -169,24 +159,14 @@ func TestDebugPayloads(t *testing.T) {
endpoint := test.NewHTTPMethodEndpoint(&svc)
endpoint = LogPayloads(c.option)(endpoint)
res, err := endpoint(c.ctx, payload)
if buf.String() != c.expectedLogs {
t.Errorf("got unexpected logs %q", buf.String())
}
assert.Equal(t, c.expectedLogs, buf.String())
if err != nil {
if err.Error() != c.expectedErr {
t.Errorf("got unexpected error %v", err)
}
assert.Equal(t, c.expectedErr, err.Error())
return
}
if c.expectedErr != "" {
t.Fatalf("expected error %q", c.expectedErr)
}
if res == nil {
t.Fatal("got nil response")
}
if *(res.(*test.Fields)) != *payload {
t.Errorf("got unexpected response %v", res)
}
require.Empty(t, c.expectedErr)
require.NotNil(t, res)
assert.Equal(t, payload, res)
})
}
}
Expand Down
67 changes: 32 additions & 35 deletions example/weather/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,51 @@ go 1.22.0

require (
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.52.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0
go.opentelemetry.io/otel v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0
go.opentelemetry.io/otel/trace v1.27.0
goa.design/clue v1.0.3
goa.design/goa/v3 v3.16.2
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.56.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0
go.opentelemetry.io/otel v1.31.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.31.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.31.0
go.opentelemetry.io/otel/trace v1.31.0
goa.design/clue v1.0.6
goa.design/goa/v3 v3.19.1
goa.design/model v1.9.8
goa.design/plugins/v3 v3.16.2
google.golang.org/grpc v1.64.1
google.golang.org/protobuf v1.34.1
goa.design/plugins/v3 v3.19.1
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.35.1
)

require (
github.com/aws/smithy-go v1.20.2 // indirect
github.com/aws/smithy-go v1.22.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dimfeld/httppath v0.0.0-20170720192232-ee938bf73598 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-chi/chi/v5 v5.0.12 // indirect
github.com/go-chi/chi/v5 v5.1.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.26.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.26.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
go.opentelemetry.io/otel/sdk v1.27.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.27.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240528155852-a33235495d66 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528155852-a33235495d66 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
go.opentelemetry.io/otel/sdk v1.31.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.31.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/tools v0.26.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit cf18bd5

Please sign in to comment.