Skip to content

Commit

Permalink
[exporter/splunkhec] Remove duplication of host.name attribute (#6527)
Browse files Browse the repository at this point in the history
The duplication used to be needed for Splunk Observability to support related contend links. Now it's not needed anymore. Proper attribute conversion was added in Splunk Observability backend
  • Loading branch information
dmitryax authored Dec 8, 2021
1 parent 9eb82f6 commit a38f067
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 69 deletions.
88 changes: 45 additions & 43 deletions exporter/splunkhecexporter/client_test.go

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions exporter/splunkhecexporter/logdata_to_splunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"time"

"go.opentelemetry.io/collector/model/pdata"
conventions "go.opentelemetry.io/collector/model/semconv/v1.5.0"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
Expand Down Expand Up @@ -75,7 +74,6 @@ func mapLogRecordToSplunkEvent(res pdata.Resource, lr pdata.LogRecord, config *C
switch k {
case hostKey:
host = v.StringVal()
fields[conventions.AttributeHostName] = v.StringVal()
case sourceKey:
source = v.StringVal()
case sourceTypeKey:
Expand All @@ -93,7 +91,6 @@ func mapLogRecordToSplunkEvent(res pdata.Resource, lr pdata.LogRecord, config *C
switch k {
case hostKey:
host = v.StringVal()
fields[conventions.AttributeHostName] = v.StringVal()
case sourceKey:
source = v.StringVal()
case sourceTypeKey:
Expand Down
24 changes: 12 additions & 12 deletions exporter/splunkhecexporter/logdata_to_splunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Test_mapLogRecordToSplunkEvent(t *testing.T) {
return config
},
wantSplunkEvents: []*splunk.Event{
commonLogSplunkEvent("mylog", ts, map[string]interface{}{"custom": "custom", "host.name": "myhost"},
commonLogSplunkEvent("mylog", ts, map[string]interface{}{"custom": "custom"},
"myhost", "myapp", "myapp-type"),
},
},
Expand All @@ -81,7 +81,7 @@ func Test_mapLogRecordToSplunkEvent(t *testing.T) {
return config
},
wantSplunkEvents: []*splunk.Event{
commonLogSplunkEvent("mylog", ts, map[string]interface{}{"custom": "custom", "host.name": "myhost", "otel.log.name": "my very own name"},
commonLogSplunkEvent("mylog", ts, map[string]interface{}{"custom": "custom", "otel.log.name": "my very own name"},
"myhost", "myapp", "myapp-type"),
},
},
Expand Down Expand Up @@ -126,7 +126,7 @@ func Test_mapLogRecordToSplunkEvent(t *testing.T) {
return config
},
wantSplunkEvents: []*splunk.Event{
commonLogSplunkEvent("mylog", ts, map[string]interface{}{"foo": float64(123), "host.name": "myhost"}, "myhost", "myapp", "myapp-type"),
commonLogSplunkEvent("mylog", ts, map[string]interface{}{"foo": float64(123)}, "myhost", "myapp", "myapp-type"),
},
},
{
Expand Down Expand Up @@ -181,7 +181,7 @@ func Test_mapLogRecordToSplunkEvent(t *testing.T) {
},
wantSplunkEvents: []*splunk.Event{
func() *splunk.Event {
event := commonLogSplunkEvent("mylog", ts, map[string]interface{}{"custom": "custom", "host.name": "myhost", "myseverity": "DEBUG", "myseveritynum": pdata.SeverityNumber(5)}, "myhost", "mysource", "mysourcetype")
event := commonLogSplunkEvent("mylog", ts, map[string]interface{}{"custom": "custom", "myseverity": "DEBUG", "myseveritynum": pdata.SeverityNumber(5)}, "myhost", "mysource", "mysourcetype")
event.Index = "myindex"
return event
}(),
Expand Down Expand Up @@ -246,7 +246,7 @@ func Test_mapLogRecordToSplunkEvent(t *testing.T) {
return config
},
wantSplunkEvents: []*splunk.Event{
commonLogSplunkEvent(float64(42), ts, map[string]interface{}{"custom": "custom", "host.name": "myhost"}, "myhost", "myapp", "myapp-type"),
commonLogSplunkEvent(float64(42), ts, map[string]interface{}{"custom": "custom"}, "myhost", "myapp", "myapp-type"),
},
},
{
Expand All @@ -269,7 +269,7 @@ func Test_mapLogRecordToSplunkEvent(t *testing.T) {
return config
},
wantSplunkEvents: []*splunk.Event{
commonLogSplunkEvent(int64(42), ts, map[string]interface{}{"custom": "custom", "host.name": "myhost"}, "myhost", "myapp", "myapp-type"),
commonLogSplunkEvent(int64(42), ts, map[string]interface{}{"custom": "custom"}, "myhost", "myapp", "myapp-type"),
},
},
{
Expand All @@ -292,7 +292,7 @@ func Test_mapLogRecordToSplunkEvent(t *testing.T) {
return config
},
wantSplunkEvents: []*splunk.Event{
commonLogSplunkEvent(true, ts, map[string]interface{}{"custom": "custom", "host.name": "myhost"}, "myhost", "myapp", "myapp-type"),
commonLogSplunkEvent(true, ts, map[string]interface{}{"custom": "custom"}, "myhost", "myapp", "myapp-type"),
},
},
{
Expand Down Expand Up @@ -320,7 +320,7 @@ func Test_mapLogRecordToSplunkEvent(t *testing.T) {
},
wantSplunkEvents: []*splunk.Event{
commonLogSplunkEvent(map[string]interface{}{"23": float64(45), "foo": "bar"}, ts,
map[string]interface{}{"custom": "custom", "host.name": "myhost"},
map[string]interface{}{"custom": "custom"},
"myhost", "myapp", "myapp-type"),
},
},
Expand All @@ -343,7 +343,7 @@ func Test_mapLogRecordToSplunkEvent(t *testing.T) {
return config
},
wantSplunkEvents: []*splunk.Event{
commonLogSplunkEvent(nil, ts, map[string]interface{}{"custom": "custom", "host.name": "myhost"},
commonLogSplunkEvent(nil, ts, map[string]interface{}{"custom": "custom"},
"myhost", "myapp", "myapp-type"),
},
},
Expand All @@ -370,7 +370,7 @@ func Test_mapLogRecordToSplunkEvent(t *testing.T) {
return config
},
wantSplunkEvents: []*splunk.Event{
commonLogSplunkEvent([]interface{}{"foo"}, ts, map[string]interface{}{"custom": "custom", "host.name": "myhost"},
commonLogSplunkEvent([]interface{}{"foo"}, ts, map[string]interface{}{"custom": "custom"},
"myhost", "myapp", "myapp-type"),
},
},
Expand All @@ -396,7 +396,7 @@ func Test_mapLogRecordToSplunkEvent(t *testing.T) {
},
wantSplunkEvents: func() []*splunk.Event {
event := commonLogSplunkEvent("mylog", ts, map[string]interface{}{
"host.name": "myhost-resource", "resourceAttr1": "some_string",
"resourceAttr1": "some_string",
}, "myhost-resource", "myapp-resource", "myapp-type-from-resource-attr")
event.Index = "index-resource"
return []*splunk.Event{
Expand Down Expand Up @@ -426,7 +426,7 @@ func Test_mapLogRecordToSplunkEvent(t *testing.T) {
return config
},
wantSplunkEvents: []*splunk.Event{
commonLogSplunkEvent("mylog", ts, map[string]interface{}{"custom": "custom", "host.name": "myhost", "otel.log.severity.number": pdata.SeverityNumberDEBUG, "otel.log.severity.text": "DEBUG"},
commonLogSplunkEvent("mylog", ts, map[string]interface{}{"custom": "custom", "otel.log.severity.number": pdata.SeverityNumberDEBUG, "otel.log.severity.text": "DEBUG"},
"myhost", "myapp", "myapp-type"),
},
},
Expand Down
2 changes: 0 additions & 2 deletions exporter/splunkhecexporter/metricdata_to_splunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"strconv"

"go.opentelemetry.io/collector/model/pdata"
conventions "go.opentelemetry.io/collector/model/semconv/v1.5.0"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
Expand Down Expand Up @@ -79,7 +78,6 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config)
switch k {
case hostKey:
host = v.StringVal()
commonFields[conventions.AttributeHostName] = host
case sourceKey:
source = v.StringVal()
case sourceTypeKey:
Expand Down
8 changes: 4 additions & 4 deletions exporter/splunkhecexporter/metricdata_to_splunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ func Test_metricDataToSplunk(t *testing.T) {
return metrics
},
wantSplunkMetrics: []*splunk.Event{
commonSplunkMetric("gauge_double_with_dims", tsMSecs, []string{"host.name", "k0", "k1", "metric_type"}, []interface{}{"myhost", "v0", "v1", "Gauge"}, doubleVal, "mysource", "mysourcetype", "myindex", "myhost"),
commonSplunkMetric("gauge_int_with_dims", tsMSecs, []string{"host.name", "k0", "k1", "metric_type"}, []interface{}{"myhost", "v0", "v1", "Gauge"}, int64Val, "mysource", "mysourcetype", "myindex", "myhost"),
commonSplunkMetric("gauge_double_with_dims", tsMSecs, []string{"k0", "k1", "metric_type"}, []interface{}{"v0", "v1", "Gauge"}, doubleVal, "mysource", "mysourcetype", "myindex", "myhost"),
commonSplunkMetric("gauge_int_with_dims", tsMSecs, []string{"k0", "k1", "metric_type"}, []interface{}{"v0", "v1", "Gauge"}, int64Val, "mysource", "mysourcetype", "myindex", "myhost"),
},
configFn: func() *Config {
return createDefaultConfig().(*Config)
Expand Down Expand Up @@ -589,8 +589,8 @@ func Test_metricDataToSplunk(t *testing.T) {
return metrics
},
wantSplunkMetrics: []*splunk.Event{
commonSplunkMetric("gauge_double_with_dims", tsMSecs, []string{"host.name", "k0", "k1", "metric_type"}, []interface{}{"myhost2", "v0", "v1", "Gauge"}, doubleVal, "mysource2", "mysourcetype2", "myindex2", "myhost2"),
commonSplunkMetric("gauge_int_with_dims", tsMSecs, []string{"host.name", "k0", "k1", "metric_type"}, []interface{}{"myhost2", "v0", "v1", "Gauge"}, int64Val, "mysource2", "mysourcetype2", "myindex2", "myhost2"),
commonSplunkMetric("gauge_double_with_dims", tsMSecs, []string{"k0", "k1", "metric_type"}, []interface{}{"v0", "v1", "Gauge"}, doubleVal, "mysource2", "mysourcetype2", "myindex2", "myhost2"),
commonSplunkMetric("gauge_int_with_dims", tsMSecs, []string{"k0", "k1", "metric_type"}, []interface{}{"v0", "v1", "Gauge"}, int64Val, "mysource2", "mysourcetype2", "myindex2", "myhost2"),
},
configFn: func() *Config {
cfg := createDefaultConfig().(*Config)
Expand Down
2 changes: 0 additions & 2 deletions exporter/splunkhecexporter/tracedata_to_splunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package splunkhecexporter // import "github.com/open-telemetry/opentelemetry-col

import (
"go.opentelemetry.io/collector/model/pdata"
conventions "go.opentelemetry.io/collector/model/semconv/v1.5.0"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
Expand Down Expand Up @@ -78,7 +77,6 @@ func traceDataToSplunk(logger *zap.Logger, data pdata.Traces, config *Config) ([
switch k {
case hostKey:
host = v.StringVal()
commonFields[conventions.AttributeHostName] = host
case sourceKey:
source = v.StringVal()
case sourceTypeKey:
Expand Down
4 changes: 1 addition & 3 deletions exporter/splunkhecexporter/tracedata_to_splunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ func commonSplunkEvent(
},
},
},
Fields: map[string]interface{}{
"host.name": "myhost",
},
Fields: map[string]interface{}{},
}
}

0 comments on commit a38f067

Please sign in to comment.