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 lint test:-confusing-naming #5507

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
5 changes: 1 addition & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ linters-settings:
# often looks like a red herring, needs investigation
- name: flag-parameter
disabled: true
# looks like a good linter, needs cleanup
- name: confusing-naming
disabled: true
# too pendantic
- name: function-length
disabled: true
Expand Down Expand Up @@ -280,4 +277,4 @@ run:
- thrift-0.9.2
- .*-gen
skip-files:
- ".*.pb.go$"
- ".*.pb.go$"
4 changes: 2 additions & 2 deletions cmd/collector/app/handler/otlp_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var _ component.Host = (*otelHost)(nil) // API check
// StartOTLPReceiver starts OpenTelemetry OTLP receiver listening on gRPC and HTTP ports.
func StartOTLPReceiver(options *flags.CollectorOptions, logger *zap.Logger, spanProcessor processor.SpanProcessor, tm *tenancy.Manager) (receiver.Traces, error) {
otlpFactory := otlpreceiver.NewFactory()
return startOTLPReceiver(
return start_OTLP_Receiver(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not what the linter was complaining about. Your names violate Go coding practices.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so how should i fix this naming problem (Warns on methods with names that differ only by capitalization) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it be okay if i name it like startOTLPReceiverInternal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine to use startOTLPReceiver as of camelCase which is generally used in Go.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

startOTLPReceiverInternal seems ok, but this needs to be decided on a case by case basis, there may be better options in other situations.

options,
logger,
spanProcessor,
Expand All @@ -58,7 +58,7 @@ func StartOTLPReceiver(options *flags.CollectorOptions, logger *zap.Logger, span
// Some of OTELCOL constructor functions return errors when passed nil arguments,
// which is a situation we cannot reproduce. To test our own error handling, this
// function allows to mock those constructors.
func startOTLPReceiver(
func start_OTLP_Receiver(
options *flags.CollectorOptions,
logger *zap.Logger,
spanProcessor processor.SpanProcessor,
Expand Down
4 changes: 2 additions & 2 deletions cmd/collector/app/handler/otlp_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestStartOtlpReceiver_Error(t *testing.T) {
return nil, errors.New("mock error")
}
f := otlpreceiver.NewFactory()
_, err = startOTLPReceiver(opts, logger, spanProcessor, &tenancy.Manager{}, f, newTraces, f.CreateTracesReceiver)
_, err = start_OTLP_Receiver(opts, logger, spanProcessor, &tenancy.Manager{}, f, newTraces, f.CreateTracesReceiver)
require.Error(t, err)
assert.Contains(t, err.Error(), "could not create the OTLP consumer")

Expand All @@ -119,7 +119,7 @@ func TestStartOtlpReceiver_Error(t *testing.T) {
) (receiver.Traces, error) {
return nil, errors.New("mock error")
}
_, err = startOTLPReceiver(opts, logger, spanProcessor, &tenancy.Manager{}, f, consumer.NewTraces, createTracesReceiver)
_, err = start_OTLP_Receiver(opts, logger, spanProcessor, &tenancy.Manager{}, f, consumer.NewTraces, createTracesReceiver)
require.Error(t, err)
assert.Contains(t, err.Error(), "could not create the OTLP receiver")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/collector/app/handler/zipkin_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func StartZipkinReceiver(
tm *tenancy.Manager,
) (receiver.Traces, error) {
zipkinFactory := zipkinreceiver.NewFactory()
return startZipkinReceiver(
return start_Zipk_in_Receiver(
options,
logger,
spanProcessor,
Expand All @@ -42,7 +42,7 @@ func StartZipkinReceiver(
// Some of OTELCOL constructor functions return errors when passed nil arguments,
// which is a situation we cannot reproduce. To test our own error handling, this
// function allows to mock those constructors.
func startZipkinReceiver(
func start_Zipk_in_Receiver(
options *flags.CollectorOptions,
logger *zap.Logger,
spanProcessor processor.SpanProcessor,
Expand Down
4 changes: 2 additions & 2 deletions cmd/collector/app/handler/zipkin_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestStartZipkinReceiver_Error(t *testing.T) {
return nil, errors.New("mock error")
}
f := zipkinreceiver.NewFactory()
_, err = startZipkinReceiver(opts, logger, spanProcessor, tm, f, newTraces, f.CreateTracesReceiver)
_, err = start_Zipk_in_Receiver(opts, logger, spanProcessor, tm, f, newTraces, f.CreateTracesReceiver)
require.Error(t, err)
assert.Contains(t, err.Error(), "could not create Zipkin consumer")

Expand All @@ -157,7 +157,7 @@ func TestStartZipkinReceiver_Error(t *testing.T) {
) (receiver.Traces, error) {
return nil, errors.New("mock error")
}
_, err = startZipkinReceiver(opts, logger, spanProcessor, tm, f, consumer.NewTraces, createTracesReceiver)
_, err = start_Zipk_in_Receiver(opts, logger, spanProcessor, tm, f, consumer.NewTraces, createTracesReceiver)
require.Error(t, err)
assert.Contains(t, err.Error(), "could not create Zipkin receiver")
}
4 changes: 2 additions & 2 deletions cmd/collector/app/span_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewSpanProcessor(
additional []ProcessSpan,
opts ...Option,
) processor.SpanProcessor {
sp := newSpanProcessor(spanWriter, additional, opts...)
sp := new_Span_Processor(spanWriter, additional, opts...)

sp.queue.StartConsumers(sp.numWorkers, func(item any) {
value := item.(*queueItem)
Expand All @@ -87,7 +87,7 @@ func NewSpanProcessor(
return sp
}

func newSpanProcessor(spanWriter spanstore.Writer, additional []ProcessSpan, opts ...Option) *spanProcessor {
func new_Span_Processor(spanWriter spanstore.Writer, additional []ProcessSpan, opts ...Option) *spanProcessor {
options := Options.apply(opts...)
handlerMetrics := NewSpanProcessorMetrics(
options.serviceMetrics,
Expand Down
8 changes: 4 additions & 4 deletions cmd/collector/app/span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestBySvcMetrics(t *testing.T) {
logger := zap.NewNop()
serviceMetrics := mb.Namespace(metrics.NSOptions{Name: "service", Tags: nil})
hostMetrics := mb.Namespace(metrics.NSOptions{Name: "host", Tags: nil})
sp := newSpanProcessor(
sp := new_Span_Processor(
&fakeSpanWriter{},
nil,
Options.ServiceMetrics(serviceMetrics),
Expand Down Expand Up @@ -574,7 +574,7 @@ func TestUpdateDynQueueSize(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
w := &fakeSpanWriter{}
p := newSpanProcessor(w, nil, Options.QueueSize(tt.initialCapacity), Options.DynQueueSizeWarmup(tt.warmup), Options.DynQueueSizeMemory(tt.sizeInBytes))
p := new_Span_Processor(w, nil, Options.QueueSize(tt.initialCapacity), Options.DynQueueSizeWarmup(tt.warmup), Options.DynQueueSizeMemory(tt.sizeInBytes))
assert.EqualValues(t, tt.initialCapacity, p.queue.Capacity())

p.spansProcessed.Store(tt.spansProcessed)
Expand All @@ -588,14 +588,14 @@ func TestUpdateDynQueueSize(t *testing.T) {

func TestUpdateQueueSizeNoActivityYet(t *testing.T) {
w := &fakeSpanWriter{}
p := newSpanProcessor(w, nil, Options.QueueSize(1), Options.DynQueueSizeWarmup(1), Options.DynQueueSizeMemory(1))
p := new_Span_Processor(w, nil, Options.QueueSize(1), Options.DynQueueSizeWarmup(1), Options.DynQueueSizeMemory(1))
assert.NotPanics(t, p.updateQueueSize)
}

func TestStartDynQueueSizeUpdater(t *testing.T) {
w := &fakeSpanWriter{}
oneGiB := uint(1024 * 1024 * 1024)
p := newSpanProcessor(w, nil, Options.QueueSize(100), Options.DynQueueSizeWarmup(1000), Options.DynQueueSizeMemory(oneGiB))
p := new_Span_Processor(w, nil, Options.QueueSize(100), Options.DynQueueSizeWarmup(1000), Options.DynQueueSizeMemory(oneGiB))
assert.EqualValues(t, 100, p.queue.Capacity())

p.spansProcessed.Store(1000)
Expand Down
4 changes: 2 additions & 2 deletions cmd/es-index-cleaner/app/index_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ type IndexFilter struct {

// Filter filters indices.
func (i *IndexFilter) Filter(indices []client.Index) []client.Index {
indices = i.filter(indices)
indices = i.filter_apply(indices)
return filter.ByDate(indices, i.DeleteBeforeThisDate)
}

func (i *IndexFilter) filter(indices []client.Index) []client.Index {
func (i *IndexFilter) filter_apply(indices []client.Index) []client.Index {
var reg *regexp.Regexp
switch {
case i.Archive:
Expand Down
6 changes: 3 additions & 3 deletions cmd/es-index-cleaner/app/index_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import (
)

func TestIndexFilter(t *testing.T) {
testIndexFilter(t, "")
test_Index_Filter(t, "")
}

func TestIndexFilter_prefix(t *testing.T) {
testIndexFilter(t, "tenant1-")
test_Index_Filter(t, "tenant1-")
}

func testIndexFilter(t *testing.T, prefix string) {
func test_Index_Filter(t *testing.T, prefix string) {
time20200807 := time.Date(2020, time.August, 0o6, 0, 0, 0, 0, time.UTC).AddDate(0, 0, 1)
indices := []client.Index{
{
Expand Down
4 changes: 2 additions & 2 deletions crossdock/services/tracehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (h *TraceHandler) AdaptiveSamplingTest(t crossdock.T) {
service := t.Param(servicesParam)
h.logger.Info("Starting AdaptiveSampling test", zap.String("service", service))

if err := h.runTest(service, request, h.adaptiveSamplingTest, validateAdaptiveSamplingTraces); err != nil {
if err := h.runTest(service, request, h.adaptive_Sampling_Test, validateAdaptiveSamplingTraces); err != nil {
h.logger.Error(err.Error())
t.Errorf("Fail: %s", err.Error())
} else {
Expand All @@ -131,7 +131,7 @@ func (h *TraceHandler) runTest(service string, request *traceRequest, tFunc test
return vFunc(request, traces)
}

func (h *TraceHandler) adaptiveSamplingTest(service string, request *traceRequest) ([]*ui.Trace, error) {
func (h *TraceHandler) adaptive_Sampling_Test(service string, request *traceRequest) ([]*ui.Trace, error) {
stop := make(chan struct{})
go h.createTracesLoop(service, *request, stop)
defer close(stop)
Expand Down
2 changes: 1 addition & 1 deletion crossdock/services/tracehandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func TestAdaptiveSamplingTestInternal(t *testing.T) {
query.On("GetTraces", "crossdock-svc", "op", mock.Anything).Return([]*ui.Trace{&testTrace}, nil)
}

_, err := handler.adaptiveSamplingTest("svc", &traceRequest{Operation: "op"})
_, err := handler.adaptive_Sampling_Test("svc", &traceRequest{Operation: "op"})
if test.errMsg != "" {
require.EqualError(t, err, test.errMsg)
} else {
Expand Down
6 changes: 3 additions & 3 deletions model/keyvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ func (kv *KeyValue) Value() any {

// AsStringLossy returns a potentially lossy string representation of the value.
func (kv *KeyValue) AsStringLossy() string {
return kv.asString(true)
return kv.as_String(true)
}

// AsString returns a string representation of the value.
func (kv *KeyValue) AsString() string {
return kv.asString(false)
return kv.as_String(false)
}

func (kv *KeyValue) asString(truncate bool) string {
func (kv *KeyValue) as_String(truncate bool) string {
switch kv.VType {
case StringType:
return kv.VStr
Expand Down
6 changes: 3 additions & 3 deletions pkg/clientcfg/clientcfghttp/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ func withServer(
}

func TestHTTPHandler(t *testing.T) {
testHTTPHandler(t, "")
test_HTTP_Handler(t, "")
}

func TestHTTPHandlerWithBasePath(t *testing.T) {
testHTTPHandler(t, "/foo")
test_HTTP_Handler(t, "/foo")
}

func testHTTPHandler(t *testing.T, basePath string) {
func test_HTTP_Handler(t *testing.T, basePath string) {
withServer(basePath, rateLimiting(42), restrictions("luggage", 10), func(ts *testServer) {
tests := []struct {
endpoint string
Expand Down
4 changes: 2 additions & 2 deletions plugin/storage/cassandra/spanstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (s *SpanReader) FindTraceIDs(ctx context.Context, traceQuery *spanstore.Tra
traceQuery.NumTraces = defaultNumTraces
}

dbTraceIDs, err := s.findTraceIDs(ctx, traceQuery)
dbTraceIDs, err := s.find_Trace_IDs(ctx, traceQuery)
if err != nil {
return nil, err
}
Expand All @@ -280,7 +280,7 @@ func (s *SpanReader) FindTraceIDs(ctx context.Context, traceQuery *spanstore.Tra
return traceIDs, nil
}

func (s *SpanReader) findTraceIDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) (dbmodel.UniqueTraceIDs, error) {
func (s *SpanReader) find_Trace_IDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) (dbmodel.UniqueTraceIDs, error) {
if traceQuery.DurationMin != 0 || traceQuery.DurationMax != 0 {
return s.queryByDuration(ctx, traceQuery)
}
Expand Down
4 changes: 2 additions & 2 deletions plugin/storage/cassandra/spanstore/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (s *SpanWriter) Close() error {
func (s *SpanWriter) WriteSpan(ctx context.Context, span *model.Span) error {
ds := dbmodel.FromDomain(span)
if s.storageMode&storeFlag == storeFlag {
if err := s.writeSpan(span, ds); err != nil {
if err := s.write_Span(span, ds); err != nil {
return err
}
}
Expand All @@ -153,7 +153,7 @@ func (s *SpanWriter) WriteSpan(ctx context.Context, span *model.Span) error {
return nil
}

func (s *SpanWriter) writeSpan(span *model.Span, ds *dbmodel.Span) error {
func (s *SpanWriter) write_Span(span *model.Span, ds *dbmodel.Span) error {
mainQuery := s.session.Query(
insertSpan,
ds.TraceID,
Expand Down
4 changes: 2 additions & 2 deletions plugin/storage/es/dependencystore/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func prefixIndexName(prefix, index string) string {
// WriteDependencies implements dependencystore.Writer#WriteDependencies.
func (s *DependencyStore) WriteDependencies(ts time.Time, dependencies []model.DependencyLink) error {
writeIndexName := s.getWriteIndex(ts)
s.writeDependencies(writeIndexName, ts, dependencies)
s.write_Dependencies(writeIndexName, ts, dependencies)
return nil
}

Expand All @@ -91,7 +91,7 @@ func (s *DependencyStore) CreateTemplates(dependenciesTemplate string) error {
return nil
}

func (s *DependencyStore) writeDependencies(indexName string, ts time.Time, dependencies []model.DependencyLink) {
func (s *DependencyStore) write_Dependencies(indexName string, ts time.Time, dependencies []model.DependencyLink) {
s.client().Index().Index(indexName).Type(dependencyType).
BodyJson(&dbmodel.TimeDependencies{
Timestamp: ts,
Expand Down
6 changes: 3 additions & 3 deletions plugin/storage/es/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,12 @@ func TestPasswordFromFile(t *testing.T) {
defer testutils.VerifyGoLeaksOnce(t)
t.Run("primary client", func(t *testing.T) {
f := NewFactory()
testPasswordFromFile(t, f, f.getPrimaryClient, f.CreateSpanWriter)
test_Password_From_File(t, f, f.getPrimaryClient, f.CreateSpanWriter)
})

t.Run("archive client", func(t *testing.T) {
f2 := NewFactory()
testPasswordFromFile(t, f2, f2.getArchiveClient, f2.CreateArchiveSpanWriter)
test_Password_From_File(t, f2, f2.getArchiveClient, f2.CreateArchiveSpanWriter)
})

t.Run("load token error", func(t *testing.T) {
Expand All @@ -352,7 +352,7 @@ func TestPasswordFromFile(t *testing.T) {
})
}

func testPasswordFromFile(t *testing.T, f *Factory, getClient func() es.Client, getWriter func() (spanstore.Writer, error)) {
func test_Password_From_File(t *testing.T, f *Factory, getClient func() es.Client, getWriter func() (spanstore.Writer, error)) {
const (
pwd1 = "first password"
pwd2 = "second password"
Expand Down
6 changes: 3 additions & 3 deletions plugin/storage/es/spanstore/dbmodel/to_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ import (
)

func TestToDomain(t *testing.T) {
testToDomain(t, false)
testToDomain(t, true)
test_To_Domain(t, false)
test_To_Domain(t, true)
// this is just to confirm the uint64 representation of float64(72.5) used as a "temperature" tag
assert.Equal(t, int64(4634802150889750528), int64(math.Float64bits(72.5)))
}

func testToDomain(t *testing.T, testParentSpanID bool) {
func test_To_Domain(t *testing.T, testParentSpanID bool) {
for i := 1; i <= NumberOfFixtures; i++ {
span, err := loadESSpanFixture(i)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions plugin/storage/es/spanstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (s *SpanReader) FindTraceIDs(ctx context.Context, traceQuery *spanstore.Tra
traceQuery.NumTraces = defaultNumTraces
}

esTraceIDs, err := s.findTraceIDs(ctx, traceQuery)
esTraceIDs, err := s.find_TraceIDs(ctx, traceQuery)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -514,7 +514,7 @@ func validateQuery(p *spanstore.TraceQueryParameters) error {
return nil
}

func (s *SpanReader) findTraceIDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]string, error) {
func (s *SpanReader) find_TraceIDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]string, error) {
ctx, childSpan := s.tracer.Start(ctx, "findTraceIDs")
defer childSpan.End()
// Below is the JSON body to our HTTP GET request to ElasticSearch. This function creates this.
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/es/spanstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ func returnSearchFunc(typ string, r *spanReaderTest) (any, error) {
spanstore.OperationQueryParameters{ServiceName: "someService"},
)
case traceIDAggregation:
return r.reader.findTraceIDs(context.Background(), &spanstore.TraceQueryParameters{})
return r.reader.find_TraceIDs(context.Background(), &spanstore.TraceQueryParameters{})
}
return nil, errors.New("Specify services, operations, traceIDs only")
}
Expand Down
4 changes: 2 additions & 2 deletions plugin/storage/es/spanstore/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (s *SpanWriter) WriteSpan(_ context.Context, span *model.Span) error {
if serviceIndexName != "" {
s.writeService(serviceIndexName, jsonSpan)
}
s.writeSpan(spanIndexName, jsonSpan)
s.write_Span(spanIndexName, jsonSpan)
return nil
}

Expand All @@ -163,6 +163,6 @@ func (s *SpanWriter) writeService(indexName string, jsonSpan *dbmodel.Span) {
s.serviceWriter(indexName, jsonSpan)
}

func (s *SpanWriter) writeSpan(indexName string, jsonSpan *dbmodel.Span) {
func (s *SpanWriter) write_Span(indexName string, jsonSpan *dbmodel.Span) {
s.client().Index().Index(indexName).Type(spanType).BodyJson(&jsonSpan).Add()
}
4 changes: 2 additions & 2 deletions plugin/storage/es/spanstore/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func TestWriteSpanInternal(t *testing.T) {

jsonSpan := &dbmodel.Span{}

w.writer.writeSpan(indexName, jsonSpan)
w.writer.write_Span(indexName, jsonSpan)
indexService.AssertNumberOfCalls(t, "Add", 1)
assert.Equal(t, "", w.logBuffer.String())
})
Expand All @@ -350,7 +350,7 @@ func TestWriteSpanInternalError(t *testing.T) {
SpanID: dbmodel.SpanID("0"),
}

w.writer.writeSpan(indexName, jsonSpan)
w.writer.write_Span(indexName, jsonSpan)
indexService.AssertNumberOfCalls(t, "Add", 1)
})
}
Expand Down
Loading
Loading