Skip to content

Commit

Permalink
Remove lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu committed Nov 6, 2020
1 parent ff49f15 commit 5cfe530
Show file tree
Hide file tree
Showing 37 changed files with 50 additions and 91 deletions.
6 changes: 1 addition & 5 deletions consumer/pdata/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,11 +617,7 @@ func (am AttributeMap) UpsertBool(k string, v bool) {

// IsEmpty returns true if the underlying data are equivalent with an empty message.
func (am AttributeMap) IsEmpty() bool {
if len(*am.orig) == 0 {
return true
}

return false
return len(*am.orig) == 0
}

// Sort sorts the entries in the AttributeMap so two instances can be compared.
Expand Down
1 change: 0 additions & 1 deletion exporter/kafkaexporter/otlp_marshaller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
func TestOTLPMarshaller(t *testing.T) {
td := pdata.NewTraces()
td.ResourceSpans().Resize(1)
td.ResourceSpans().At(0).Resource().InitEmpty()
td.ResourceSpans().At(0).Resource().Attributes().InsertString("foo", "bar")
request := &otlptrace.ExportTraceServiceRequest{
ResourceSpans: pdata.TracesToOtlp(td),
Expand Down
6 changes: 3 additions & 3 deletions exporter/loggingexporter/logging_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (s *loggingExporter) pushTraceData(
buf.logEntry("* Nil ResourceSpans")
continue
}
if !rs.Resource().IsNil() {
if !rs.Resource().IsEmpty() {
buf.logAttributeMap("Resource labels", rs.Resource().Attributes())
}
ilss := rs.InstrumentationLibrarySpans()
Expand Down Expand Up @@ -391,7 +391,7 @@ func (s *loggingExporter) pushMetricsData(
buf.logEntry("* Nil ResourceMetrics")
continue
}
if !rm.Resource().IsNil() {
if !rm.Resource().IsEmpty() {
buf.logAttributeMap("Resource labels", rm.Resource().Attributes())
}
ilms := rm.InstrumentationLibraryMetrics()
Expand Down Expand Up @@ -504,7 +504,7 @@ func (s *loggingExporter) pushLogData(
buf.logEntry("* Nil ResourceLog")
continue
}
if !rl.Resource().IsNil() {
if !rl.Resource().IsEmpty() {
buf.logAttributeMap("Resource labels", rl.Resource().Attributes())
}

Expand Down
4 changes: 0 additions & 4 deletions exporter/opencensusexporter/opencensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ func TestSendTraces(t *testing.T) {
})
traces = sink.AllTraces()
require.Len(t, traces, 1)
// The conversion will initialize the Resource
td.ResourceSpans().At(0).Resource().InitEmpty()
assert.Equal(t, td, traces[0])
}

Expand Down Expand Up @@ -182,8 +180,6 @@ func TestSendMetrics(t *testing.T) {
})
metrics = sink.AllMetrics()
require.Len(t, metrics, 1)
// The conversion will initialize the Resource
md.ResourceMetrics().At(0).Resource().InitEmpty()
assert.Equal(t, md, metrics[0])
}

Expand Down
2 changes: 0 additions & 2 deletions internal/data/testdata/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
)

func initResource1(r pdata.Resource) {
r.InitEmpty()
initResourceAttributes1(r.Attributes())
}

Expand All @@ -32,7 +31,6 @@ func generateOtlpResource1() otlpresource.Resource {
}

func initResource2(r pdata.Resource) {
r.InitEmpty()
initResourceAttributes2(r.Attributes())
}

Expand Down
1 change: 0 additions & 1 deletion internal/goldendataset/metric_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func (g *metricGenerator) genMetricDataFromCfg(cfg MetricCfg) pdata.Metrics {
for i := 0; i < cfg.NumResourceMetrics; i++ {
rm := rms.At(i)
resource := rm.Resource()
resource.InitEmpty()
for j := 0; j < cfg.NumResourceAttrs; j++ {
resource.Attributes().Insert(
fmt.Sprintf("resource-attr-name-%d", j),
Expand Down
2 changes: 1 addition & 1 deletion internal/processor/filterspan/filterspan.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (mp *propertiesMatcher) MatchSpan(span pdata.Span, resource pdata.Resource,

// serviceNameForResource gets the service name for a specified Resource.
func serviceNameForResource(resource pdata.Resource) string {
if resource.IsNil() {
if resource.IsEmpty() {
return "<nil-resource>"
}

Expand Down
28 changes: 27 additions & 1 deletion internal/processor/filterspan/filterspan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,33 @@ func TestSpan_Matching_False(t *testing.T) {
}
}

func resource(service string) pdata.Resource {
r := pdata.NewResource()
r.Attributes().InitFromMap(map[string]pdata.AttributeValue{conventions.AttributeServiceName: pdata.NewAttributeValueString(service)})
return r
}

func TestSpan_MatchingCornerCases(t *testing.T) {
cfg := &filterconfig.MatchProperties{
Config: *createConfig(filterset.Strict),
Services: []string{"svcA"},
Attributes: []filterconfig.Attribute{
{
Key: "keyOne",
Value: nil,
},
},
}

mp, err := NewMatcher(cfg)
assert.Nil(t, err)
assert.NotNil(t, mp)

emptySpan := pdata.NewSpan()
emptySpan.InitEmpty()
assert.False(t, mp.MatchSpan(emptySpan, resource("svcA"), pdata.NewInstrumentationLibrary()))
}

func TestSpan_MissingServiceName(t *testing.T) {
cfg := &filterconfig.MatchProperties{
Config: *createConfig(filterset.Regexp),
Expand Down Expand Up @@ -234,7 +261,6 @@ func TestSpan_Matching_True(t *testing.T) {
assert.NotNil(t, span)

resource := pdata.NewResource()
resource.InitEmpty()
resource.Attributes().InitFromMap(map[string]pdata.AttributeValue{
conventions.AttributeServiceName: pdata.NewAttributeValueString("svcA"),
})
Expand Down
3 changes: 1 addition & 2 deletions processor/attributesprocessor/attributes_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func generateLogData(logName string, attrs map[string]pdata.AttributeValue) pdat
td := pdata.NewLogs()
td.ResourceLogs().Resize(1)
rs := td.ResourceLogs().At(0)
rs.Resource().InitEmpty()
rs.InstrumentationLibraryLogs().Resize(1)
ils := rs.InstrumentationLibraryLogs().At(0)
lrs := ils.Logs()
Expand All @@ -70,7 +69,7 @@ func sortLogAttributes(ld pdata.Logs) {
if rs.IsNil() {
continue
}
if !rs.Resource().IsNil() {
if !rs.Resource().IsEmpty() {
rs.Resource().Attributes().Sort()
}
ilss := rss.At(i).InstrumentationLibraryLogs()
Expand Down
3 changes: 1 addition & 2 deletions processor/attributesprocessor/attributes_trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func generateTraceData(serviceName, spanName string, attrs map[string]pdata.Attr
td.ResourceSpans().Resize(1)
rs := td.ResourceSpans().At(0)
if serviceName != "" {
rs.Resource().InitEmpty()
rs.Resource().Attributes().UpsertString(conventions.AttributeServiceName, serviceName)
}
rs.InstrumentationLibrarySpans().Resize(1)
Expand All @@ -75,7 +74,7 @@ func sortAttributes(td pdata.Traces) {
if rs.IsNil() {
continue
}
if !rs.Resource().IsNil() {
if !rs.Resource().IsEmpty() {
rs.Resource().Attributes().Sort()
}
ilss := rss.At(i).InstrumentationLibrarySpans()
Expand Down
1 change: 0 additions & 1 deletion processor/filterprocessor/metric_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (idx metricIndex) extract(pdm pdata.Metrics) pdata.Metrics {
rmOut.InitEmpty()
rmSliceOut.Append(rmOut)
resourceOut := rmOut.Resource()
resourceOut.InitEmpty()
rmIn.Resource().CopyTo(resourceOut)
ilmSliceOut := rmOut.InstrumentationLibraryMetrics()
ilmIndexes := idx.m[rmIdx]
Expand Down
9 changes: 0 additions & 9 deletions processor/resourceprocessor/resource_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ func (rp *resourceProcessor) ProcessTraces(_ context.Context, td pdata.Traces) (
rss := td.ResourceSpans()
for i := 0; i < rss.Len(); i++ {
resource := rss.At(i).Resource()
if resource.IsNil() {
resource.InitEmpty()
}
attrs := resource.Attributes()
rp.attrProc.Process(attrs)
}
Expand All @@ -44,9 +41,6 @@ func (rp *resourceProcessor) ProcessMetrics(_ context.Context, md pdata.Metrics)
rms := md.ResourceMetrics()
for i := 0; i < rms.Len(); i++ {
resource := rms.At(i).Resource()
if resource.IsNil() {
resource.InitEmpty()
}
if resource.Attributes().Len() == 0 {
resource.Attributes().InitEmptyWithCapacity(1)
}
Expand All @@ -60,9 +54,6 @@ func (rp *resourceProcessor) ProcessLogs(_ context.Context, ld pdata.Logs) (pdat
rls := ld.ResourceLogs()
for i := 0; i < rls.Len(); i++ {
resource := rls.At(i).Resource()
if resource.IsNil() {
resource.InitEmpty()
}
attrs := resource.Attributes()
rp.attrProc.Process(attrs)
}
Expand Down
5 changes: 1 addition & 4 deletions processor/resourceprocessor/resource_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ func generateTraceData(attributes map[string]string) pdata.Traces {
return td
}
resource := td.ResourceSpans().At(0).Resource()
resource.InitEmpty()
for k, v := range attributes {
resource.Attributes().InsertString(k, v)
}
Expand All @@ -188,7 +187,6 @@ func generateMetricData(attributes map[string]string) pdata.Metrics {
return md
}
resource := md.ResourceMetrics().At(0).Resource()
resource.InitEmpty()
for k, v := range attributes {
resource.Attributes().InsertString(k, v)
}
Expand All @@ -202,7 +200,6 @@ func generateLogData(attributes map[string]string) pdata.Logs {
return ld
}
resource := ld.ResourceLogs().At(0).Resource()
resource.InitEmpty()
for k, v := range attributes {
resource.Attributes().InsertString(k, v)
}
Expand Down Expand Up @@ -250,7 +247,7 @@ func (tln *testLogsConsumer) ConsumeLogs(_ context.Context, ld pdata.Logs) error
}

func sortResourceAttributes(resource pdata.Resource) {
if resource.IsNil() {
if resource.IsEmpty() {
return
}
resource.Attributes().Sort()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func (tsp *tracesamplerprocessor) processTraces(ctx context.Context, resourceSpa

sampledTraceData.ResourceSpans().Resize(sampledTraceData.ResourceSpans().Len() + 1)
rs := sampledTraceData.ResourceSpans().At(sampledTraceData.ResourceSpans().Len() - 1)
rs.Resource().InitEmpty()
resourceSpans.Resource().CopyTo(rs.Resource())
rs.InstrumentationLibrarySpans().Resize(1)
spns := rs.InstrumentationLibrarySpans().At(0).Spans()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ func Test_tracesamplerprocessor_SpanSamplingPriority(t *testing.T) {
traces := pdata.NewTraces()
traces.ResourceSpans().Resize(1)
rs := traces.ResourceSpans().At(0)
rs.Resource().InitEmpty()
rs.InstrumentationLibrarySpans().Resize(1)
instrLibrarySpans := rs.InstrumentationLibrarySpans().At(0)
instrLibrarySpans.Spans().Append(getSpanWithAttributes(key, attribValue))
Expand Down Expand Up @@ -453,7 +452,6 @@ func genRandomTestData(numBatches, numTracesPerBatch int, serviceName string, re
traces.ResourceSpans().Resize(resourceSpanCount)
for j := 0; j < resourceSpanCount; j++ {
rs := traces.ResourceSpans().At(j)
rs.Resource().InitEmpty()
rs.Resource().Attributes().InsertString("service.name", serviceName)
rs.Resource().Attributes().InsertBool("bool", true)
rs.Resource().Attributes().InsertString("string", "yes")
Expand Down
3 changes: 1 addition & 2 deletions processor/spanprocessor/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func runIndividualTestCase(t *testing.T, tt testCase, tp component.TracesProcess
if rs.IsNil() {
continue
}
if !rs.Resource().IsNil() {
if !rs.Resource().IsEmpty() {
rs.Resource().Attributes().Sort()
}
ilss := rss.At(i).InstrumentationLibrarySpans()
Expand All @@ -95,7 +95,6 @@ func generateTraceData(serviceName, inputName string, attrs map[string]pdata.Att
td.ResourceSpans().Resize(1)
rs := td.ResourceSpans().At(0)
if serviceName != "" {
rs.Resource().InitEmpty()
rs.Resource().Attributes().UpsertString(conventions.AttributeServiceName, serviceName)
}
rs.InstrumentationLibrarySpans().Resize(1)
Expand Down
1 change: 0 additions & 1 deletion receiver/fluentforwardreceiver/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func collectLogRecords(events []Event) pdata.Logs {
logs.Resize(1)
rls := logs.At(0)

rls.Resource().InitEmpty()
rls.InstrumentationLibraryLogs().Resize(1)
logSlice := rls.InstrumentationLibraryLogs().At(0).Logs()

Expand Down
3 changes: 1 addition & 2 deletions receiver/hostmetricsreceiver/hostmetrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ func assertIncludesExpectedMetrics(t *testing.T, got pdata.Metrics) {
rm := rms.At(i)
metrics := getMetricSlice(t, rm)
returnedMetricNames := getReturnedMetricNames(metrics)

if rm.Resource().IsNil() || rm.Resource().Attributes().Len() == 0 {
if rm.Resource().Attributes().Len() == 0 {
appendMapInto(returnedMetrics, returnedMetricNames)
} else {
appendMapInto(returnedResourceMetrics, returnedMetricNames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type commandMetadata struct {
}

func (m *processMetadata) initializeResource(resource pdata.Resource) {
resource.InitEmpty()
attr := resource.Attributes()
attr.InitEmptyWithCapacity(6)
m.insertPid(attr)
Expand Down
1 change: 0 additions & 1 deletion receiver/jaegerreceiver/jaeger_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ func newClientUDP(hostPort string, binary bool) (*agent.AgentClient, error) {
func generateTraceData() pdata.Traces {
td := pdata.NewTraces()
td.ResourceSpans().Resize(1)
td.ResourceSpans().At(0).Resource().InitEmpty()
td.ResourceSpans().At(0).Resource().Attributes().UpsertString(conventions.AttributeServiceName, "test")
td.ResourceSpans().At(0).InstrumentationLibrarySpans().Resize(1)
td.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).Spans().Resize(1)
Expand Down
1 change: 0 additions & 1 deletion receiver/jaegerreceiver/trace_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ func expectedTraceData(t1, t2, t3 time.Time) pdata.Traces {
traces := pdata.NewTraces()
traces.ResourceSpans().Resize(1)
rs := traces.ResourceSpans().At(0)
rs.Resource().InitEmpty()
rs.Resource().Attributes().InsertString(conventions.AttributeServiceName, "issaTest")
rs.Resource().Attributes().InsertBool("bool", true)
rs.Resource().Attributes().InsertString("string", "yes")
Expand Down
1 change: 0 additions & 1 deletion receiver/kafkareceiver/otlp_unmarshaller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
func TestUnmarshallOTLP(t *testing.T) {
td := pdata.NewTraces()
td.ResourceSpans().Resize(1)
td.ResourceSpans().At(0).Resource().InitEmpty()
td.ResourceSpans().At(0).Resource().Attributes().InsertString("foo", "bar")
request := &otlptrace.ExportTraceServiceRequest{
ResourceSpans: pdata.TracesToOtlp(td),
Expand Down
1 change: 0 additions & 1 deletion receiver/kafkareceiver/zipkin_unmarshaller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
func TestUnmarshallZipkin(t *testing.T) {
td := pdata.NewTraces()
td.ResourceSpans().Resize(1)
td.ResourceSpans().At(0).Resource().InitEmpty()
td.ResourceSpans().At(0).Resource().Attributes().InitFromMap(
map[string]pdata.AttributeValue{conventions.AttributeServiceName: pdata.NewAttributeValueString("my_service")})
td.ResourceSpans().At(0).InstrumentationLibrarySpans().Resize(1)
Expand Down
1 change: 0 additions & 1 deletion testutil/logstest/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func Logs(recs ...Log) pdata.Logs {
logs.Resize(1)
rls := logs.At(0)

rls.Resource().InitEmpty()
rls.InstrumentationLibraryLogs().Resize(1)
logSlice := rls.InstrumentationLibraryLogs().At(0).Logs()

Expand Down
1 change: 0 additions & 1 deletion translator/internaldata/oc_testdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ func generateOCTestMetricDoubleSummary() *ocmetrics.Metric {

func generateResourceWithOcNodeAndResource() pdata.Resource {
resource := pdata.NewResource()
resource.InitEmpty()
resource.Attributes().InitFromMap(map[string]pdata.AttributeValue{
conventions.OCAttributeProcessStartTime: pdata.NewAttributeValueString("2020-02-11T20:26:00Z"),
conventions.AttributeHostHostname: pdata.NewAttributeValueString("host1"),
Expand Down
8 changes: 1 addition & 7 deletions translator/internaldata/oc_to_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestOCToMetrics(t *testing.T) {
Node: &occommon.Node{},
Resource: &ocresource.Resource{},
},
internal: wrapMetricsWithEmptyResource(testdata.GenerateMetricsOneEmptyResourceMetrics()),
internal: testdata.GenerateMetricsOneEmptyResourceMetrics(),
},

{
Expand Down Expand Up @@ -158,12 +158,6 @@ func TestOCToMetrics(t *testing.T) {
}
}

// TODO: Try to avoid unnecessary Resource object allocation.
func wrapMetricsWithEmptyResource(md pdata.Metrics) pdata.Metrics {
md.ResourceMetrics().At(0).Resource().InitEmpty()
return md
}

func TestOCToMetrics_ResourceInMetric(t *testing.T) {
internal := testdata.GenerateMetricsOneMetric()
want := pdata.NewMetrics()
Expand Down
2 changes: 0 additions & 2 deletions translator/internaldata/oc_to_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ func ocNodeResourceToInternal(ocNode *occommon.Node, ocResource *ocresource.Reso
return
}

dest.InitEmpty()

// Number of special fields in OC that will be translated to Attributes
const serviceInfoAttrCount = 1 // Number of Node.ServiceInfo fields.
const nodeIdentifierAttrCount = 3 // Number of Node.Identifier fields.
Expand Down
Loading

0 comments on commit 5cfe530

Please sign in to comment.