Skip to content

Commit

Permalink
fix: shallow copy config in processor (#2856)
Browse files Browse the repository at this point in the history
  • Loading branch information
cisse21 authored Jan 10, 2023
1 parent 82de4c3 commit df890fc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ test-with-coverage: test coverage

build: ## Build rudder-server binary
$(eval BUILD_OPTIONS = )
ifeq ($(RACE_ENABLED), TRUE)
$(eval BUILD_OPTIONS = $(BUILD_OPTIONS) -race -o rudder-server-with-race)
endif
$(GO) build $(BUILD_OPTIONS) -a -installsuffix cgo -ldflags="$(LDFLAGS)"
$(GO) build -o build/wait-for-go/wait-for-go build/wait-for-go/wait-for.go
$(GO) build -o build/regulation-worker ./regulation-worker/cmd/
Expand Down
20 changes: 10 additions & 10 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"io"
"math"
"net/http"
"reflect"
"runtime/trace"
"strconv"
"strings"
"sync"
"time"

jsoniter "github.com/json-iterator/go"
"github.com/samber/lo"
"github.com/tidwall/gjson"
"golang.org/x/sync/errgroup"

Expand Down Expand Up @@ -1371,14 +1371,14 @@ func (proc *HandleT) processJobsForDest(subJobs subJob, parsedEventList [][]type
destination := &enabledDestinationsList[idx]
shallowEventCopy := transformer.TransformerEventT{}
shallowEventCopy.Message = singularEvent
shallowEventCopy.Destination = reflect.ValueOf(*destination).Interface().(backendconfig.DestinationT)
shallowEventCopy.Destination = *destination
shallowEventCopy.Libraries = workspaceLibraries
shallowEventCopy.Metadata = event.Metadata

// At the TP flow we are not having destination information, so adding it here.
shallowEventCopy.Metadata.DestinationID = destination.ID
shallowEventCopy.Metadata.DestinationType = destination.DestinationDefinition.Name
filterConfig(&shallowEventCopy, destination)
filterConfig(&shallowEventCopy)
metadata := shallowEventCopy.Metadata
srcAndDestKey := getKeyFromSourceAndDest(metadata.SourceID, metadata.DestinationID)
// We have at-least one event so marking it good
Expand Down Expand Up @@ -2555,14 +2555,14 @@ func (proc *HandleT) updateRudderSourcesStats(ctx context.Context, tx jobsdb.Sto
return err
}

func filterConfig(eventCopy *transformer.TransformerEventT, destination *backendconfig.DestinationT) {
if configsToFilterI, ok := destination.DestinationDefinition.Config["configFilters"]; ok {
func filterConfig(eventCopy *transformer.TransformerEventT) {
if configsToFilterI, ok := eventCopy.Destination.DestinationDefinition.Config["configFilters"]; ok {
if configsToFilter, ok := configsToFilterI.([]interface{}); ok {
for _, configKey := range configsToFilter {
if configKeyStr, ok := configKey.(string); ok {
eventCopy.Destination.Config[configKeyStr] = ""
}
}
omitKeys := lo.FilterMap(configsToFilter, func(configKey interface{}, _ int) (string, bool) {
configKeyStr, ok := configKey.(string)
return configKeyStr, ok
})
eventCopy.Destination.Config = lo.OmitByKeys(eventCopy.Destination.Config, omitKeys)
}
}
}
14 changes: 5 additions & 9 deletions processor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2436,9 +2436,7 @@ var _ = Describe("TestConfigFilter", func() {
ID: "1",
Name: "test",
Config: map[string]interface{}{
"config_key": "config_value",
"long_config1": "",
"long_config2": "",
"config_key": "config_value",
},
DestinationDefinition: backendconfig.DestinationDefinitionT{
Config: map[string]interface{}{
Expand All @@ -2455,7 +2453,7 @@ var _ = Describe("TestConfigFilter", func() {
},
Destination: intgConfig,
}
filterConfig(&event, &intgConfig)
filterConfig(&event)
Expect(event).To(Equal(expectedEvent))
})

Expand Down Expand Up @@ -2489,9 +2487,7 @@ var _ = Describe("TestConfigFilter", func() {
ID: "1",
Name: "test",
Config: map[string]interface{}{
"config_key": "config_value",
"long_config1": "",
"long_config2": "",
"config_key": "config_value",
},
DestinationDefinition: backendconfig.DestinationDefinitionT{
Config: map[string]interface{}{
Expand All @@ -2508,7 +2504,7 @@ var _ = Describe("TestConfigFilter", func() {
},
Destination: intgConfig,
}
filterConfig(&event, &intgConfig)
filterConfig(&event)
Expect(event).To(Equal(expectedEvent))
})

Expand Down Expand Up @@ -2556,7 +2552,7 @@ var _ = Describe("TestConfigFilter", func() {
},
Destination: intgConfig,
}
filterConfig(&event, &intgConfig)
filterConfig(&event)
Expect(event).To(Equal(expectedEvent))
})
})
Expand Down

0 comments on commit df890fc

Please sign in to comment.