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

Use gofumpt instead of gofmt #4623

Merged
merged 5 commits into from
Oct 16, 2023
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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ linters:
- depguard
- errcheck
- godot
- gofmt
- gofumpt
- goimports
- gosimple
- govet
Expand Down
4 changes: 2 additions & 2 deletions attribute/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestDefined(t *testing.T) {
},
} {
t.Run(testcase.name, func(t *testing.T) {
//func (k attribute.Key) Defined() bool {
// func (k attribute.Key) Defined() bool {
have := testcase.k.Defined()
if have != testcase.want {
t.Errorf("Want: %v, but have: %v", testcase.want, have)
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestEmit(t *testing.T) {
},
} {
t.Run(testcase.name, func(t *testing.T) {
//proto: func (v attribute.Value) Emit() string {
// proto: func (v attribute.Value) Emit() string {
have := testcase.v.Emit()
if have != testcase.want {
t.Errorf("Want: %s, but have: %s", testcase.want, have)
Expand Down
28 changes: 18 additions & 10 deletions bridge/opencensus/internal/ocmetric/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func TestConvertMetrics(t *testing.T) {
},
TimeSeries: []*ocmetricdata.TimeSeries{
{

LabelValues: []ocmetricdata.LabelValue{
{
Value: "hello",
Expand Down Expand Up @@ -370,7 +369,8 @@ func TestConvertMetrics(t *testing.T) {
},
},
},
}, {
},
{
desc: "histogram without data points",
input: []*ocmetricdata.Metric{
{
Expand All @@ -393,7 +393,8 @@ func TestConvertMetrics(t *testing.T) {
},
},
},
}, {
},
{
desc: "sum without data points",
input: []*ocmetricdata.Metric{
{
Expand All @@ -417,7 +418,8 @@ func TestConvertMetrics(t *testing.T) {
},
},
},
}, {
},
{
desc: "gauge without data points",
input: []*ocmetricdata.Metric{
{
Expand All @@ -439,7 +441,8 @@ func TestConvertMetrics(t *testing.T) {
},
},
},
}, {
},
{
desc: "histogram with negative count",
input: []*ocmetricdata.Metric{
{
Expand All @@ -462,7 +465,8 @@ func TestConvertMetrics(t *testing.T) {
},
},
expectedErr: errNegativeDistributionCount,
}, {
},
{
desc: "histogram with negative bucket count",
input: []*ocmetricdata.Metric{
{
Expand All @@ -489,7 +493,8 @@ func TestConvertMetrics(t *testing.T) {
},
},
expectedErr: errNegativeBucketCount,
}, {
},
{
desc: "histogram with non-histogram datapoint type",
input: []*ocmetricdata.Metric{
{
Expand All @@ -510,7 +515,8 @@ func TestConvertMetrics(t *testing.T) {
},
},
expectedErr: errMismatchedValueTypes,
}, {
},
{
desc: "sum with non-sum datapoint type",
input: []*ocmetricdata.Metric{
{
Expand All @@ -531,7 +537,8 @@ func TestConvertMetrics(t *testing.T) {
},
},
expectedErr: errMismatchedValueTypes,
}, {
},
{
desc: "gauge with non-gauge datapoint type",
input: []*ocmetricdata.Metric{
{
Expand All @@ -552,7 +559,8 @@ func TestConvertMetrics(t *testing.T) {
},
},
expectedErr: errMismatchedValueTypes,
}, {
},
{
desc: "unsupported Gauge Distribution type",
input: []*ocmetricdata.Metric{
{
Expand Down
12 changes: 6 additions & 6 deletions bridge/opentracing/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,10 @@ type BridgeTracer struct {
propagator propagation.TextMapPropagator
}

var _ ot.Tracer = &BridgeTracer{}
var _ ot.TracerContextWithSpanExtension = &BridgeTracer{}
var (
_ ot.Tracer = &BridgeTracer{}
_ ot.TracerContextWithSpanExtension = &BridgeTracer{}
)

// NewBridgeTracer creates a new BridgeTracer. The new tracer forwards
// the calls to the OpenTelemetry Noop tracer, so it should be
Expand Down Expand Up @@ -829,15 +831,13 @@ func newTextMapWrapperForInject(carrier interface{}) (*textMapWrapper, error) {
return t, nil
}

type textMapWriter struct {
}
type textMapWriter struct{}

func (t *textMapWriter) Set(key string, value string) {
// maybe print a warning log.
}

type textMapReader struct {
}
type textMapReader struct{}

func (t *textMapReader) ForeachKey(handler func(key, val string) error) error {
return nil // maybe print a warning log.
Expand Down
8 changes: 3 additions & 5 deletions bridge/opentracing/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import (
"go.opentelemetry.io/otel/trace"
)

type testOnlyTextMapReader struct {
}
type testOnlyTextMapReader struct{}

func newTestOnlyTextMapReader() *testOnlyTextMapReader {
return &testOnlyTextMapReader{}
Expand Down Expand Up @@ -144,8 +143,7 @@ var (
spanID trace.SpanID = [8]byte{byte(11)}
)

type testTextMapPropagator struct {
}
type testTextMapPropagator struct{}

func (t testTextMapPropagator) Inject(ctx context.Context, carrier propagation.TextMapCarrier) {
carrier.Set(testHeader, strings.Join([]string{traceID.String(), spanID.String()}, ":"))
Expand All @@ -163,7 +161,7 @@ func (t testTextMapPropagator) Extract(ctx context.Context, carrier propagation.
return ctx
}

var exist = false
exist := false

for _, key := range carrier.Keys() {
if strings.EqualFold(testHeader, key) {
Expand Down
12 changes: 8 additions & 4 deletions bridge/opentracing/internal/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ type MockTracer struct {
rand *rand.Rand
}

var _ trace.Tracer = &MockTracer{}
var _ migration.DeferredContextSetupTracerExtension = &MockTracer{}
var (
_ trace.Tracer = &MockTracer{}
_ migration.DeferredContextSetupTracerExtension = &MockTracer{}
)

func NewMockTracer() *MockTracer {
return &MockTracer{
Expand Down Expand Up @@ -195,8 +197,10 @@ type MockSpan struct {
Events []MockEvent
}

var _ trace.Span = &MockSpan{}
var _ migration.OverrideTracerSpanExtension = &MockSpan{}
var (
_ trace.Span = &MockSpan{}
_ migration.OverrideTracerSpanExtension = &MockSpan{}
)

func (s *MockSpan) SpanContext() trace.SpanContext {
return s.spanContext
Expand Down
3 changes: 3 additions & 0 deletions bridge/opentracing/test/bridge_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ type testGRPCServer struct{}
func (*testGRPCServer) UnaryCall(ctx context.Context, r *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
return &testpb.SimpleResponse{Payload: r.Payload * 2}, nil
}

func (*testGRPCServer) StreamingOutputCall(*testpb.SimpleRequest, testpb.TestService_StreamingOutputCallServer) error {
return nil
}

func (*testGRPCServer) StreamingInputCall(testpb.TestService_StreamingInputCallServer) error {
return nil
}

func (*testGRPCServer) StreamingBidirectionalCall(testpb.TestService_StreamingBidirectionalCallServer) error {
return nil
}
Expand Down
6 changes: 4 additions & 2 deletions bridge/opentracing/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ type WrapperTracer struct {
tracer trace.Tracer
}

var _ trace.Tracer = &WrapperTracer{}
var _ migration.DeferredContextSetupTracerExtension = &WrapperTracer{}
var (
_ trace.Tracer = &WrapperTracer{}
_ migration.DeferredContextSetupTracerExtension = &WrapperTracer{}
)

// NewWrapperTracer wraps the passed tracer and also talks to the
// passed bridge tracer when setting up the context with the new
Expand Down
4 changes: 1 addition & 3 deletions example/namedtracer/foo/foo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import (
"go.opentelemetry.io/otel/trace"
)

var (
lemonsKey = attribute.Key("ex.com/lemons")
)
var lemonsKey = attribute.Key("ex.com/lemons")

// SubOperation is an example to demonstrate the use of named tracer.
// It creates a named tracer with its package path.
Expand Down
2 changes: 2 additions & 0 deletions exporters/otlp/otlpmetric/otlpmetricgrpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ type clientShim struct {
func (clientShim) Temporality(metric.InstrumentKind) metricdata.Temporality {
return metricdata.CumulativeTemporality
}

func (clientShim) Aggregation(metric.InstrumentKind) metric.Aggregation {
return nil
}

func (clientShim) ForceFlush(ctx context.Context) error {
return ctx.Err()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func TestConfigs(t *testing.T) {
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
if grpcOption {
//TODO: make sure gRPC's credentials actually works
// TODO: make sure gRPC's credentials actually works
assert.NotNil(t, c.Metrics.GRPCCredentials)
} else {
// nolint:staticcheck // ignoring tlsCert.RootCAs.Subjects is deprecated ERR because cert does not come from SystemCertPool.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (

var (
// Sat Jan 01 2000 00:00:00 GMT+0000.
start = time.Date(2000, time.January, 01, 0, 0, 0, 0, time.FixedZone("GMT", 0))
start = time.Date(2000, time.January, 0o1, 0, 0, 0, 0, time.FixedZone("GMT", 0))
end = start.Add(30 * time.Second)

kvAlice = &cpb.KeyValue{Key: "user", Value: &cpb.AnyValue{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type unknownAggT struct {

var (
// Sat Jan 01 2000 00:00:00 GMT+0000.
start = time.Date(2000, time.January, 01, 0, 0, 0, 0, time.FixedZone("GMT", 0))
start = time.Date(2000, time.January, 0o1, 0, 0, 0, 0, time.FixedZone("GMT", 0))
end = start.Add(30 * time.Second)

alice = attribute.NewSet(attribute.String("user", "alice"))
Expand Down
2 changes: 2 additions & 0 deletions exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ type clientShim struct {
func (clientShim) Temporality(metric.InstrumentKind) metricdata.Temporality {
return metricdata.CumulativeTemporality
}

func (clientShim) Aggregation(metric.InstrumentKind) metric.Aggregation {
return nil
}

func (clientShim) ForceFlush(ctx context.Context) error {
return ctx.Err()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func TestConfigs(t *testing.T) {
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
if grpcOption {
//TODO: make sure gRPC's credentials actually works
// TODO: make sure gRPC's credentials actually works
assert.NotNil(t, c.Metrics.GRPCCredentials)
} else {
// nolint:staticcheck // ignoring tlsCert.RootCAs.Subjects is deprecated ERR because cert does not come from SystemCertPool.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (

var (
// Sat Jan 01 2000 00:00:00 GMT+0000.
start = time.Date(2000, time.January, 01, 0, 0, 0, 0, time.FixedZone("GMT", 0))
start = time.Date(2000, time.January, 0o1, 0, 0, 0, 0, time.FixedZone("GMT", 0))
end = start.Add(30 * time.Second)

kvAlice = &cpb.KeyValue{Key: "user", Value: &cpb.AnyValue{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type unknownAggT struct {

var (
// Sat Jan 01 2000 00:00:00 GMT+0000.
start = time.Date(2000, time.January, 01, 0, 0, 0, 0, time.FixedZone("GMT", 0))
start = time.Date(2000, time.January, 0o1, 0, 0, 0, 0, time.FixedZone("GMT", 0))
end = start.Add(30 * time.Second)

alice = attribute.NewSet(attribute.String("user", "alice"))
Expand Down
6 changes: 2 additions & 4 deletions exporters/otlp/otlptrace/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import (
tracesdk "go.opentelemetry.io/otel/sdk/trace"
)

var (
errAlreadyStarted = errors.New("already started")
)
var errAlreadyStarted = errors.New("already started")

// Exporter exports trace data in the OTLP wire format.
type Exporter struct {
Expand Down Expand Up @@ -55,7 +53,7 @@ func (e *Exporter) ExportSpans(ctx context.Context, ss []tracesdk.ReadOnlySpan)

// Start establishes a connection to the receiving endpoint.
func (e *Exporter) Start(ctx context.Context) error {
var err = errAlreadyStarted
err := errAlreadyStarted
e.startOnce.Do(func() {
e.mu.Lock()
e.started = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,14 @@ func TestSpanData(t *testing.T) {
StartTime: startTime,
EndTime: endTime,
Events: []tracesdk.Event{
{Time: startTime,
{
Time: startTime,
Attributes: []attribute.KeyValue{
attribute.Int64("CompressedByteSize", 512),
},
},
{Time: endTime,
{
Time: endTime,
Attributes: []attribute.KeyValue{
attribute.String("EventType", "Recv"),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func TestConfigs(t *testing.T) {
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
if grpcOption {
//TODO: make sure gRPC's credentials actually works
// TODO: make sure gRPC's credentials actually works
assert.NotNil(t, c.Traces.GRPCCredentials)
} else {
// nolint:staticcheck // ignoring tlsCert.RootCAs.Subjects is deprecated ERR because cert does not come from SystemCertPool.
Expand Down
10 changes: 4 additions & 6 deletions exporters/otlp/otlptrace/otlptracehttp/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ const (
instrumentationVersion = "0.1.0"
)

var (
tracer = otel.GetTracerProvider().Tracer(
instrumentationName,
trace.WithInstrumentationVersion(instrumentationVersion),
trace.WithSchemaURL(semconv.SchemaURL),
)
var tracer = otel.GetTracerProvider().Tracer(
instrumentationName,
trace.WithInstrumentationVersion(instrumentationVersion),
trace.WithSchemaURL(semconv.SchemaURL),
)

func add(ctx context.Context, x, y int64) int64 {
Expand Down
Loading