Skip to content

Commit

Permalink
Change default value of 'parse_to' to 'attributes' (#463)
Browse files Browse the repository at this point in the history
* Change default value of 'parse_to' to 'attributes'

* Fix tests in recently added operator
  • Loading branch information
djaglowski authored Apr 6, 2022
1 parent 708e313 commit 4672c7f
Show file tree
Hide file tree
Showing 10 changed files with 517 additions and 357 deletions.
2 changes: 1 addition & 1 deletion operator/helper/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewParserConfig(operatorID, operatorType string) ParserConfig {
return ParserConfig{
TransformerConfig: NewTransformerConfig(operatorID, operatorType),
ParseFrom: entry.NewBodyField(),
ParseTo: entry.NewBodyField(),
ParseTo: entry.NewAttributeField(),
PreserveTo: nil,
}
}
Expand Down
27 changes: 17 additions & 10 deletions operator/helper/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,11 @@ func TestParserFields(t *testing.T) {
e := entry.New()
e.ObservedTimestamp = now
e.Body = map[string]interface{}{
"key": "value",
"one": map[string]interface{}{},
}
e.Attributes = map[string]interface{}{
"key": "value",
}
return e
},
},
Expand All @@ -515,10 +517,8 @@ func TestParserFields(t *testing.T) {
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = map[string]interface{}{
"key": "value",
}
e.Attributes = map[string]interface{}{
"key": "value",
"one": map[string]interface{}{},
}
return e
Expand All @@ -542,7 +542,7 @@ func TestParserFields(t *testing.T) {
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = map[string]interface{}{
e.Attributes = map[string]interface{}{
"key": "value",
}
e.Resource = map[string]interface{}{
Expand Down Expand Up @@ -596,7 +596,7 @@ func TestParserFields(t *testing.T) {
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = map[string]interface{}{"key": "value"}
e.Attributes = map[string]interface{}{"key": "value"}
return e
},
},
Expand All @@ -616,16 +616,18 @@ func TestParserFields(t *testing.T) {
e := entry.New()
e.ObservedTimestamp = now
e.Body = map[string]interface{}{
"key": "value",
"original": keyValue,
}
e.Attributes = map[string]interface{}{
"key": "value",
}
return e
},
},
{
"PreserveToOverwrite",
func(cfg *ParserConfig) {
dst := entry.NewBodyField("key")
dst := entry.NewAttributeField("key")
cfg.PreserveTo = &dst
},
func() *entry.Entry {
Expand All @@ -637,7 +639,7 @@ func TestParserFields(t *testing.T) {
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = map[string]interface{}{
e.Attributes = map[string]interface{}{
"key": keyValue,
}
return e
Expand All @@ -659,6 +661,9 @@ func TestParserFields(t *testing.T) {
e := entry.New()
e.ObservedTimestamp = now
e.Body = keyValue
e.Attributes = map[string]interface{}{
"key": "value",
}
return e
},
},
Expand All @@ -682,7 +687,9 @@ func TestParserFields(t *testing.T) {
e.ObservedTimestamp = now
e.Body = map[string]interface{}{
"source": keyValue,
"key": "value",
}
e.Attributes = map[string]interface{}{
"key": "value",
}
return e
},
Expand Down
12 changes: 6 additions & 6 deletions operator/input/syslog/syslog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ func SyslogInputTest(t *testing.T, cfg *SyslogInputConfig, tc syslog.Case) {
require.NoError(t, err)
}

if v, ok := tc.InputBody.(string); ok {
if v, ok := tc.Input.Body.(string); ok {
_, err = conn.Write([]byte(v))
} else {
_, err = conn.Write(tc.InputBody.([]byte))
_, err = conn.Write(tc.Input.Body.([]byte))
}

conn.Close()
Expand All @@ -85,10 +85,10 @@ func SyslogInputTest(t *testing.T, cfg *SyslogInputConfig, tc syslog.Case) {
select {
case e := <-fake.Received:
// close pipeline to avoid data race
require.Equal(t, tc.ExpectedBody, e.Body)
require.Equal(t, tc.ExpectedTimestamp, e.Timestamp)
require.Equal(t, tc.ExpectedSeverity, e.Severity)
require.Equal(t, tc.ExpectedSeverityText, e.SeverityText)
ots := time.Now()
e.ObservedTimestamp = ots
tc.Expect.ObservedTimestamp = ots
require.Equal(t, tc.Expect, e)
case <-time.After(time.Second):
require.FailNow(t, "Timed out waiting for entry to be processed")
}
Expand Down
Loading

0 comments on commit 4672c7f

Please sign in to comment.