Skip to content

Commit

Permalink
Add ResourceAttributes to Splunk Event
Browse files Browse the repository at this point in the history
  • Loading branch information
rockb1017 committed Mar 24, 2021
1 parent fa90892 commit 6b7a968
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
20 changes: 18 additions & 2 deletions exporter/splunkhecexporter/logdata_to_splunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,36 @@ func logDataToSplunk(logger *zap.Logger, ld pdata.Logs, config *Config) []*splun
for j := 0; j < ills.Len(); j++ {
logs := ills.At(j).Logs()
for k := 0; k < logs.Len(); k++ {
splunkEvents = append(splunkEvents, mapLogRecordToSplunkEvent(logs.At(k), config, logger))
splunkEvents = append(splunkEvents, mapLogRecordToSplunkEvent(rls.At(i), logs.At(k), config, logger))
}
}
}

return splunkEvents
}

func mapLogRecordToSplunkEvent(lr pdata.LogRecord, config *Config, logger *zap.Logger) *splunk.Event {
func mapLogRecordToSplunkEvent(rls pdata.ResourceLogs, lr pdata.LogRecord, config *Config, logger *zap.Logger) *splunk.Event {
host := unknownHostName
source := config.Source
sourcetype := config.SourceType
index := config.Index
fields := map[string]interface{}{}
rls.Resource().Attributes().ForEach(func(k string, v pdata.AttributeValue) {
switch k {
case conventions.AttributeHostName:
host = v.StringVal()
fields[k] = v.StringVal()
case conventions.AttributeServiceName:
source = v.StringVal()
fields[k] = v.StringVal()
case splunk.SourcetypeLabel:
sourcetype = v.StringVal()
case splunk.IndexLabel:
index = v.StringVal()
default:
fields[k] = convertAttributeValue(v, logger)
}
})
lr.Attributes().ForEach(func(k string, v pdata.AttributeValue) {
switch k {
case conventions.AttributeHostName:
Expand Down
15 changes: 8 additions & 7 deletions processor/k8sprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ type ExtractConfig struct {
//
// procesors:
// k8s-tagger:
// annotations:
// - name: git.sha
// key: kubernetes.io/change-cause
// regex: GIT_SHA=(?P<value>\w+)
// - name: ci.build
// key: kubernetes.io/change-cause
// regex: JENKINS=(?P<value>[\w]+)
// extract:
// annotations:
// - tag_name: git.sha
// key: kubernetes.io/change-cause
// regex: GIT_SHA=(?P<value>\w+)
// - tag_name: ci.build
// key: kubernetes.io/change-cause
// regex: JENKINS=(?P<value>[\w]+)
//
// this will add the `git.sha` and `ci.build` tags to the spans or metrics.
type FieldExtractConfig struct {
Expand Down

0 comments on commit 6b7a968

Please sign in to comment.