Skip to content

Commit

Permalink
Fix more 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 4, 2020
1 parent 6623b18 commit 77a995e
Show file tree
Hide file tree
Showing 28 changed files with 57 additions and 189 deletions.
2 changes: 0 additions & 2 deletions cmd/pdatagen/internal/base_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ func (ms ${structName}) ${fieldName}() ${returnType} {
const accessorsMessageValueTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) {
ms := New${structName}()
ms.InitEmpty()
assert.True(t, ms.${fieldName}().IsEmpty())
fillTest${returnType}(ms.${fieldName}())
assert.False(t, ms.${fieldName}().IsEmpty())
assert.EqualValues(t, generateTest${returnType}(), ms.${fieldName}())
}`

Expand Down
40 changes: 3 additions & 37 deletions cmd/pdatagen/internal/base_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,35 +378,21 @@ func (ms ${structName}) InitEmpty() {
*ms.orig = ${originName}{}
}
// Deprecated: Use IsEmpty instead
// Deprecated: This function will be removed soon.
func (ms ${structName}) IsNil() bool {
return ms.IsEmpty()
return false
}`

const messageValueIsEmptyHeaderTemplate = `// IsEmpty returns true if the underlying data are equivalent with an empty message.
func (ms ${structName}) IsEmpty() bool {
return `

const messageValueIsEmptyFooterTemplate = `}`

const messageValueCopyToHeaderTemplate = `// CopyTo copies all properties from the current struct to the dest.
func (ms ${structName}) CopyTo(dest ${structName}) {
if ms.IsEmpty() {
*dest.orig = emptyValue${structName}
return
}`
func (ms ${structName}) CopyTo(dest ${structName}) {`

const messageValueCopyToFooterTemplate = `}`

const messageValueTestTemplate = `
func Test${structName}_CopyTo(t *testing.T) {
ms := New${structName}()
assert.True(t, ms.IsEmpty())
New${structName}().CopyTo(ms)
assert.True(t, ms.IsEmpty())
generateTest${structName}().CopyTo(ms)
assert.EqualValues(t, generateTest${structName}(), ms)
assert.False(t, ms.IsEmpty())
}`

const messageValueGenerateTestTemplate = `func generateTest${structName}() ${structName} {
Expand Down Expand Up @@ -613,26 +599,6 @@ func (ms *messageValueStruct) generateStruct(sb *strings.Builder) {
f.generateAccessors(ms, sb)
}
sb.WriteString(newLine + newLine)
sb.WriteString(os.Expand(messageValueIsEmptyHeaderTemplate, func(name string) string {
switch name {
case "structName":
return ms.structName
default:
panic(name)
}
}))
// Write accessors IsEmpty for the struct
for i, f := range ms.fields {
f.generateIsEmpty(sb)
if i != len(ms.fields)-1 {
sb.WriteString(" ||")
}
}
sb.WriteString(newLine)
sb.WriteString(os.Expand(messageValueIsEmptyFooterTemplate, func(name string) string {
panic(name)
}))
sb.WriteString(newLine + newLine)
sb.WriteString(os.Expand(messageValueCopyToHeaderTemplate, func(name string) string {
switch name {
case "structName":
Expand Down
2 changes: 0 additions & 2 deletions consumer/pdata/generated_log_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions consumer/pdata/generated_metrics_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 2 additions & 11 deletions consumer/pdata/generated_resource.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions consumer/pdata/generated_resource_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions consumer/pdata/generated_trace_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion consumer/simple/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ func (mb *Metrics) getMetricsSlice() pdata.MetricSlice {
rm.InitEmpty()

res := rm.Resource()
res.InitEmpty()
for k, v := range mb.ResourceAttributes {
res.Attributes().Insert(k, pdata.NewAttributeValueString(v))
}
Expand Down
1 change: 0 additions & 1 deletion consumer/simple/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ func BenchmarkPdataMetrics(b *testing.B) {
rm.InitEmpty()

res := rm.Resource()
res.InitEmpty()
resAttrs := res.Attributes()
resAttrs.Insert("host", pdata.NewAttributeValueString("my-host"))
resAttrs.Insert("serviceName", pdata.NewAttributeValueString("app"))
Expand Down
13 changes: 3 additions & 10 deletions exporter/loggingexporter/logging_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ func (s *loggingExporter) pushTraceData(
buf.logEntry("* Nil ResourceSpans")
continue
}
if !rs.Resource().IsEmpty() {
buf.logAttributeMap("Resource labels", rs.Resource().Attributes())
}
buf.logAttributeMap("Resource labels", rs.Resource().Attributes())
ilss := rs.InstrumentationLibrarySpans()
for j := 0; j < ilss.Len(); j++ {
buf.logEntry("InstrumentationLibrarySpans #%d", j)
Expand Down Expand Up @@ -391,9 +389,7 @@ func (s *loggingExporter) pushMetricsData(
buf.logEntry("* Nil ResourceMetrics")
continue
}
if !rm.Resource().IsEmpty() {
buf.logAttributeMap("Resource labels", rm.Resource().Attributes())
}
buf.logAttributeMap("Resource labels", rm.Resource().Attributes())
ilms := rm.InstrumentationLibraryMetrics()
for j := 0; j < ilms.Len(); j++ {
buf.logEntry("InstrumentationLibraryMetrics #%d", j)
Expand Down Expand Up @@ -504,10 +500,7 @@ func (s *loggingExporter) pushLogData(
buf.logEntry("* Nil ResourceLog")
continue
}
if !rl.Resource().IsEmpty() {
buf.logAttributeMap("Resource labels", rl.Resource().Attributes())
}

buf.logAttributeMap("Resource labels", rl.Resource().Attributes())
ills := rl.InstrumentationLibraryLogs()
for j := 0; j < ills.Len(); j++ {
buf.logEntry("InstrumentationLibraryLogs #%d", j)
Expand Down
2 changes: 0 additions & 2 deletions internal/processor/filtermatcher/filtermatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ func Test_Matching_True(t *testing.T) {
})

resource := pdata.NewResource()
resource.InitEmpty()
resource.Attributes().InitFromMap(map[string]pdata.AttributeValue{
conventions.AttributeServiceName: pdata.NewAttributeValueString("svcA"),
"resString": pdata.NewAttributeValueString("arithmetic"),
Expand All @@ -392,7 +391,6 @@ func Test_Matching_True(t *testing.T) {

func resource(service string) pdata.Resource {
r := pdata.NewResource()
r.InitEmpty()
r.Attributes().InitFromMap(map[string]pdata.AttributeValue{conventions.AttributeServiceName: pdata.NewAttributeValueString(service)})
return r
}
4 changes: 0 additions & 4 deletions internal/processor/filterspan/filterspan.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ 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.IsEmpty() {
return "<nil-resource>"
}

service, found := resource.Attributes().Get(conventions.AttributeServiceName)
if !found {
return "<nil-service-name>"
Expand Down
29 changes: 1 addition & 28 deletions internal/processor/filterspan/filterspan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,33 +162,6 @@ 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 @@ -280,7 +253,7 @@ func TestSpan_Matching_True(t *testing.T) {

func TestServiceNameForResource(t *testing.T) {
td := testdata.GenerateTraceDataOneSpanNoResource()
require.Equal(t, serviceNameForResource(td.ResourceSpans().At(0).Resource()), "<nil-resource>")
require.Equal(t, serviceNameForResource(td.ResourceSpans().At(0).Resource()), "<nil-service-name>")

td = testdata.GenerateTraceDataOneSpan()
resource := td.ResourceSpans().At(0).Resource()
Expand Down
4 changes: 1 addition & 3 deletions processor/attributesprocessor/attributes_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ func sortLogAttributes(ld pdata.Logs) {
if rs.IsNil() {
continue
}
if !rs.Resource().IsEmpty() {
rs.Resource().Attributes().Sort()
}
rs.Resource().Attributes().Sort()
ilss := rss.At(i).InstrumentationLibraryLogs()
for j := 0; j < ilss.Len(); j++ {
ils := ilss.At(j)
Expand Down
4 changes: 1 addition & 3 deletions processor/attributesprocessor/attributes_trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ func sortAttributes(td pdata.Traces) {
if rs.IsNil() {
continue
}
if !rs.Resource().IsEmpty() {
rs.Resource().Attributes().Sort()
}
rs.Resource().Attributes().Sort()
ilss := rss.At(i).InstrumentationLibrarySpans()
for j := 0; j < ilss.Len(); j++ {
ils := ilss.At(j)
Expand Down
13 changes: 3 additions & 10 deletions processor/resourceprocessor/resource_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ type testTraceConsumer struct {
func (ttn *testTraceConsumer) ConsumeTraces(_ context.Context, td pdata.Traces) error {
// sort attributes to be able to compare traces
for i := 0; i < td.ResourceSpans().Len(); i++ {
sortResourceAttributes(td.ResourceSpans().At(i).Resource())
td.ResourceSpans().At(i).Resource().Attributes().Sort()
}
ttn.td = td
return nil
Expand All @@ -227,7 +227,7 @@ type testMetricsConsumer struct {
func (tmn *testMetricsConsumer) ConsumeMetrics(_ context.Context, md pdata.Metrics) error {
// sort attributes to be able to compare traces
for i := 0; i < md.ResourceMetrics().Len(); i++ {
sortResourceAttributes(md.ResourceMetrics().At(i).Resource())
md.ResourceMetrics().At(i).Resource().Attributes().Sort()
}
tmn.md = md
return nil
Expand All @@ -240,15 +240,8 @@ type testLogsConsumer struct {
func (tln *testLogsConsumer) ConsumeLogs(_ context.Context, ld pdata.Logs) error {
// sort attributes to be able to compare traces
for i := 0; i < ld.ResourceLogs().Len(); i++ {
sortResourceAttributes(ld.ResourceLogs().At(i).Resource())
ld.ResourceLogs().At(i).Resource().Attributes().Sort()
}
tln.ld = ld
return nil
}

func sortResourceAttributes(resource pdata.Resource) {
if resource.IsEmpty() {
return
}
resource.Attributes().Sort()
}
4 changes: 1 addition & 3 deletions processor/spanprocessor/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ func runIndividualTestCase(t *testing.T, tt testCase, tp component.TracesProcess
if rs.IsNil() {
continue
}
if !rs.Resource().IsEmpty() {
rs.Resource().Attributes().Sort()
}
rs.Resource().Attributes().Sort()
ilss := rss.At(i).InstrumentationLibrarySpans()
for j := 0; j < ilss.Len(); j++ {
ils := ilss.At(j)
Expand Down
1 change: 0 additions & 1 deletion testbed/tests/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ func verifySingleSpan(
// Send one span.
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(serviceName),
})
Expand Down
4 changes: 2 additions & 2 deletions translator/internaldata/oc_to_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ import (
func TestOcNodeResourceToInternal(t *testing.T) {
resource := pdata.NewResource()
ocNodeResourceToInternal(nil, nil, resource)
assert.True(t, resource.IsEmpty())
assert.Equal(t, 0, resource.Attributes().Len())

ocNode := &occommon.Node{}
ocResource := &ocresource.Resource{}
ocNodeResourceToInternal(ocNode, ocResource, resource)
assert.True(t, resource.IsEmpty())
assert.Equal(t, 0, resource.Attributes().Len())

ocNode = generateOcNode()
ocResource = generateOcResource()
Expand Down
9 changes: 2 additions & 7 deletions translator/internaldata/resource_to_oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,13 @@ func getSDKLangToOCLangCodeMap() map[string]int32 {
}

func internalResourceToOC(resource pdata.Resource) (*occommon.Node, *ocresource.Resource) {
if resource.IsEmpty() {
attrs := resource.Attributes()
if attrs.Len() == 0 {
return nil, nil
}
attrs := resource.Attributes()

ocNode := occommon.Node{}
ocResource := ocresource.Resource{}

if attrs.Len() == 0 {
return &ocNode, &ocResource
}

labels := make(map[string]string, attrs.Len())
attrs.ForEach(func(k string, v pdata.AttributeValue) {
val := tracetranslator.AttributeValueToString(v, false)
Expand Down
Loading

0 comments on commit 77a995e

Please sign in to comment.