Skip to content

Commit

Permalink
Route using user-defined data_stream.{dataset,namespace} for logs
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonip committed Jan 15, 2024
1 parent 56bf536 commit eed60d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 8 additions & 2 deletions model/modelprocessor/datastream.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ func (s *SetDataStream) ProcessBatch(ctx context.Context, b *modelpb.Batch) erro
if (*b)[i].DataStream == nil {
(*b)[i].DataStream = modelpb.DataStreamFromVTPool()
}
(*b)[i].DataStream.Namespace = s.Namespace
if (*b)[i].DataStream.Namespace == "" {
// Only set namespace if it is not already set by user
(*b)[i].DataStream.Namespace = s.Namespace
}
if (*b)[i].DataStream.Type == "" || (*b)[i].DataStream.Dataset == "" {
s.setDataStream((*b)[i])
}
Expand All @@ -75,7 +78,10 @@ func (s *SetDataStream) setDataStream(event *modelpb.APMEvent) {
event.DataStream.Dataset = errorsDataset
case modelpb.LogEventType:
event.DataStream.Type = logsType
event.DataStream.Dataset = getAppLogsDataset(event)
if event.DataStream.Dataset == "" {
// Only set dataset if it is not already set by user
event.DataStream.Dataset = getAppLogsDataset(event)
}
case modelpb.MetricEventType:
event.DataStream.Type = metricsType
event.DataStream.Dataset = metricsetDataset(event)
Expand Down
8 changes: 8 additions & 0 deletions model/modelprocessor/datastream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ func TestSetDataStream(t *testing.T) {
Service: &modelpb.Service{Name: "service-name"},
},
output: &modelpb.DataStream{Type: "logs", Dataset: "apm.app.service_name", Namespace: "custom"},
}, {
input: &modelpb.APMEvent{
Log: &modelpb.Log{},
Agent: &modelpb.Agent{Name: "iOS/swift"},
Service: &modelpb.Service{Name: "service-name"},
DataStream: &modelpb.DataStream{Dataset: "dataset", Namespace: "namespace"},
},
output: &modelpb.DataStream{Type: "logs", Dataset: "dataset", Namespace: "namespace"},
}, {
input: &modelpb.APMEvent{
Agent: &modelpb.Agent{Name: "rum-js"},
Expand Down

0 comments on commit eed60d5

Please sign in to comment.