Skip to content

Commit

Permalink
Remove test only code, avoid unsing proto and InternalRep in testdata (
Browse files Browse the repository at this point in the history
…#3387)

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Jun 14, 2021
1 parent 0e5784c commit 27df57b
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 1,030 deletions.
100 changes: 0 additions & 100 deletions internal/testdata/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package testdata

import (
otlpcommon "go.opentelemetry.io/collector/internal/data/protogen/common/v1"

"go.opentelemetry.io/collector/consumer/pdata"
)

Expand All @@ -43,136 +41,38 @@ func initResourceAttributes1(dest pdata.AttributeMap) {
dest.InitFromMap(resourceAttributes1)
}

func generateOtlpResourceAttributes1() []otlpcommon.KeyValue {
return []otlpcommon.KeyValue{
{
Key: "resource-attr",
Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "resource-attr-val-1"}},
},
}
}

func initResourceAttributes2(dest pdata.AttributeMap) {
dest.InitFromMap(resourceAttributes2)
}

func generateOtlpResourceAttributes2() []otlpcommon.KeyValue {
return []otlpcommon.KeyValue{
{
Key: "resource-attr",
Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "resource-attr-val-2"}},
},
}
}

func initSpanAttributes(dest pdata.AttributeMap) {
dest.InitFromMap(spanAttributes)
}

func generateOtlpSpanAttributes() []otlpcommon.KeyValue {
return []otlpcommon.KeyValue{
{
Key: "span-attr",
Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "span-attr-val"}},
},
}
}

func initSpanEventAttributes(dest pdata.AttributeMap) {
dest.InitFromMap(spanEventAttributes)
}

func generateOtlpSpanEventAttributes() []otlpcommon.KeyValue {
return []otlpcommon.KeyValue{
{
Key: "span-event-attr",
Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "span-event-attr-val"}},
},
}
}

func initSpanLinkAttributes(dest pdata.AttributeMap) {
dest.InitFromMap(spanLinkAttributes)
}

func generateOtlpSpanLinkAttributes() []otlpcommon.KeyValue {
return []otlpcommon.KeyValue{
{
Key: "span-link-attr",
Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "span-link-attr-val"}},
},
}
}

func initMetricLabels1(dest pdata.StringMap) {
dest.InitFromMap(map[string]string{TestLabelKey1: TestLabelValue1})
}

func generateOtlpMetricLabels1() []otlpcommon.StringKeyValue {
return []otlpcommon.StringKeyValue{
{
Key: TestLabelKey1,
Value: TestLabelValue1,
},
}
}

func initMetricLabels12(dest pdata.StringMap) {
dest.InitFromMap(map[string]string{TestLabelKey1: TestLabelValue1, TestLabelKey2: TestLabelValue2}).Sort()
}

func generateOtlpMetricLabels12() []otlpcommon.StringKeyValue {
return []otlpcommon.StringKeyValue{
{
Key: TestLabelKey1,
Value: TestLabelValue1,
},
{
Key: TestLabelKey2,
Value: TestLabelValue2,
},
}
}

func initMetricLabels13(dest pdata.StringMap) {
dest.InitFromMap(map[string]string{TestLabelKey1: TestLabelValue1, TestLabelKey3: TestLabelValue3}).Sort()
}

func generateOtlpMetricLabels13() []otlpcommon.StringKeyValue {
return []otlpcommon.StringKeyValue{
{
Key: TestLabelKey1,
Value: TestLabelValue1,
},
{
Key: TestLabelKey3,
Value: TestLabelValue3,
},
}
}

func initMetricLabels2(dest pdata.StringMap) {
dest.InitFromMap(map[string]string{TestLabelKey2: TestLabelValue2})
}

func generateOtlpMetricLabels2() []otlpcommon.StringKeyValue {
return []otlpcommon.StringKeyValue{
{
Key: TestLabelKey2,
Value: TestLabelValue2,
},
}
}

func initMetricAttachment(dest pdata.StringMap) {
dest.InitFromMap(map[string]string{TestAttachmentKey: TestAttachmentValue})
}

func generateOtlpMetricAttachment() []otlpcommon.StringKeyValue {
return []otlpcommon.StringKeyValue{
{
Key: TestAttachmentKey,
Value: TestAttachmentValue,
},
}
}
174 changes: 0 additions & 174 deletions internal/testdata/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import (
"time"

"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/internal/data"
otlpcollectorlog "go.opentelemetry.io/collector/internal/data/protogen/collector/logs/v1"
otlpcommon "go.opentelemetry.io/collector/internal/data/protogen/common/v1"
otlplogs "go.opentelemetry.io/collector/internal/data/protogen/logs/v1"
)

var (
Expand All @@ -35,100 +31,32 @@ func GenerateLogsOneEmptyResourceLogs() pdata.Logs {
return ld
}

func generateLogsOtlpOneEmptyResourceLogs() *otlpcollectorlog.ExportLogsServiceRequest {
return &otlpcollectorlog.ExportLogsServiceRequest{
ResourceLogs: []*otlplogs.ResourceLogs{
{},
},
}
}

func GenerateLogsNoLogRecords() pdata.Logs {
ld := GenerateLogsOneEmptyResourceLogs()
initResource1(ld.ResourceLogs().At(0).Resource())
return ld
}

func generateLogOtlpNoLogRecords() *otlpcollectorlog.ExportLogsServiceRequest {
return &otlpcollectorlog.ExportLogsServiceRequest{
ResourceLogs: []*otlplogs.ResourceLogs{
{
Resource: generateOtlpResource1(),
},
},
}
}

func GenerateLogsOneEmptyLogRecord() pdata.Logs {
ld := GenerateLogsNoLogRecords()
rs0 := ld.ResourceLogs().At(0)
rs0.InstrumentationLibraryLogs().AppendEmpty().Logs().AppendEmpty()
return ld
}

func generateLogsOtlpOneEmptyLogRecord() *otlpcollectorlog.ExportLogsServiceRequest {
return &otlpcollectorlog.ExportLogsServiceRequest{
ResourceLogs: []*otlplogs.ResourceLogs{
{
Resource: generateOtlpResource1(),
InstrumentationLibraryLogs: []*otlplogs.InstrumentationLibraryLogs{
{
Logs: []*otlplogs.LogRecord{
{},
},
},
},
},
},
}
}

func GenerateLogsOneLogRecordNoResource() pdata.Logs {
ld := GenerateLogsOneEmptyResourceLogs()
rs0 := ld.ResourceLogs().At(0)
fillLogOne(rs0.InstrumentationLibraryLogs().AppendEmpty().Logs().AppendEmpty())
return ld
}

func generateLogsOtlpOneLogRecordNoResource() *otlpcollectorlog.ExportLogsServiceRequest {
return &otlpcollectorlog.ExportLogsServiceRequest{
ResourceLogs: []*otlplogs.ResourceLogs{
{
InstrumentationLibraryLogs: []*otlplogs.InstrumentationLibraryLogs{
{
Logs: []*otlplogs.LogRecord{
generateOtlpLogOne(),
},
},
},
},
},
}
}

func GenerateLogsOneLogRecord() pdata.Logs {
ld := GenerateLogsOneEmptyLogRecord()
fillLogOne(ld.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).Logs().At(0))
return ld
}

func generateLogsOtlpOneLogRecord() *otlpcollectorlog.ExportLogsServiceRequest {
return &otlpcollectorlog.ExportLogsServiceRequest{
ResourceLogs: []*otlplogs.ResourceLogs{
{
Resource: generateOtlpResource1(),
InstrumentationLibraryLogs: []*otlplogs.InstrumentationLibraryLogs{
{
Logs: []*otlplogs.LogRecord{
generateOtlpLogOne(),
},
},
},
},
},
}
}

func GenerateLogsTwoLogRecordsSameResource() pdata.Logs {
ld := GenerateLogsOneEmptyLogRecord()
logs := ld.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).Logs()
Expand All @@ -137,24 +65,6 @@ func GenerateLogsTwoLogRecordsSameResource() pdata.Logs {
return ld
}

func generateLogsOtlpTwoLogRecordsSameResource() *otlpcollectorlog.ExportLogsServiceRequest {
return &otlpcollectorlog.ExportLogsServiceRequest{
ResourceLogs: []*otlplogs.ResourceLogs{
{
Resource: generateOtlpResource1(),
InstrumentationLibraryLogs: []*otlplogs.InstrumentationLibraryLogs{
{
Logs: []*otlplogs.LogRecord{
generateOtlpLogOne(),
generateOtlpLogTwo(),
},
},
},
},
},
}
}

func GenerateLogsTwoLogRecordsSameResourceOneDifferent() pdata.Logs {
ld := pdata.NewLogs()
rl0 := ld.ResourceLogs().AppendEmpty()
Expand All @@ -167,35 +77,6 @@ func GenerateLogsTwoLogRecordsSameResourceOneDifferent() pdata.Logs {
fillLogThree(rl1.InstrumentationLibraryLogs().AppendEmpty().Logs().AppendEmpty())
return ld
}

func generateLogsOtlpTwoLogRecordsSameResourceOneDifferent() *otlpcollectorlog.ExportLogsServiceRequest {
return &otlpcollectorlog.ExportLogsServiceRequest{
ResourceLogs: []*otlplogs.ResourceLogs{
{
Resource: generateOtlpResource1(),
InstrumentationLibraryLogs: []*otlplogs.InstrumentationLibraryLogs{
{
Logs: []*otlplogs.LogRecord{
generateOtlpLogOne(),
generateOtlpLogTwo(),
},
},
},
},
{
Resource: generateOtlpResource2(),
InstrumentationLibraryLogs: []*otlplogs.InstrumentationLibraryLogs{
{
Logs: []*otlplogs.LogRecord{
generateOtlpLogThree(),
},
},
},
},
},
}
}

func fillLogOne(log pdata.LogRecord) {
log.SetName("logA")
log.SetTimestamp(TestLogTimestamp)
Expand All @@ -212,29 +93,6 @@ func fillLogOne(log pdata.LogRecord) {
log.Body().SetStringVal("This is a log message")
}

func generateOtlpLogOne() *otlplogs.LogRecord {
return &otlplogs.LogRecord{
Name: "logA",
TimeUnixNano: uint64(TestLogTimestamp),
DroppedAttributesCount: 1,
SeverityNumber: otlplogs.SeverityNumber_SEVERITY_NUMBER_INFO,
SeverityText: "Info",
Body: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "This is a log message"}},
SpanId: data.NewSpanID([8]byte{0x01, 0x02, 0x04, 0x08}),
TraceId: data.NewTraceID([16]byte{0x08, 0x04, 0x02, 0x01}),
Attributes: []otlpcommon.KeyValue{
{
Key: "app",
Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "server"}},
},
{
Key: "instance_num",
Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{IntValue: 1}},
},
},
}
}

func fillLogTwo(log pdata.LogRecord) {
log.SetName("logB")
log.SetTimestamp(TestLogTimestamp)
Expand All @@ -249,27 +107,6 @@ func fillLogTwo(log pdata.LogRecord) {
log.Body().SetStringVal("something happened")
}

func generateOtlpLogTwo() *otlplogs.LogRecord {
return &otlplogs.LogRecord{
Name: "logB",
TimeUnixNano: uint64(TestLogTimestamp),
DroppedAttributesCount: 1,
SeverityNumber: otlplogs.SeverityNumber_SEVERITY_NUMBER_INFO,
SeverityText: "Info",
Body: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "something happened"}},
Attributes: []otlpcommon.KeyValue{
{
Key: "customer",
Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "acme"}},
},
{
Key: "env",
Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "dev"}},
},
},
}
}

func fillLogThree(log pdata.LogRecord) {
log.SetName("logC")
log.SetTimestamp(TestLogTimestamp)
Expand All @@ -280,17 +117,6 @@ func fillLogThree(log pdata.LogRecord) {
log.Body().SetStringVal("something else happened")
}

func generateOtlpLogThree() *otlplogs.LogRecord {
return &otlplogs.LogRecord{
Name: "logC",
TimeUnixNano: uint64(TestLogTimestamp),
DroppedAttributesCount: 1,
SeverityNumber: otlplogs.SeverityNumber_SEVERITY_NUMBER_WARN,
SeverityText: "Warning",
Body: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "something else happened"}},
}
}

func GenerateLogsManyLogRecordsSameResource(count int) pdata.Logs {
ld := GenerateLogsOneEmptyLogRecord()
logs := ld.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).Logs()
Expand Down
Loading

0 comments on commit 27df57b

Please sign in to comment.