Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exporter and receiver/signalfx] Remove LogRecord Name field usage #7553

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions exporter/signalfxexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ func makeSampleResourceLogs() pdata.Logs {
out := pdata.NewLogs()
l := out.ResourceLogs().AppendEmpty().InstrumentationLibraryLogs().AppendEmpty().LogRecords().AppendEmpty()

l.SetName("shutdown")
l.SetTimestamp(pdata.Timestamp(1000))
attrs := l.Attributes()

Expand All @@ -490,6 +489,7 @@ func makeSampleResourceLogs() pdata.Logs {
propMap.Sort()
attrs.Insert("com.splunk.signalfx.event_properties", propMapVal)
attrs.Insert("com.splunk.signalfx.event_category", pdata.NewAttributeValueInt(int64(sfxpb.EventCategory_USER_DEFINED)))
attrs.Insert("com.splunk.signalfx.event_type", pdata.NewAttributeValueString("shutdown"))

l.Attributes().Sort()

Expand All @@ -515,7 +515,9 @@ func TestConsumeEventData(t *testing.T) {
name: "no_event_attribute",
resourceLogs: func() pdata.Logs {
out := makeSampleResourceLogs()
out.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).Attributes().Delete("com.splunk.signalfx.event_category")
attrs := out.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).Attributes()
attrs.Delete("com.splunk.signalfx.event_category")
attrs.Delete("com.splunk.signalfx.event_type")
return out
}(),
reqTestFunc: nil,
Expand Down Expand Up @@ -713,7 +715,6 @@ func generateLargeEventBatch() pdata.Logs {
ts := time.Now()
for i := 0; i < batchSize; i++ {
lr := logs.AppendEmpty()
lr.SetName("test_" + strconv.Itoa(i))
lr.Attributes().InsertString("k0", "k1")
lr.Attributes().InsertNull("com.splunk.signalfx.event_category")
lr.SetTimestamp(pdata.NewTimestampFromTime(ts))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ func convertLogRecord(lr pdata.LogRecord, resourceAttrs pdata.AttributeMap, logg

addDimension := func(k string, v pdata.AttributeValue) bool {
// Skip internal attributes
if k == splunk.SFxEventCategoryKey || k == splunk.SFxEventPropertiesKey {
switch k {
case splunk.SFxEventCategoryKey:
return true
case splunk.SFxEventPropertiesKey:
return true
case splunk.SFxEventType:
if v.Type() == pdata.AttributeValueTypeString {
event.EventType = v.StringVal()
}
return true
}

Expand All @@ -108,7 +116,6 @@ func convertLogRecord(lr pdata.LogRecord, resourceAttrs pdata.AttributeMap, logg
resourceAttrsForDimensions.Range(addDimension)
attrs.Range(addDimension)

event.EventType = lr.Name()
// Convert nanoseconds to nearest milliseconds, which is the unit of
// SignalFx event timestamps.
event.Timestamp = int64(lr.Timestamp()) / 1e6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func TestLogDataToSignalFxEvents(t *testing.T) {
logSlice := ilLogs.AppendEmpty().LogRecords()

l := logSlice.AppendEmpty()
l.SetName("shutdown")
l.SetTimestamp(pdata.NewTimestampFromTime(now.Truncate(time.Millisecond)))
attrs := l.Attributes()

Expand All @@ -80,6 +79,7 @@ func TestLogDataToSignalFxEvents(t *testing.T) {
propMap.Sort()
attrs.Insert("com.splunk.signalfx.event_properties", propMapVal)
attrs.Insert("com.splunk.signalfx.event_category", pdata.NewAttributeValueInt(int64(sfxpb.EventCategory_USER_DEFINED)))
attrs.Insert("com.splunk.signalfx.event_type", pdata.NewAttributeValueString("shutdown"))

l.Attributes().Sort()

Expand Down
1 change: 1 addition & 0 deletions internal/splunk/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
SFxAccessTokenLabel = "com.splunk.signalfx.access_token" // #nosec
SFxEventCategoryKey = "com.splunk.signalfx.event_category"
SFxEventPropertiesKey = "com.splunk.signalfx.event_properties"
SFxEventType = "com.splunk.signalfx.event_type"
DefaultSourceTypeLabel = "com.splunk.sourcetype"
DefaultSourceLabel = "com.splunk.source"
DefaultIndexLabel = "com.splunk.index"
Expand Down
14 changes: 8 additions & 6 deletions receiver/signalfxreceiver/signalfxv2_event_to_logdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@ func signalFxV2EventsToLogRecords(events []*sfxpb.Event, lrs pdata.LogRecordSlic
for _, event := range events {
lr := lrs.AppendEmpty()

// The EventType field is the most logical "name" of the event.
lr.SetName(event.EventType)
attrs := lr.Attributes()
attrs.Clear()
attrs.EnsureCapacity(2 + len(event.Dimensions) + len(event.Properties))

// The EventType field is stored as an attribute.
if event.EventType != "" {
attrs.InsertString(splunk.SFxEventType, event.EventType)
}

// SignalFx timestamps are in millis so convert to nanos by multiplying
// by 1 million.
lr.SetTimestamp(pdata.Timestamp(event.Timestamp * 1e6))

attrs := lr.Attributes()
attrs.Clear()
attrs.EnsureCapacity(1 + len(event.Dimensions) + len(event.Properties))

if event.Category != nil {
attrs.InsertInt(splunk.SFxEventCategoryKey, int64(*event.Category))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ func TestSignalFxV2EventsToLogData(t *testing.T) {
buildDefaultLogs := func() pdata.LogRecordSlice {
logSlice := pdata.NewLogRecordSlice()
l := logSlice.AppendEmpty()
l.SetName("shutdown")
l.SetTimestamp(pdata.NewTimestampFromTime(now.Truncate(time.Millisecond)))
attrs := l.Attributes()
attrs.InsertString("com.splunk.signalfx.event_type", "shutdown")
attrs.InsertString("k0", "v0")
attrs.InsertString("k1", "v1")
attrs.InsertString("k2", "v2")
Expand Down