Skip to content

Commit

Permalink
Less allocations in mask plugin (#656)
Browse files Browse the repository at this point in the history
* Add flag

---------

Co-authored-by: george pogosyan <[email protected]>
  • Loading branch information
goshansmails and george pogosyan authored Aug 20, 2024
1 parent 2533c1b commit 9dea20e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions plugin/action/mask/mask.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,9 @@ func (p *Plugin) Do(event *pipeline.Event) pipeline.ActionResult {
}

p.sourceBuf = append(p.sourceBuf[:0], value...)
p.maskBuf = append(p.maskBuf[:0], p.sourceBuf...)
// valueMasked is not the same as maskApplied;
// it shows if current node is masked and really needs to be changed
valueMasked := false
for i := range p.config.Masks {
mask := &p.config.Masks[i]
if mask.Re != "" && !valueIsCommonMatched {
Expand All @@ -515,6 +517,8 @@ func (p *Plugin) Do(event *pipeline.Event) pipeline.ActionResult {
if !locApplied {
continue
}
valueMasked = true

if mask.AppliedField != "" {
event.Root.AddFieldNoAlloc(event.Root, mask.AppliedField).MutateToString(mask.AppliedValue)
}
Expand All @@ -524,7 +528,10 @@ func (p *Plugin) Do(event *pipeline.Event) pipeline.ActionResult {

maskApplied = true
}
v.MutateToString(string(p.maskBuf))

if valueMasked {
v.MutateToString(string(p.maskBuf))
}
}

if p.config.MaskAppliedField != "" && maskApplied {
Expand Down

0 comments on commit 9dea20e

Please sign in to comment.