Skip to content

Commit

Permalink
Enable unconvert linter, fix errors (#1546)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Nov 10, 2020
1 parent 7b959c2 commit 1ac9899
Show file tree
Hide file tree
Showing 29 changed files with 44 additions and 47 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ linters:
- staticcheck
- misspell
- scopelint
- unconvert

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (kv *KeyValues) String() string {

func (kv *KeyValues) labelToStringBuilder(sb *strings.Builder) {
for index, label := range kv.keyValues {
sb.WriteString(string(label.Key))
sb.WriteString(label.Key)
sb.WriteString("#$#")
sb.WriteString(label.Value)
if index != len(kv.keyValues)-1 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func spansToLogServiceData(spans []*tracepb.Span) []*sls.Log {

for k, v := range span.GetAttributes().GetAttributeMap() {
contents = append(contents, &sls.LogContent{
Key: proto.String(tagsPrefix + string(k)),
Key: proto.String(tagsPrefix + k),
Value: proto.String(attributeValueToString(v)),
})
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/awsemfexporter/metric_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ func TestBuildCWMetric(t *testing.T) {
"label1": "value1",
})
dp.SetCount(uint64(17))
dp.SetSum(float64(17.13))
dp.SetSum(17.13)
dp.SetBucketCounts([]uint64{1, 2, 3})
dp.SetExplicitBounds([]float64{1, 2, 3})

Expand Down
2 changes: 1 addition & 1 deletion exporter/azuremonitorexporter/trace_to_envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ func setAttributeValueAsPropertyOrMeasurement(
measurements[key] = float64(attributeValue.IntVal())

case pdata.AttributeValueDOUBLE:
measurements[key] = float64(attributeValue.DoubleVal())
measurements[key] = attributeValue.DoubleVal()
}
}

Expand Down
2 changes: 1 addition & 1 deletion exporter/azuremonitorexporter/trace_to_envelope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ func assertAttributesCopiedToPropertiesOrMeasurements(
case pdata.AttributeValueDOUBLE:
m, exists := measurements[k]
assert.True(t, exists)
assert.Equal(t, float64(v.DoubleVal()), m)
assert.Equal(t, v.DoubleVal(), m)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/carbonexporter/metricdata_to_plaintext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func expectedSummaryLines(
) []string {
lines := []string{
metricName + ".count" + tags + " " + formatInt64(count) + " " + timestampStr,
metricName + tags + " " + formatFloatForValue(float64(sum)) + " " + timestampStr,
metricName + tags + " " + formatFloatForValue(sum) + " " + timestampStr,
}

for _, p := range percentiles {
Expand Down
2 changes: 1 addition & 1 deletion exporter/datadogexporter/metrics/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewGauge(name string, ts uint64, value float64, tags []string) datadog.Metr
// DefaultMetrics creates built-in metrics to report that an exporter is running
func DefaultMetrics(exporterType string, timestamp uint64) []datadog.Metric {
return []datadog.Metric{
NewGauge(fmt.Sprintf("datadog_exporter.%s.running", exporterType), timestamp, float64(1.0), []string{}),
NewGauge(fmt.Sprintf("datadog_exporter.%s.running", exporterType), timestamp, 1.0, []string{}),
}
}

Expand Down
8 changes: 3 additions & 5 deletions exporter/datadogexporter/metrics_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ func mapIntMetrics(name string, slice pdata.IntDataPointSlice) []datadog.Metric
if p.IsNil() {
continue
}
ms = append(ms,
metrics.NewGauge(name, uint64(p.Timestamp()), float64(p.Value()), getTags(p.LabelsMap())),
)
ms = append(ms, metrics.NewGauge(name, uint64(p.Timestamp()), float64(p.Value()), getTags(p.LabelsMap())))
}
return ms
}
Expand All @@ -65,7 +63,7 @@ func mapDoubleMetrics(name string, slice pdata.DoubleDataPointSlice) []datadog.M
continue
}
ms = append(ms,
metrics.NewGauge(name, uint64(p.Timestamp()), float64(p.Value()), getTags(p.LabelsMap())),
metrics.NewGauge(name, uint64(p.Timestamp()), p.Value(), getTags(p.LabelsMap())),
)
}
return ms
Expand Down Expand Up @@ -131,7 +129,7 @@ func mapDoubleHistogramMetrics(name string, slice pdata.DoubleHistogramDataPoint

ms = append(ms,
metrics.NewGauge(fmt.Sprintf("%s.count", name), ts, float64(p.Count()), tags),
metrics.NewGauge(fmt.Sprintf("%s.sum", name), ts, float64(p.Sum()), tags),
metrics.NewGauge(fmt.Sprintf("%s.sum", name), ts, p.Sum(), tags),
)

if buckets {
Expand Down
2 changes: 1 addition & 1 deletion exporter/datadogexporter/translate_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func spanToDatadogSpan(s pdata.Span,
Resource: getDatadogResourceName(s, tags),
Service: serviceName,
Start: int64(startTime),
Duration: int64(duration),
Duration: duration,
Metrics: map[string]float64{},
Meta: map[string]string{},
Type: datadogType,
Expand Down
2 changes: 1 addition & 1 deletion exporter/honeycombexporter/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestSpanAttributesToMap(t *testing.T) {
got := spanAttributesToMap(attrs)
want := wantResults[i]
for k := range want {
if interface{}(got[k]) != want[k] {
if got[k] != want[k] {
t.Errorf("Got: %+v, Want: %+v", got[k], want[k])
}
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/newrelicexporter/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestTransformSpan(t *testing.T) {
"resource": "R1",
"prod": true,
"weight": int64(10),
"score": float64(99.8),
"score": 99.8,
"user": "alice",
},
},
Expand Down
2 changes: 1 addition & 1 deletion exporter/splunkhecexporter/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func createTraceData(numberOfTraces int) pdata.Traces {
span.SetEndTime(pdata.TimestampUnixNano((i + 2) * 1e9))
span.SetTraceID(pdata.NewTraceID([16]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}))
span.SetSpanID(pdata.NewSpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}))
span.SetTraceState(pdata.TraceState("foo"))
span.SetTraceState("foo")
if i%2 == 0 {
span.SetParentSpanID(pdata.NewSpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8}))
span.Status().InitEmpty()
Expand Down
2 changes: 1 addition & 1 deletion exporter/splunkhecexporter/tracedata_to_splunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func makeSpan(name string, ts *pdata.TimestampUnixNano) pdata.Span {
}
spanLink := pdata.NewSpanLink()
spanLink.InitEmpty()
spanLink.SetTraceState(pdata.TraceState("OK"))
spanLink.SetTraceState("OK")
bytes, _ := hex.DecodeString("12345678")
var traceID [16]byte
copy(traceID[:], bytes)
Expand Down
4 changes: 2 additions & 2 deletions processor/groupbytraceprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func TestTraceDisappearedFromStorageBeforeReleasing(t *testing.T) {

// test
// we trigger this manually, instead of waiting the whole duration
err = p.markAsReleased(pdata.TraceID(traceID))
err = p.markAsReleased(traceID)

// verify
assert.Error(t, err)
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestTraceErrorFromStorageWhileReleasing(t *testing.T) {

// test
// we trigger this manually, instead of waiting the whole duration
err = p.markAsReleased(pdata.TraceID(traceID))
err = p.markAsReleased(traceID)

// verify
assert.True(t, errors.Is(err, expectedError))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func TestAttributesToMap(t *testing.T) {
m := map[string]interface{}{
"str": "a",
"int": int64(5),
"double": float64(5.0),
"double": 5.0,
"bool": true,
"map": map[string]interface{}{
"inner": "val",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

func TestGetMetricsData(t *testing.T) {
v := uint64(1)
f := float64(1.0)
f := 1.0

memStats := make(map[string]uint64)
memStats["cache"] = v
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

func TestGetContainerAndTaskMetrics(t *testing.T) {
v := uint64(1)
f := float64(1.0)
f := 1.0
floatZero := float64(0)

memStats := make(map[string]uint64)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestMetricSampleFile(t *testing.T) {

func TestMetricData(t *testing.T) {
v := uint64(1)
f := float64(1.0)
f := 1.0

memStats := make(map[string]uint64)
memStats["cache"] = v
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func convertToOTLPMetrics(prefix string, m ECSMetrics, r pdata.Resource, timesta
ilms.Append(intGauge(prefix+AttributeCPUCores, UnitCount, int64(m.NumOfCPUCores), timestamp))
ilms.Append(intGauge(prefix+AttributeCPUOnlines, UnitCount, int64(m.CPUOnlineCpus), timestamp))
ilms.Append(intSum(prefix+AttributeCPUSystemUsage, UnitNanoSecond, int64(m.SystemCPUUsage), timestamp))
ilms.Append(doubleGauge(prefix+AttributeCPUUtilized, UnitPercent, float64(m.CPUUtilized), timestamp))
ilms.Append(doubleGauge(prefix+AttributeCPUReserved, UnitVCpu, float64(m.CPUReserved), timestamp))
ilms.Append(doubleGauge(prefix+AttributeCPUUsageInVCPU, UnitVCpu, float64(m.CPUUsageInVCPU), timestamp))
ilms.Append(doubleGauge(prefix+AttributeCPUUtilized, UnitPercent, m.CPUUtilized, timestamp))
ilms.Append(doubleGauge(prefix+AttributeCPUReserved, UnitVCpu, m.CPUReserved, timestamp))
ilms.Append(doubleGauge(prefix+AttributeCPUUsageInVCPU, UnitVCpu, m.CPUUsageInVCPU, timestamp))

ilms.Append(doubleGauge(prefix+AttributeNetworkRateRx, UnitBytesPerSec, float64(m.NetworkRateRxBytesPerSecond), timestamp))
ilms.Append(doubleGauge(prefix+AttributeNetworkRateTx, UnitBytesPerSec, float64(m.NetworkRateTxBytesPerSecond), timestamp))
ilms.Append(doubleGauge(prefix+AttributeNetworkRateRx, UnitBytesPerSec, m.NetworkRateRxBytesPerSecond, timestamp))
ilms.Append(doubleGauge(prefix+AttributeNetworkRateTx, UnitBytesPerSec, m.NetworkRateTxBytesPerSecond, timestamp))

ilms.Append(intSum(prefix+AttributeNetworkRxBytes, UnitBytes, int64(m.NetworkRxBytes), timestamp))
ilms.Append(intSum(prefix+AttributeNetworkRxPackets, UnitCount, int64(m.NetworkRxPackets), timestamp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestIntGauge(t *testing.T) {

func TestDoubleGauge(t *testing.T) {
timestamp := pdata.TimeToUnixNano(time.Now())
floatValue := float64(100.01)
floatValue := 100.01

m := doubleGauge("cpu_utilized", "Count", floatValue, timestamp)
require.NotNil(t, m)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestAddAnnotations(t *testing.T) {
input["int64"] = int64(2)
input["bool"] = false
input["float32"] = float32(4.5)
input["float64"] = float64(5.5)
input["float64"] = 5.5

attrMap := pdata.NewAttributeMap()
attrMap.InitEmptyWithCapacity(initAttrCapacity)
Expand All @@ -41,8 +41,8 @@ func TestAddAnnotations(t *testing.T) {
"int32": pdata.NewAttributeValueInt(int64(1)),
"int64": pdata.NewAttributeValueInt(int64(2)),
"bool": pdata.NewAttributeValueBool(false),
"float32": pdata.NewAttributeValueDouble(float64(4.5)),
"float64": pdata.NewAttributeValueDouble(float64(5.5)),
"float32": pdata.NewAttributeValueDouble(4.5),
"float64": pdata.NewAttributeValueDouble(5.5),
},
)
assert.Equal(t, expectedAttrMap.Sort(), attrMap.Sort(), "attribute maps differ")
Expand Down
2 changes: 1 addition & 1 deletion receiver/collectdreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
const (
typeStr = "collectd"
defaultBindEndpoint = "localhost:8081"
defaultTimeout = time.Duration(time.Second * 30)
defaultTimeout = time.Second * 30
defaultEncodingFormat = "json"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestMetricsStoreOperations(t *testing.T) {
// Remove non existent item
ms.remove(&corev1.Pod{
ObjectMeta: v1.ObjectMeta{
UID: types.UID("1"),
UID: "1",
},
})
require.Equal(t, len(updates), len(ms.metricsCache))
Expand Down
7 changes: 3 additions & 4 deletions receiver/kubeletstatsreceiver/kubelet/accumulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"go.uber.org/zap/zaptest/observer"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
stats "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1"
)

Expand All @@ -53,7 +52,7 @@ func TestMetadataErrorCases(t *testing.T) {
Items: []v1.Pod{
{
ObjectMeta: metav1.ObjectMeta{
UID: types.UID("pod-uid-123"),
UID: "pod-uid-123",
},
Status: v1.PodStatus{
ContainerStatuses: []v1.ContainerStatus{
Expand Down Expand Up @@ -121,7 +120,7 @@ func TestMetadataErrorCases(t *testing.T) {
Items: []v1.Pod{
{
ObjectMeta: metav1.ObjectMeta{
UID: types.UID("pod-uid-123"),
UID: "pod-uid-123",
},
Spec: v1.PodSpec{
Volumes: []v1.Volume{
Expand Down Expand Up @@ -163,7 +162,7 @@ func TestMetadataErrorCases(t *testing.T) {
Items: []v1.Pod{
{
ObjectMeta: metav1.ObjectMeta{
UID: types.UID("pod-uid-123"),
UID: "pod-uid-123",
},
Spec: v1.PodSpec{
Volumes: []v1.Volume{
Expand Down
9 changes: 4 additions & 5 deletions receiver/kubeletstatsreceiver/kubelet/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/stretchr/testify/require"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

func TestValidateMetadataLabelsConfig(t *testing.T) {
Expand Down Expand Up @@ -88,7 +87,7 @@ func TestSetExtraLabels(t *testing.T) {
Items: []v1.Pod{
{
ObjectMeta: metav1.ObjectMeta{
UID: types.UID("uid-1234"),
UID: "uid-1234",
},
Status: v1.PodStatus{
ContainerStatuses: []v1.ContainerStatus{
Expand Down Expand Up @@ -118,7 +117,7 @@ func TestSetExtraLabels(t *testing.T) {
Items: []v1.Pod{
{
ObjectMeta: metav1.ObjectMeta{
UID: types.UID("uid-1234"),
UID: "uid-1234",
},
Status: v1.PodStatus{
ContainerStatuses: []v1.ContainerStatus{
Expand Down Expand Up @@ -146,7 +145,7 @@ func TestSetExtraLabels(t *testing.T) {
Items: []v1.Pod{
{
ObjectMeta: metav1.ObjectMeta{
UID: types.UID("uid-1234"),
UID: "uid-1234",
},
Spec: v1.PodSpec{
Volumes: []v1.Volume{
Expand Down Expand Up @@ -312,7 +311,7 @@ func TestSetExtraLabelsForVolumeTypes(t *testing.T) {
Items: []v1.Pod{
{
ObjectMeta: metav1.ObjectMeta{
UID: types.UID("uid-1234"),
UID: "uid-1234",
},
Spec: v1.PodSpec{
Volumes: []v1.Volume{
Expand Down
2 changes: 1 addition & 1 deletion receiver/receivercreator/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (run *receiverRunner) loadRuntimeReceiverConfig(
return nil, fmt.Errorf("failed to merge template config from discovered runtime values: %v", err)
}

receiverConfig, err := config.LoadReceiver(mergedConfig, configmodels.Type(receiver.typeStr), receiver.fullName, factory)
receiverConfig, err := config.LoadReceiver(mergedConfig, receiver.typeStr, receiver.fullName, factory)
if err != nil {
return nil, fmt.Errorf("failed to load template config: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/stanzareceiver/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type UnstartableOperator struct {
}

func newUnstartableParams() pipeline.Params {
return pipeline.Params(map[string]interface{}{"type": "unstartable_operator"})
return map[string]interface{}{"type": "unstartable_operator"}
}

// NewUnstartableConfig creates new output config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ func (ar *MockAwsXrayReceiver) handleRequest(ctx context.Context, req *http.Requ

var result map[string]interface{}

json.Unmarshal([]byte(body), &result)
json.Unmarshal(body, &result)

traces, _ := ToTraces([]byte(body))
traces, _ := ToTraces(body)

ar.nextConsumer.ConsumeTraces(ctx, *traces)

Expand Down

0 comments on commit 1ac9899

Please sign in to comment.