Skip to content

Commit

Permalink
[all][chore] Moved from interface{} to any for all go code (#29072)
Browse files Browse the repository at this point in the history
Additionally added a golangci-lint.yaml update to automatically apply
this change to new code going forward

Fixes #23811

---------

Co-authored-by: Alex Boten <[email protected]>
  • Loading branch information
lucasoskorep and Alex Boten authored Nov 9, 2023
1 parent 330ff0a commit f4c4485
Show file tree
Hide file tree
Showing 581 changed files with 4,888 additions and 4,886 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ linters-settings:
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
rewrite-rules:
- pattern: interface{}
replacement: any

goimports:
# put imports beginning with prefix after 3rd-party packages;
Expand Down
2 changes: 1 addition & 1 deletion cmd/configschema/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type CfgInfo struct {
// the component type, e.g. "otlpreceiver.Config"
Type component.Type
// an instance of the component's configuration struct
CfgInstance interface{}
CfgInstance any
}

// GetAllCfgInfos accepts a Factories struct, then creates and returns a CfgInfo
Expand Down
12 changes: 6 additions & 6 deletions cmd/configschema/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (

// Field holds attributes and subfields of a config struct.
type Field struct {
Name string `yaml:",omitempty"`
Type string `yaml:",omitempty"`
Kind string `yaml:",omitempty"`
Default interface{} `yaml:",omitempty"`
Doc string `yaml:",omitempty"`
Fields []*Field `yaml:",omitempty"`
Name string `yaml:",omitempty"`
Type string `yaml:",omitempty"`
Kind string `yaml:",omitempty"`
Default any `yaml:",omitempty"`
Doc string `yaml:",omitempty"`
Fields []*Field `yaml:",omitempty"`
}

// ReadFields accepts both a config struct's Value, as well as a DirResolver,
Expand Down
6 changes: 3 additions & 3 deletions cmd/configschema/fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func TestReadFieldsWithDefaults(t *testing.T) {
defaults := map[string]interface{}{
defaults := map[string]any{
"one": "1",
"two": int64(2),
"three": uint64(3),
Expand Down Expand Up @@ -43,7 +43,7 @@ func TestReadFieldsWithDefaults(t *testing.T) {
}

func TestReadFieldsWithoutDefaults(t *testing.T) {
testReadFields(t, testStruct{}, map[string]interface{}{
testReadFields(t, testStruct{}, map[string]any{
"one": "",
"three": uint64(0),
"four": false,
Expand All @@ -53,7 +53,7 @@ func TestReadFieldsWithoutDefaults(t *testing.T) {
})
}

func testReadFields(t *testing.T, s testStruct, defaults map[string]interface{}) {
func testReadFields(t *testing.T, s testStruct, defaults map[string]any) {
root, _ := ReadFields(
reflect.ValueOf(s),
testDR(),
Expand Down
2 changes: 1 addition & 1 deletion cmd/configschema/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestTypetoProjectPath_External(t *testing.T) {
assert.Equal(t, "", dir)
}

func testTypeToPackagePath(t *testing.T, v interface{}) string {
func testTypeToPackagePath(t *testing.T, v any) string {
packageDir, err := testDR().TypeToPackagePath(reflect.ValueOf(v).Type())
require.NoError(t, err)
return packageDir
Expand Down
2 changes: 1 addition & 1 deletion cmd/mdatagen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func templatize(tmplFile string, md metadata) *template.Template {
template.
New(filepath.Base(tmplFile)).
Option("missingkey=error").
Funcs(map[string]interface{}{
Funcs(map[string]any{
"publicVar": func(s string) (string, error) {
return formatIdentifier(s, true)
},
Expand Down
2 changes: 1 addition & 1 deletion confmap/provider/s3provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (fmp *provider) Retrieve(ctx context.Context, uri string, _ confmap.Watcher
// read config from response body
dec := yaml.NewDecoder(resp.Body)
defer resp.Body.Close()
var conf map[string]interface{}
var conf map[string]any
err = dec.Decode(&conf)
if err != nil {
return nil, err
Expand Down
12 changes: 6 additions & 6 deletions connector/exceptionsconnector/connector_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ func TestBuildKeyWithDimensions(t *testing.T) {
for _, tc := range []struct {
name string
optionalDims []dimension
resourceAttrMap map[string]interface{}
spanAttrMap map[string]interface{}
resourceAttrMap map[string]any
spanAttrMap map[string]any
wantKey string
}{
{
Expand All @@ -273,7 +273,7 @@ func TestBuildKeyWithDimensions(t *testing.T) {
optionalDims: []dimension{
{name: "foo"},
},
spanAttrMap: map[string]interface{}{
spanAttrMap: map[string]any{
"foo": 99,
},
wantKey: "ab\u0000c\u0000SPAN_KIND_UNSPECIFIED\u0000STATUS_CODE_UNSET\u000099",
Expand All @@ -283,7 +283,7 @@ func TestBuildKeyWithDimensions(t *testing.T) {
optionalDims: []dimension{
{name: "foo"},
},
resourceAttrMap: map[string]interface{}{
resourceAttrMap: map[string]any{
"foo": 99,
},
wantKey: "ab\u0000c\u0000SPAN_KIND_UNSPECIFIED\u0000STATUS_CODE_UNSET\u000099",
Expand All @@ -293,10 +293,10 @@ func TestBuildKeyWithDimensions(t *testing.T) {
optionalDims: []dimension{
{name: "foo"},
},
spanAttrMap: map[string]interface{}{
spanAttrMap: map[string]any{
"foo": 100,
},
resourceAttrMap: map[string]interface{}{
resourceAttrMap: map[string]any{
"foo": 99,
},
wantKey: "ab\u0000c\u0000SPAN_KIND_UNSPECIFIED\u0000STATUS_CODE_UNSET\u0000100",
Expand Down
2 changes: 1 addition & 1 deletion connector/routingconnector/internal/common/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func createRouteFunction[K any](_ ottl.FunctionContext, _ ottl.Arguments) (ottl.ExprFunc[K], error) {
return func(context.Context, K) (interface{}, error) {
return func(context.Context, K) (any, error) {
return true, nil
}, nil
}
Expand Down
12 changes: 6 additions & 6 deletions connector/spanmetricsconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ func TestBuildKeyWithDimensions(t *testing.T) {
for _, tc := range []struct {
name string
optionalDims []dimension
resourceAttrMap map[string]interface{}
spanAttrMap map[string]interface{}
resourceAttrMap map[string]any
spanAttrMap map[string]any
wantKey string
}{
{
Expand All @@ -520,7 +520,7 @@ func TestBuildKeyWithDimensions(t *testing.T) {
optionalDims: []dimension{
{name: "foo"},
},
spanAttrMap: map[string]interface{}{
spanAttrMap: map[string]any{
"foo": 99,
},
wantKey: "ab\u0000c\u0000SPAN_KIND_UNSPECIFIED\u0000STATUS_CODE_UNSET\u000099",
Expand All @@ -530,7 +530,7 @@ func TestBuildKeyWithDimensions(t *testing.T) {
optionalDims: []dimension{
{name: "foo"},
},
resourceAttrMap: map[string]interface{}{
resourceAttrMap: map[string]any{
"foo": 99,
},
wantKey: "ab\u0000c\u0000SPAN_KIND_UNSPECIFIED\u0000STATUS_CODE_UNSET\u000099",
Expand All @@ -540,10 +540,10 @@ func TestBuildKeyWithDimensions(t *testing.T) {
optionalDims: []dimension{
{name: "foo"},
},
spanAttrMap: map[string]interface{}{
spanAttrMap: map[string]any{
"foo": 100,
},
resourceAttrMap: map[string]interface{}{
resourceAttrMap: map[string]any{
"foo": 99,
},
wantKey: "ab\u0000c\u0000SPAN_KIND_UNSPECIFIED\u0000STATUS_CODE_UNSET\u0000100",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func resourceToLogContents(resource pcommon.Resource) []*sls.LogContent {
}
}

fields := map[string]interface{}{}
fields := map[string]any{}
attrs.Range(func(k string, v pcommon.Value) bool {
if k == conventions.AttributeServiceName || k == conventions.AttributeHostName {
return true
Expand Down Expand Up @@ -144,7 +144,7 @@ func mapLogRecordToLogService(lr plog.LogRecord,
Value: proto.String(lr.SeverityText()),
})

fields := map[string]interface{}{}
fields := map[string]any{}
lr.Attributes().Range(func(k string, v pcommon.Value) bool {
fields[k] = v.AsString()
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ func statusCodeToShortString(code ptrace.StatusCode) string {
}

func eventsToString(events ptrace.SpanEventSlice) string {
eventArray := make([]map[string]interface{}, 0, events.Len())
eventArray := make([]map[string]any, 0, events.Len())
for i := 0; i < events.Len(); i++ {
spanEvent := events.At(i)
event := map[string]interface{}{}
event := map[string]any{}
event[nameField] = spanEvent.Name()
event[timeField] = spanEvent.Timestamp()
event[attributeField] = spanEvent.Attributes().AsRaw()
Expand All @@ -192,10 +192,10 @@ func eventsToString(events ptrace.SpanEventSlice) string {
}

func spanLinksToString(spanLinkSlice ptrace.SpanLinkSlice) string {
linkArray := make([]map[string]interface{}, 0, spanLinkSlice.Len())
linkArray := make([]map[string]any, 0, spanLinkSlice.Len())
for i := 0; i < spanLinkSlice.Len(); i++ {
spanLink := spanLinkSlice.At(i)
link := map[string]interface{}{}
link := map[string]any{}
link[spanIDField] = traceutil.SpanIDToHexOrEmptyString(spanLink.SpanID())
link[traceIDField] = traceutil.TraceIDToHexOrEmptyString(spanLink.TraceID())
link[attributeField] = spanLink.Attributes().AsRaw()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestTraceDataToLogService(t *testing.T) {
}
}

func loadFromJSON(file string, obj interface{}) error {
func loadFromJSON(file string, obj any) error {
blob, err := os.ReadFile(file)
if err == nil {
err = json.Unmarshal(blob, obj)
Expand Down Expand Up @@ -97,7 +97,7 @@ func fillResource(resource pcommon.Resource) {
}

func fillHTTPClientSpan(span ptrace.Span) {
attributes := make(map[string]interface{})
attributes := make(map[string]any)
attributes[conventions.AttributeHTTPMethod] = "GET"
attributes[conventions.AttributeHTTPURL] = "https://api.example.com/users/junit"
attributes[conventions.AttributeHTTPStatusCode] = 200
Expand Down Expand Up @@ -129,7 +129,7 @@ func fillHTTPClientSpan(span ptrace.Span) {
}

func fillHTTPServerSpan(span ptrace.Span) {
attributes := make(map[string]interface{})
attributes := make(map[string]any)
attributes[conventions.AttributeHTTPMethod] = "GET"
attributes[conventions.AttributeHTTPURL] = "https://api.example.com/users/junit"
attributes[conventions.AttributeHTTPClientIP] = "192.168.15.32"
Expand All @@ -151,7 +151,7 @@ func fillHTTPServerSpan(span ptrace.Span) {
status.SetMessage("something error")
}

func constructSpanAttributes(attributes map[string]interface{}) pcommon.Map {
func constructSpanAttributes(attributes map[string]any) pcommon.Map {
attrs := pcommon.NewMap()
for key, value := range attributes {
if cast, ok := value.(int); ok {
Expand Down
24 changes: 12 additions & 12 deletions exporter/awscloudwatchlogsexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,18 @@ func pushLogsToCWLogs(logger *zap.Logger, ld plog.Logs, config *Config, pusher c
}

type cwLogBody struct {
Body interface{} `json:"body,omitempty"`
SeverityNumber int32 `json:"severity_number,omitempty"`
SeverityText string `json:"severity_text,omitempty"`
DroppedAttributesCount uint32 `json:"dropped_attributes_count,omitempty"`
Flags uint32 `json:"flags,omitempty"`
TraceID string `json:"trace_id,omitempty"`
SpanID string `json:"span_id,omitempty"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
Resource map[string]interface{} `json:"resource,omitempty"`
Body any `json:"body,omitempty"`
SeverityNumber int32 `json:"severity_number,omitempty"`
SeverityText string `json:"severity_text,omitempty"`
DroppedAttributesCount uint32 `json:"dropped_attributes_count,omitempty"`
Flags uint32 `json:"flags,omitempty"`
TraceID string `json:"trace_id,omitempty"`
SpanID string `json:"span_id,omitempty"`
Attributes map[string]any `json:"attributes,omitempty"`
Resource map[string]any `json:"resource,omitempty"`
}

func logToCWLog(resourceAttrs map[string]interface{}, log plog.LogRecord, config *Config) (*cwlogs.Event, error) {
func logToCWLog(resourceAttrs map[string]any, log plog.LogRecord, config *Config) (*cwlogs.Event, error) {
// TODO(jbd): Benchmark and improve the allocations.
// Evaluate go.elastic.co/fastjson as a replacement for encoding/json.
logGroupName := config.LogGroupName
Expand Down Expand Up @@ -232,11 +232,11 @@ func logToCWLog(resourceAttrs map[string]interface{}, log plog.LogRecord, config
}, nil
}

func attrsValue(attrs pcommon.Map) map[string]interface{} {
func attrsValue(attrs pcommon.Map) map[string]any {
if attrs.Len() == 0 {
return nil
}
out := make(map[string]interface{}, attrs.Len())
out := make(map[string]any, attrs.Len())
attrs.Range(func(k string, v pcommon.Value) bool {
out[k] = v.AsRaw()
return true
Expand Down
4 changes: 2 additions & 2 deletions exporter/awsemfexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ func (config *Config) Validate() error {

}

func newEMFSupportedUnits() map[string]interface{} {
unitIndexer := map[string]interface{}{}
func newEMFSupportedUnits() map[string]any {
unitIndexer := map[string]any{}
for _, unit := range []string{"Seconds", "Microseconds", "Milliseconds", "Bytes", "Kilobytes", "Megabytes",
"Gigabytes", "Terabytes", "Bits", "Kilobits", "Megabits", "Gigabits", "Terabits",
"Percent", "Count", "Bytes/Second", "Kilobytes/Second", "Megabytes/Second",
Expand Down
8 changes: 4 additions & 4 deletions exporter/awsemfexporter/datapoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type emfCalculators struct {
summary aws.MetricCalculator
}

func calculateSummaryDelta(prev *aws.MetricValue, val interface{}, _ time.Time) (interface{}, bool) {
func calculateSummaryDelta(prev *aws.MetricValue, val any, _ time.Time) (any, bool) {
metricEntry := val.(summaryMetricEntry)
summaryDelta := metricEntry.sum
countDelta := metricEntry.count
Expand All @@ -44,7 +44,7 @@ func calculateSummaryDelta(prev *aws.MetricValue, val interface{}, _ time.Time)
// dataPoint represents a processed metric data point
type dataPoint struct {
name string
value interface{}
value any
labels map[string]string
timestampMs int64
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func (dps numberDataPointSlice) CalculateDeltaDatapoints(i int, instrumentationS
retained := true

if dps.adjustToDelta {
var deltaVal interface{}
var deltaVal any
mKey := aws.NewKey(dps.deltaMetricMetadata, labels)
deltaVal, retained = calculators.delta.Calculate(mKey, metricVal, metric.Timestamp().AsTime())

Expand Down Expand Up @@ -299,7 +299,7 @@ func (dps summaryDataPointSlice) CalculateDeltaDatapoints(i int, instrumentation
datapoints := []dataPoint{}

if dps.adjustToDelta {
var delta interface{}
var delta any
mKey := aws.NewKey(dps.deltaMetricMetadata, labels)
delta, retained = calculators.summary.Calculate(mKey, summaryMetricEntry{sum, count}, metric.Timestamp().AsTime())

Expand Down
Loading

0 comments on commit f4c4485

Please sign in to comment.