Skip to content

Commit

Permalink
Fix most staticcheck errors
Browse files Browse the repository at this point in the history
  • Loading branch information
songy23 committed Aug 1, 2019
1 parent c53fea9 commit 12a36ee
Show file tree
Hide file tree
Showing 40 changed files with 57 additions and 91 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ all-srcs:
.DEFAULT_GOAL := addlicense-fmt-vet-lint-goimports-misspell-staticcheck-test

.PHONY: addlicense-fmt-vet-lint-goimports-misspell-staticcheck-test
addlicense-fmt-vet-lint-goimports-misspell-test: addlicense fmt vet lint goimports misspell staticcheck test
addlicense-fmt-vet-lint-goimports-misspell-staticcheck-test: addlicense fmt vet lint goimports misspell staticcheck test

.PHONY: e2e-test
e2e-test: otelsvc
Expand Down
8 changes: 4 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func loadReceivers(v *viper.Viper, factories map[string]receiver.Factory) (confi
keyMap := v.GetStringMap(receiversKeyName)

// Prepare resulting map
receivers := make(configmodels.Receivers, 0)
receivers := make(configmodels.Receivers)

// Iterate over input map and create a config for each.
for key := range keyMap {
Expand Down Expand Up @@ -242,7 +242,7 @@ func loadExporters(v *viper.Viper, factories map[string]exporter.Factory) (confi
keyMap := v.GetStringMap(exportersKeyName)

// Prepare resulting map
exporters := make(configmodels.Exporters, 0)
exporters := make(configmodels.Exporters)

// Iterate over exporters and create a config for each.
for key := range keyMap {
Expand Down Expand Up @@ -299,7 +299,7 @@ func loadProcessors(v *viper.Viper, factories map[string]processor.Factory) (con
keyMap := v.GetStringMap(processorsKeyName)

// Prepare resulting map.
processors := make(configmodels.Processors, 0)
processors := make(configmodels.Processors)

// Iterate over processors and create a config for each.
for key := range keyMap {
Expand Down Expand Up @@ -356,7 +356,7 @@ func loadPipelines(v *viper.Viper) (configmodels.Pipelines, error) {
keyMap := v.GetStringMap(pipelinesKeyName)

// Prepare resulting map.
pipelines := make(configmodels.Pipelines, 0)
pipelines := make(configmodels.Pipelines)

// Iterate over input map and create a config for each.
for key := range keyMap {
Expand Down
2 changes: 1 addition & 1 deletion exporter/exporterhelper/metricshelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func newPushMetricsData(droppedSpans int, retError error) PushMetricsData {
}

func generateMetricsTraffic(t *testing.T, te exporter.MetricsExporter, numRequests int, wantError error) {
td := consumerdata.MetricsData{Metrics: make([]*metricspb.Metric, 1, 1)}
td := consumerdata.MetricsData{Metrics: make([]*metricspb.Metric, 1)}
ctx, span := trace.StartSpan(context.Background(), fakeParentSpanName, trace.WithSampler(trace.AlwaysSample()))
defer span.End()
for i := 0; i < numRequests; i++ {
Expand Down
4 changes: 2 additions & 2 deletions exporter/exporterhelper/tracehelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func checkRecordedMetricsForTraceExporter(t *testing.T, te exporter.TraceExporte
doneFn := observabilitytest.SetupRecordedMetricsTest()
defer doneFn()

spans := make([]*tracepb.Span, 2, 2)
spans := make([]*tracepb.Span, 2)
td := consumerdata.TraceData{Spans: spans}
ctx := observability.ContextWithReceiverName(context.Background(), fakeReceiverName)
const numBatches = 7
Expand All @@ -151,7 +151,7 @@ func checkRecordedMetricsForTraceExporter(t *testing.T, te exporter.TraceExporte
}

func generateTraceTraffic(t *testing.T, te exporter.TraceExporter, numRequests int, wantError error) {
td := consumerdata.TraceData{Spans: make([]*tracepb.Span, 1, 1)}
td := consumerdata.TraceData{Spans: make([]*tracepb.Span, 1)}
ctx, span := trace.StartSpan(context.Background(), fakeParentSpanName, trace.WithSampler(trace.AlwaysSample()))
defer span.End()
for i := 0; i < numRequests; i++ {
Expand Down
8 changes: 4 additions & 4 deletions exporter/exportertest/nop_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestNopTraceExporter_NoErrors(t *testing.T) {
if err := nte.ConsumeTraceData(context.Background(), td); err != nil {
t.Fatalf("Wanted nil got error")
}
if "nop_trace" != nte.TraceExportFormat() {
if nte.TraceExportFormat() != "nop_trace" {
t.Fatalf("Wanted nop_trace got %s", nte.TraceExportFormat())
}
}
Expand All @@ -45,7 +45,7 @@ func TestNopTraceExporter_WithErrors(t *testing.T) {
if got := nte.ConsumeTraceData(context.Background(), td); got != want {
t.Fatalf("Want %v Got %v", want, got)
}
if "nop_trace" != nte.TraceExportFormat() {
if nte.TraceExportFormat() != "nop_trace" {
t.Fatalf("Wanted nop_trace got %s", nte.TraceExportFormat())
}
}
Expand All @@ -58,7 +58,7 @@ func TestNopMetricsExporter_NoErrors(t *testing.T) {
if err := nme.ConsumeMetricsData(context.Background(), md); err != nil {
t.Fatalf("Wanted nil got error")
}
if "nop_metrics" != nme.MetricsExportFormat() {
if nme.MetricsExportFormat() != "nop_metrics" {
t.Fatalf("Wanted nop_metrics got %s", nme.MetricsExportFormat())
}
}
Expand All @@ -72,7 +72,7 @@ func TestNopMetricsExporter_WithErrors(t *testing.T) {
if got := nme.ConsumeMetricsData(context.Background(), md); got != want {
t.Fatalf("Want %v Got %v", want, got)
}
if "nop_metrics" != nme.MetricsExportFormat() {
if nme.MetricsExportFormat() != "nop_metrics" {
t.Fatalf("Wanted nop_metrics got %s", nme.MetricsExportFormat())
}
}
4 changes: 2 additions & 2 deletions exporter/exportertest/sink_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestSinkTraceExporter(t *testing.T) {
if !reflect.DeepEqual(got, want) {
t.Errorf("Mismatches responses\nGot:\n\t%v\nWant:\n\t%v\n", got, want)
}
if "sink_trace" != sink.TraceExportFormat() {
if sink.TraceExportFormat() != "sink_trace" {
t.Errorf("Wanted sink_trace got %s", sink.TraceExportFormat())
}
}
Expand All @@ -60,7 +60,7 @@ func TestSinkMetricsExporter(t *testing.T) {
if !reflect.DeepEqual(got, want) {
t.Errorf("Mismatches responses\nGot:\n\t%v\nWant:\n\t%v\n", got, want)
}
if "sink_metrics" != sink.MetricsExportFormat() {
if sink.MetricsExportFormat() != "sink_metrics" {
t.Errorf("Wanted sink_metrics got %s", sink.MetricsExportFormat())
}
}
2 changes: 1 addition & 1 deletion exporter/jaegerexporter/jaeger_thrift_http_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (s *JaegerThriftHTTPSender) ConsumeTraceData(ctx context.Context, td consum
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
if resp.StatusCode >= http.StatusBadRequest {
return fmt.Errorf("Jaeger Thirft HTTP sender error: %d", resp.StatusCode)
return fmt.Errorf("jaeger Thirft HTTP sender error: %d", resp.StatusCode)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions exporter/loggingexporter/logging_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestLoggingTraceExporterNoErrors(t *testing.T) {
if err := lte.ConsumeTraceData(context.Background(), td); err != nil {
t.Fatalf("Wanted nil got %v", err)
}
if "logging_trace" != lte.TraceExportFormat() {
if lte.TraceExportFormat() != "logging_trace" {
t.Errorf("Wanted logging_trace got %v", lte.TraceExportFormat())
}
}
Expand All @@ -50,7 +50,7 @@ func TestLoggingMetricsExporterNoErrors(t *testing.T) {
if err := lme.ConsumeMetricsData(context.Background(), md); err != nil {
t.Fatalf("Wanted nil got %v", err)
}
if "logging_metrics" != lme.MetricsExportFormat() {
if lme.MetricsExportFormat() != "logging_metrics" {
t.Errorf("Wanted logging_metrics got %v", lme.MetricsExportFormat())
}
}
1 change: 0 additions & 1 deletion exporter/opencensusexporter/opencensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ type opencensusConfig struct {
}

type ocagentExporter struct {
counter uint32
exporters chan *ocagent.Exporter
}

Expand Down
1 change: 0 additions & 1 deletion exporter/prometheusexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestCreateTraceExporter(t *testing.T) {
}

func TestCreateMetricsExporter(t *testing.T) {
const defaultTestEndPoint = "127.0.0.1:55678"
tests := []struct {
name string
config Config
Expand Down
2 changes: 1 addition & 1 deletion exporter/zipkinexporter/zipkin.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func ZipkinExportersFromViper(v *viper.Viper) (tps []consumer.TraceConsumer, mps
}
zle, err := newZipkinExporter(endpoint, serviceName, localEndpointURI, uploadPeriod)
if err != nil {
return nil, nil, nil, fmt.Errorf("Cannot configure Zipkin exporter: %v", err)
return nil, nil, nil, fmt.Errorf("cannot configure Zipkin exporter: %v", err)
}
tps = append(tps, zle)
doneFns = append(doneFns, zle.stop)
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/processor/idbatcher/id_batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ type batcher struct {
cbMutex sync.Mutex
currentBatch Batch

numBatches uint64
newBatchesInitialCapacity uint64
stopchan chan bool
stopped bool
Expand Down Expand Up @@ -127,8 +126,8 @@ func (b *batcher) CloseCurrentAndTakeFirstBatch() (Batch, bool) {
b.batches <- b.currentBatch
b.currentBatch = nextBatch
b.cbMutex.Unlock()
return readBatch, true
}
return readBatch, true
}

readBatch := b.currentBatch
Expand Down
1 change: 0 additions & 1 deletion internal/collector/processor/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func MetricTagKeys(level telemetry.Level) []tag.Key {
fallthrough
case telemetry.Basic:
tagKeys = append(tagKeys, TagExporterNameKey)
break
default:
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions observability/observabilitytest/observabilitytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func checkValueForView(vName string, wantTags []tag.Tag, value int64) error {

rows, err := view.RetrieveData(vName)
if err != nil {
return fmt.Errorf("Error retrieving view data for view Name %s", vName)
return fmt.Errorf("error retrieving view data for view Name %s", vName)
}

for _, row := range rows {
Expand All @@ -99,13 +99,13 @@ func checkValueForView(vName string, wantTags []tag.Tag, value int64) error {
if reflect.DeepEqual(wantTags, row.Tags) {
sum := row.Data.(*view.SumData)
if float64(value) != sum.Value {
return fmt.Errorf("Different recorded value: want %v got %v", float64(value), sum.Value)
return fmt.Errorf("different recorded value: want %v got %v", float64(value), sum.Value)
}
// We found the result
return nil
}
}
return fmt.Errorf("Could not find wantTags: %s in rows %v", wantTags, rows)
return fmt.Errorf("could not find wantTags: %s in rows %v", wantTags, rows)
}

func wantsTagsForExporterView(receiverName string, exporterTagName string) []tag.Tag {
Expand Down
2 changes: 1 addition & 1 deletion processor/addattributesprocessor/addattributesprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

var (
errUnsupportedType = errors.New("Unsupported type")
errUnsupportedType = errors.New("unsupported type")
)

type addattributesprocessor struct {
Expand Down
4 changes: 2 additions & 2 deletions processor/attributekeyprocessor/attributekeyprocessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ func Test_attributekeyprocessor_ConsumeTraceData(t *testing.T) {
},
},
td: consumerdata.TraceData{
Spans: make([]*tracepb.Span, 1, 1),
Spans: make([]*tracepb.Span, 1),
},
want: []consumerdata.TraceData{
{
Spans: make([]*tracepb.Span, 1, 1),
Spans: make([]*tracepb.Span, 1),
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions processor/attributekeyprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

func TestLoadConfig(t *testing.T) {
receivers, _, exporters, err := config.ExampleComponents()
require.NoError(t, err)
processors, err := processor.Build(&Factory{})
require.NotNil(t, processors)
require.NoError(t, err)
Expand Down Expand Up @@ -76,6 +77,7 @@ func TestLoadConfig(t *testing.T) {

func TestLoadConfigEmpty(t *testing.T) {
receivers, _, exporters, err := config.ExampleComponents()
require.NoError(t, err)
processors, err := processor.Build(&Factory{})
require.NotNil(t, processors)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion processor/attributekeyprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (f *Factory) CreateDefaultConfig() configmodels.Processor {
TypeVal: typeStr,
NameVal: typeStr,
},
Keys: make(map[string]NewKeyProperties, 0),
Keys: make(map[string]NewKeyProperties),
}
}

Expand Down
2 changes: 0 additions & 2 deletions processor/nodebatcher/node_batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ type batcher struct {
numTickers int
tickTime time.Duration
timeout time.Duration

bucketMu sync.RWMutex
}

var _ consumer.TraceConsumer = (*batcher)(nil)
Expand Down
1 change: 1 addition & 0 deletions processor/probabilisticsampler/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestLoadConfig(t *testing.T) {

func TestLoadConfigEmpty(t *testing.T) {
receivers, _, exporters, err := config.ExampleComponents()
require.NoError(t, err)
processors, err := processor.Build(&Factory{})
require.NotNil(t, processors)
require.NoError(t, err)
Expand Down
6 changes: 1 addition & 5 deletions processor/tailsampling/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ type tailSamplingSpanProcessor struct {
numTracesOnMap uint64
}

const (
sourceFormat = "tail-sampling"
)

var _ processor.TraceProcessor = (*tailSamplingSpanProcessor)(nil)

// NewTraceProcessor returns a processor.TraceProcessor that will perform tail sampling according to the given
Expand Down Expand Up @@ -201,7 +197,7 @@ func (tsp *tailSamplingSpanProcessor) ConsumeTraceData(ctx context.Context, td c
for id, spans := range idToSpans {
lenSpans := int64(len(spans))
lenPolicies := len(tsp.policies)
initialDecisions := make([]sampling.Decision, lenPolicies, lenPolicies)
initialDecisions := make([]sampling.Decision, lenPolicies)
for i := 0; i < lenPolicies; i++ {
initialDecisions[i] = sampling.Pending
}
Expand Down
12 changes: 1 addition & 11 deletions processor/tailsampling/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func TestSamplingPolicyTypicalPath(t *testing.T) {
}

func generateIdsAndBatches(numIds int) ([][]byte, []consumerdata.TraceData) {
traceIds := make([][]byte, numIds, numIds)
traceIds := make([][]byte, numIds)
for i := 0; i < numIds; i++ {
traceIds[i] = tracetranslator.UInt64ToByteTraceID(1, uint64(i+1))
}
Expand Down Expand Up @@ -241,16 +241,6 @@ func generateIdsAndBatches(numIds int) ([][]byte, []consumerdata.TraceData) {
return traceIds, tds
}

func newTestPolicy() []*Policy {
return []*Policy{
{
Name: "test",
Evaluator: sampling.NewAlwaysSample(),
Destination: &mockSpanProcessor{},
},
}
}

type mockPolicyEvaluator struct {
NextDecision sampling.Decision
NextError error
Expand Down
4 changes: 1 addition & 3 deletions receiver/jaegerreceiver/trace_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ type jReceiver struct {

config *Configuration

agent *agentapp.Agent
agentServer *http.Server
agent *agentapp.Agent

grpc *grpc.Server
tchannel *tchannel.Channel
Expand All @@ -93,7 +92,6 @@ const (
// 5775 UDP accept zipkin.thrift over compact thrift protocol
// 6831 UDP accept jaeger.thrift over compact thrift protocol
// 6832 UDP accept jaeger.thrift over binary thrift protocol
defaultZipkinThriftUDPPort = 5775
defaultCompactThriftUDPPort = 6831
defaultBinaryThriftUDPPort = 6832

Expand Down
2 changes: 2 additions & 0 deletions receiver/jaegerreceiver/trace_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
model "github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/proto-gen/api_v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opencensus.io/trace"
"google.golang.org/grpc"

Expand Down Expand Up @@ -106,6 +107,7 @@ func TestGRPCReception(t *testing.T) {
t.Log("StartTraceReception")

conn, err := grpc.Dial(fmt.Sprintf("0.0.0.0:%d", config.CollectorGRPCPort), grpc.WithInsecure())
require.NoError(t, err)
defer conn.Close()

cl := api_v2.NewCollectorServiceClient(conn)
Expand Down
1 change: 0 additions & 1 deletion receiver/opencensusreceiver/octrace/opencensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ func (ocr *Receiver) Stop() {

type receiverWorker struct {
receiver *Receiver
tes agenttracepb.TraceService_ExportServer
cancel chan struct{}
}

Expand Down
2 changes: 1 addition & 1 deletion receiver/opencensusreceiver/opencensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func New(addr string, tc consumer.TraceConsumer, mc consumer.MetricsConsumer, op
// TODO: (@odeke-em) use options to enable address binding changes.
ln, err := net.Listen("tcp", addr)
if err != nil {
return nil, fmt.Errorf("Failed to bind to address %q: %v", addr, err)
return nil, fmt.Errorf("failed to bind to address %q: %v", addr, err)
}

ocr := &Receiver{
Expand Down
Loading

0 comments on commit 12a36ee

Please sign in to comment.