Skip to content

Commit

Permalink
Remove preserve_to (#464)
Browse files Browse the repository at this point in the history
* wip - removing preserve_to

* Remove 'preserve_to' option, and preserve in place by default
  • Loading branch information
djaglowski authored Apr 8, 2022
1 parent 5a05d45 commit 2ef44fa
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 403 deletions.
10 changes: 0 additions & 10 deletions operator/helper/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func (c ParserConfig) Build(logger *zap.SugaredLogger) (ParserOperator, error) {
TransformerOperator: transformerOperator,
ParseFrom: c.ParseFrom,
ParseTo: c.ParseTo,
PreserveTo: c.PreserveTo,
}

if c.TimeParser != nil {
Expand Down Expand Up @@ -94,7 +93,6 @@ type ParserOperator struct {
TransformerOperator
ParseFrom entry.Field
ParseTo entry.Field
PreserveTo *entry.Field
TimeParser *TimeParser
SeverityParser *SeverityParser
TraceParser *TraceParser
Expand Down Expand Up @@ -148,18 +146,10 @@ func (p *ParserOperator) ParseWith(ctx context.Context, entry *entry.Entry, pars
return p.HandleEntryError(ctx, entry, err)
}

original, _ := entry.Delete(p.ParseFrom)

if err := entry.Set(p.ParseTo, newValue); err != nil {
return p.HandleEntryError(ctx, entry, errors.Wrap(err, "set parse_to"))
}

if p.PreserveTo != nil {
if err := entry.Set(p.PreserveTo, original); err != nil {
return p.HandleEntryError(ctx, entry, errors.Wrap(err, "set preserve_to"))
}
}

var timeParseErr error
if p.TimeParser != nil {
timeParseErr = p.TimeParser.Parse(entry)
Expand Down
178 changes: 10 additions & 168 deletions operator/helper/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ func TestParserFields(t *testing.T) {
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = keyValue
e.Attributes = map[string]interface{}{
"key": "value",
}
Expand All @@ -426,6 +427,7 @@ func TestParserFields(t *testing.T) {
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = keyValue
e.Resource = map[string]interface{}{
"key": "value",
}
Expand Down Expand Up @@ -470,6 +472,7 @@ func TestParserFields(t *testing.T) {
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = keyValue
e.Attributes = map[string]interface{}{
"one": map[string]interface{}{
"two": map[string]interface{}{
Expand All @@ -494,6 +497,7 @@ func TestParserFields(t *testing.T) {
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = keyValue
e.Resource = map[string]interface{}{
"one": map[string]interface{}{
"two": map[string]interface{}{
Expand Down Expand Up @@ -523,7 +527,9 @@ func TestParserFields(t *testing.T) {
e := entry.New()
e.ObservedTimestamp = now
e.Body = map[string]interface{}{
"one": map[string]interface{}{},
"one": map[string]interface{}{
"two": keyValue,
},
}
e.Attributes = map[string]interface{}{
"key": "value",
Expand Down Expand Up @@ -551,7 +557,9 @@ func TestParserFields(t *testing.T) {
e.ObservedTimestamp = now
e.Attributes = map[string]interface{}{
"key": "value",
"one": map[string]interface{}{},
"one": map[string]interface{}{
"two": keyValue,
},
}
return e
},
Expand All @@ -578,178 +586,12 @@ func TestParserFields(t *testing.T) {
"key": "value",
}
e.Resource = map[string]interface{}{
"one": map[string]interface{}{},
}
return e
},
},
{
"AllFields",
func(cfg *ParserConfig) {
cfg.ParseFrom = entry.NewBodyField("one", "two")
cfg.ParseTo = entry.NewAttributeField()
dst := entry.NewResourceField("foo")
cfg.PreserveTo = &dst
},
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = map[string]interface{}{
"one": map[string]interface{}{
"two": keyValue,
},
}
return e
},
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = map[string]interface{}{
"one": map[string]interface{}{},
}
e.Attributes = map[string]interface{}{
"key": "value",
}
e.Resource = map[string]interface{}{
"foo": keyValue,
}
return e
},
},
{
"NoPreserve",
func(cfg *ParserConfig) {},
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = keyValue
return e
},
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Attributes = map[string]interface{}{"key": "value"}
return e
},
},
{
"PreserveToSubkey",
func(cfg *ParserConfig) {
dst := entry.NewBodyField("original")
cfg.PreserveTo = &dst
},
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = keyValue
return e
},
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = map[string]interface{}{
"original": keyValue,
}
e.Attributes = map[string]interface{}{
"key": "value",
}
return e
},
},
{
"PreserveToOverwrite",
func(cfg *ParserConfig) {
dst := entry.NewAttributeField("key")
cfg.PreserveTo = &dst
},
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = keyValue
return e
},
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Attributes = map[string]interface{}{
"key": keyValue,
}
return e
},
},
{
"PreserveToRoot",
func(cfg *ParserConfig) {
dst := entry.NewBodyField()
cfg.PreserveTo = &dst
},
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = keyValue
return e
},
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = keyValue
e.Attributes = map[string]interface{}{
"key": "value",
}
return e
},
},
{
"AlternativeParseFrom",
func(cfg *ParserConfig) {
dst := entry.NewBodyField("source")
cfg.PreserveTo = &dst
cfg.ParseFrom = dst
},
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = map[string]interface{}{
"source": keyValue,
}
return e
},
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = map[string]interface{}{
"source": keyValue,
}
e.Attributes = map[string]interface{}{
"key": "value",
}
return e
},
},
{
"AlternativeParseTo",
func(cfg *ParserConfig) {
dst := entry.NewBodyField("original")
cfg.PreserveTo = &dst
cfg.ParseTo = entry.NewBodyField("source_parsed")
},
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = keyValue
return e
},
func() *entry.Entry {
e := entry.New()
e.ObservedTimestamp = now
e.Body = map[string]interface{}{
"source_parsed": map[string]interface{}{
"key": "value",
},
"original": keyValue,
}
return e
},
},
}

Expand Down
Loading

0 comments on commit 2ef44fa

Please sign in to comment.