Skip to content

Commit

Permalink
Enable Lint Rule: use-any (jaegertracing#5510)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlamingSaint authored Jun 3, 2024
1 parent 3382a27 commit f2b46d4
Show file tree
Hide file tree
Showing 77 changed files with 275 additions and 278 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ linters-settings:
- name: cyclomatic
disabled: true
# do a clean-up and enable
- name: use-any
disabled: true
# do a clean-up and enable
- name: unused-parameter
disabled: true
# do a clean-up and enable
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/app/processors/thrift_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewThriftProcessor(
"number of processors must be greater than 0, called with %d", numProcessors)
}
protocolPool := &sync.Pool{
New: func() interface{} {
New: func() any {
trans := &customtransport.TBufferedReadTransport{}
return factory.GetProtocol(trans)
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/app/reporter/client_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (r *ClientMetricsReporter) expireClientMetricsLoop() {

func (r *ClientMetricsReporter) expireClientMetrics(t time.Time) {
var size int64
r.lastReceivedClientStats.Range(func(k, v interface{}) bool {
r.lastReceivedClientStats.Range(func(k, v any) bool {
stats := v.(*lastReceivedClientStats)
stats.lock.Lock()
defer stats.lock.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/app/reporter/grpc/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ type fakeInterceptor struct {
isCalled bool
}

func (f *fakeInterceptor) intercept(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
func (f *fakeInterceptor) intercept(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
f.isCalled = true
return invoker(ctx, method, req, reply, cc, opts...)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/app/servers/tbuffered_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func NewTBufferedServer(
dataChan := make(chan *ReadBuf, maxQueueSize)

readBufPool := &sync.Pool{
New: func() interface{} {
New: func() any {
return &ReadBuf{bytes: make([]byte, maxPacketSize)}
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/anonymizer/app/uiconv/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestExtractorTraceScanError(t *testing.T) {
require.Contains(t, err.Error(), "failed when scanning the file")
}

func loadJSON(t *testing.T, fileName string, i interface{}) {
func loadJSON(t *testing.T, fileName string, i any) {
b, err := os.ReadFile(fileName)
require.NoError(t, err)
err = json.Unmarshal(b, i)
Expand Down
2 changes: 1 addition & 1 deletion cmd/collector/app/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func newTraceCountsBySvc(factory metrics.Factory, category string, maxServices i
},
// use sync.Pool to reduce allocation of stringBuilder
stringBuilderPool: &sync.Pool{
New: func() interface{} {
New: func() any {
return new(strings.Builder)
},
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/collector/app/span_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func NewSpanProcessor(
) processor.SpanProcessor {
sp := newSpanProcessor(spanWriter, additional, opts...)

sp.queue.StartConsumers(sp.numWorkers, func(item interface{}) {
sp.queue.StartConsumers(sp.numWorkers, func(item any) {
value := item.(*queueItem)
sp.processItemFromQueue(value)
})
Expand All @@ -93,7 +93,7 @@ func newSpanProcessor(spanWriter spanstore.Writer, additional []ProcessSpan, opt
options.serviceMetrics,
options.hostMetrics,
options.extraFormatTypes)
droppedItemHandler := func(item interface{}) {
droppedItemHandler := func(item any) {
handlerMetrics.SpansDropped.Inc(1)
if options.onDroppedSpan != nil {
options.onDroppedSpan(item.(*queueItem).span)
Expand Down
4 changes: 2 additions & 2 deletions cmd/es-rollover/app/init/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ func createIndexIfNotExist(c client.IndexAPI, index string) error {
return esErr.Err
}
// check for the reason of the error
jsonError := map[string]interface{}{}
jsonError := map[string]any{}
err := json.Unmarshal(esErr.Body, &jsonError)
if err != nil {
// return unmarshal error
return err
}
errorMap := jsonError["error"].(map[string]interface{})
errorMap := jsonError["error"].(map[string]any)
// check for reason, ignore already exist error
if strings.Contains(errorMap["type"].(string), "resource_already_exists_exception") {
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/es-rollover/app/rollover/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (a *Action) Do() error {
}

func (a *Action) rollover(indexSet app.IndexOption) error {
conditionsMap := map[string]interface{}{}
conditionsMap := map[string]any{}
if len(a.Conditions) > 0 {
err := json.Unmarshal([]byte(a.Config.Conditions), &conditionsMap)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions cmd/es-rollover/app/rollover/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestRolloverAction(t *testing.T) {
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, test *testCase) {
indexClient.On("GetJaegerIndices", "").Return(test.indices, test.getJaegerIndicesErr)
indexClient.On("CreateAlias", aliasToCreate).Return(test.createAliasErr)
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]interface{}{"max_age": "2d"}).Return(test.rolloverErr)
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).Return(test.rolloverErr)
},
},
{
Expand All @@ -74,7 +74,7 @@ func TestRolloverAction(t *testing.T) {
},
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, test *testCase) {
indexClient.On("GetJaegerIndices", "").Return(test.indices, test.getJaegerIndicesErr)
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]interface{}{"max_age": "2d"}).Return(test.rolloverErr)
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).Return(test.rolloverErr)
},
},
{
Expand All @@ -84,7 +84,7 @@ func TestRolloverAction(t *testing.T) {
getJaegerIndicesErr: errors.New("unable to get indices"),
indices: readIndices,
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, test *testCase) {
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]interface{}{"max_age": "2d"}).Return(test.rolloverErr)
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).Return(test.rolloverErr)
indexClient.On("GetJaegerIndices", "").Return(test.indices, test.getJaegerIndicesErr)
},
},
Expand All @@ -95,7 +95,7 @@ func TestRolloverAction(t *testing.T) {
rolloverErr: errors.New("unable to rollover"),
indices: readIndices,
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, test *testCase) {
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]interface{}{"max_age": "2d"}).Return(test.rolloverErr)
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).Return(test.rolloverErr)
},
},
{
Expand All @@ -107,7 +107,7 @@ func TestRolloverAction(t *testing.T) {
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, test *testCase) {
indexClient.On("GetJaegerIndices", "").Return(test.indices, test.getJaegerIndicesErr)
indexClient.On("CreateAlias", aliasToCreate).Return(test.createAliasErr)
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]interface{}{"max_age": "2d"}).Return(test.rolloverErr)
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).Return(test.rolloverErr)
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion cmd/esmapping-generator/app/renderer/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func Test_getMappingAsString(t *testing.T) {
// Prepare
mockTemplateApplier := &mocks.TemplateApplier{}
mockTemplateApplier.On("Execute", mock.Anything, mock.Anything).Return(
func(wr io.Writer, data interface{}) error {
func(wr io.Writer, data any) error {
wr.Write([]byte(tt.want))
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/flags/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestAdminFailToServe(t *testing.T) {
adminServer.serveWithListener(l)
defer adminServer.Close()

waitForEqual(t, healthcheck.Broken, func() interface{} { return adminServer.HC().Get() })
waitForEqual(t, healthcheck.Broken, func() any { return adminServer.HC().Get() })

logEntries := logs.TakeAll()
var matchedEntry string
Expand Down
8 changes: 4 additions & 4 deletions cmd/internal/flags/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ func TestStartErrors(t *testing.T) {
}
go s.RunAndThen(shutdown)

waitForEqual(t, healthcheck.Ready, func() interface{} { return s.HC().Get() })
waitForEqual(t, healthcheck.Ready, func() any { return s.HC().Get() })
s.HC().Set(healthcheck.Unavailable)
waitForEqual(t, healthcheck.Unavailable, func() interface{} { return s.HC().Get() })
waitForEqual(t, healthcheck.Unavailable, func() any { return s.HC().Get() })

s.signalsChannel <- os.Interrupt
waitForEqual(t, true, func() interface{} { return stopped.Load() })
waitForEqual(t, true, func() any { return stopped.Load() })
})
}
}

func waitForEqual(t *testing.T, expected interface{}, getter func() interface{}) {
func waitForEqual(t *testing.T, expected any, getter func() any) {
for i := 0; i < 1000; i++ {
value := getter()
if reflect.DeepEqual(value, expected) {
Expand Down
20 changes: 10 additions & 10 deletions cmd/jaeger/internal/integration/e2e_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,36 +127,36 @@ func (s *E2EStorageIntegration) e2eCleanUp(t *testing.T) {
func createStorageCleanerConfig(t *testing.T, configFile string, storage string) string {
data, err := os.ReadFile(configFile)
require.NoError(t, err)
var config map[string]interface{}
var config map[string]any
err = yaml.Unmarshal(data, &config)
require.NoError(t, err)

service, ok := config["service"].(map[string]interface{})
service, ok := config["service"].(map[string]any)
require.True(t, ok)
service["extensions"] = append(service["extensions"].([]interface{}), "storage_cleaner")
service["extensions"] = append(service["extensions"].([]any), "storage_cleaner")

extensions, ok := config["extensions"].(map[string]interface{})
extensions, ok := config["extensions"].(map[string]any)
require.True(t, ok)
query, ok := extensions["jaeger_query"].(map[string]interface{})
query, ok := extensions["jaeger_query"].(map[string]any)
require.True(t, ok)
trace_storage := query["trace_storage"].(string)
extensions["storage_cleaner"] = map[string]string{"trace_storage": trace_storage}

jaegerStorage, ok := extensions["jaeger_storage"].(map[string]interface{})
jaegerStorage, ok := extensions["jaeger_storage"].(map[string]any)
require.True(t, ok)

switch storage {
case "elasticsearch":
elasticsearch, ok := jaegerStorage["elasticsearch"].(map[string]interface{})
elasticsearch, ok := jaegerStorage["elasticsearch"].(map[string]any)
require.True(t, ok)
esMain, ok := elasticsearch["es_main"].(map[string]interface{})
esMain, ok := elasticsearch["es_main"].(map[string]any)
require.True(t, ok)
esMain["service_cache_ttl"] = "1ms"

case "opensearch":
opensearch, ok := jaegerStorage["opensearch"].(map[string]interface{})
opensearch, ok := jaegerStorage["opensearch"].(map[string]any)
require.True(t, ok)
osMain, ok := opensearch["os_main"].(map[string]interface{})
osMain, ok := opensearch["os_main"].(map[string]any)
require.True(t, ok)
osMain["service_cache_ttl"] = "1ms"

Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/apiv3/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (gw *testGateway) execRequest(t *testing.T, url string) ([]byte, int) {

func (gw *testGateway) verifySnapshot(t *testing.T, body []byte) []byte {
// reformat JSON body with indentation, to make diffing easier
var data interface{}
var data any
require.NoError(t, json.Unmarshal(body, &data), "response: %s", string(body))
body, err := json.MarshalIndent(data, "", " ")
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/apiv3/http_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (h *HTTPGateway) addRoute(
router *mux.Router,
f func(http.ResponseWriter, *http.Request),
route string,
args ...interface{},
args ...any,
) *mux.Route {
var handler http.Handler = http.HandlerFunc(f)
if h.TenancyMgr.Enabled {
Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/grpc_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (g *GRPCHandler) handleErr(msg string, err error) error {
return status.Errorf(codes.Internal, "%s: %v", msg, err)
}

func (g *GRPCHandler) newBaseQueryParameters(r interface{}) (bqp metricsstore.BaseQueryParameters, err error) {
func (g *GRPCHandler) newBaseQueryParameters(r any) (bqp metricsstore.BaseQueryParameters, err error) {
if r == nil {
return bqp, errNilRequest
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/query/app/grpc_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ func TestTenancyContextFlowGRPC(t *testing.T) {
}

addTenantedGetServices := func(mockReader *spanstoremocks.Reader, tenant string, expectedServices []string) {
mockReader.On("GetServices", mock.MatchedBy(func(v interface{}) bool {
mockReader.On("GetServices", mock.MatchedBy(func(v any) bool {
ctx, ok := v.(context.Context)
if !ok {
return false
Expand All @@ -1121,7 +1121,7 @@ func TestTenancyContextFlowGRPC(t *testing.T) {
})).Return(expectedServices, nil).Once()
}
addTenantedGetTrace := func(mockReader *spanstoremocks.Reader, tenant string, trace *model.Trace, err error) {
mockReader.On("GetTrace", mock.MatchedBy(func(v interface{}) bool {
mockReader.On("GetTrace", mock.MatchedBy(func(v any) bool {
ctx, ok := v.(context.Context)
if !ok {
return false
Expand Down
4 changes: 2 additions & 2 deletions cmd/query/app/handler_deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ func TestGetDependenciesSuccess(t *testing.T) {
var response structuredResponse
err := getJSON(ts.server.URL+"/api/dependencies?endTs=1476374248550&service=queen", &response)
assert.NotEmpty(t, response.Data)
data := response.Data.([]interface{})[0]
actual := data.(map[string]interface{})
data := response.Data.([]any)[0]
actual := data.(map[string]any)
assert.Equal(t, "killer", actual["parent"])
assert.Equal(t, "queen", actual["child"])
assert.Equal(t, 12.00, actual["callCount"]) // recovered type is float
Expand Down
10 changes: 5 additions & 5 deletions cmd/query/app/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type HTTPHandler interface {
}

type structuredResponse struct {
Data interface{} `json:"data"`
Data any `json:"data"`
Total int `json:"total"`
Limit int `json:"limit"`
Offset int `json:"offset"`
Expand Down Expand Up @@ -141,7 +141,7 @@ func (aH *APIHandler) handleFunc(
router *mux.Router,
f func(http.ResponseWriter, *http.Request),
routeFmt string,
args ...interface{},
args ...any,
) *mux.Route {
route := aH.formatRoute(routeFmt, args...)
var handler http.Handler = http.HandlerFunc(f)
Expand All @@ -155,8 +155,8 @@ func (aH *APIHandler) handleFunc(
return router.HandleFunc(route, traceMiddleware.ServeHTTP)
}

func (aH *APIHandler) formatRoute(route string, args ...interface{}) string {
args = append([]interface{}{aH.apiPrefix}, args...)
func (aH *APIHandler) formatRoute(route string, args ...any) string {
args = append([]any{aH.apiPrefix}, args...)
return fmt.Sprintf("/%s"+route, args...)
}

Expand Down Expand Up @@ -516,7 +516,7 @@ func (aH *APIHandler) handleError(w http.ResponseWriter, err error, statusCode i
return true
}

func (aH *APIHandler) writeJSON(w http.ResponseWriter, r *http.Request, response interface{}) {
func (aH *APIHandler) writeJSON(w http.ResponseWriter, r *http.Request, response any) {
prettyPrintValue := r.FormValue(prettyPrintParam)
prettyPrint := prettyPrintValue != "" && prettyPrintValue != "false"

Expand Down
Loading

0 comments on commit f2b46d4

Please sign in to comment.