Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for config to custom destinations #2625

Merged
merged 18 commits into from
Nov 2, 2022

Conversation

utsabc
Copy link
Member

@utsabc utsabc commented Oct 27, 2022

Adding support for passing config to transformer for custom destinations

Description

Previously we were filtering the total config for requests to transformer for custom destinations. Main motivation for it was to avoid making heavy requests as some some configs would contain would contain certificate details etc.

This PR approaches the solution with more general intnet by filtering any destination config based on predefined filters set in integrations module

Notion Ticket

Notion link: https://www.notion.so/rudderstacks/Kafka-Destination-with-Multiple-Topics-85cbce26706d49eca6853b972e5497b0

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

…assing config to transformer for custom destinations
@utsabc
Copy link
Member Author

utsabc commented Oct 27, 2022

Related PR: #2569

@codecov
Copy link

codecov bot commented Oct 27, 2022

Codecov Report

Base: 43.85% // Head: 43.84% // Decreases project coverage by -0.00% ⚠️

Coverage data is based on head (b2ad586) compared to base (5c26d1b).
Patch coverage: 81.81% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2625      +/-   ##
==========================================
- Coverage   43.85%   43.84%   -0.01%     
==========================================
  Files         187      187              
  Lines       40027    40024       -3     
==========================================
- Hits        17552    17550       -2     
- Misses      21376    21378       +2     
+ Partials     1099     1096       -3     
Impacted Files Coverage Δ
utils/misc/misc.go 12.54% <0.00%> (+0.01%) ⬆️
processor/processor.go 71.36% <100.00%> (+0.12%) ⬆️
utils/httputil/server.go 80.76% <0.00%> (-11.54%) ⬇️
config/backend-config/namespace_config.go 70.83% <0.00%> (-3.13%) ⬇️
enterprise/reporting/reporting.go 8.33% <0.00%> (-1.44%) ⬇️
services/rsources/handler.go 70.55% <0.00%> (+0.83%) ⬆️
middleware/middleware.go 94.82% <0.00%> (+8.62%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@koladilip koladilip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good, but is this something that can be done from destination definitions itself? Why keep config at different places?

@utsabc
Copy link
Member Author

utsabc commented Oct 27, 2022

It looks good, but is this something that can be done from destination definitions itself? Why keep config at different places?

Ideally yes for a quick fix I went with this appraoch

@utsabc utsabc changed the title feat: support for config to custom destinations): feat: support for config to custom destinations Oct 28, 2022
@koladilip
Copy link
Contributor

It looks good, but is this something that can be done from destination definitions itself? Why keep config at different places?

Ideally yes for a quick fix I went with this appraoch

is this going to be tech debt again? I prefer to have this to be defined at destDef level so that it is easy to debug and understand.

@utsabc
Copy link
Member Author

utsabc commented Oct 28, 2022

It looks good, but is this something that can be done from destination definitions itself? Why keep config at different places?

Ideally yes for a quick fix I went with this appraoch

is this going to be tech debt again? I prefer to have this to be defined at destDef level so that it is easy to debug and understand.

Make sense I will try to do an impl

@utsabc
Copy link
Member Author

utsabc commented Oct 31, 2022

It looks good, but is this something that can be done from destination definitions itself? Why keep config at different places?

Ideally yes for a quick fix I went with this appraoch

is this going to be tech debt again? I prefer to have this to be defined at destDef level so that it is easy to debug and understand.

Make sense I will try to do an impl

@koladilip I have approached the problem with the way you suggested, taking the filter keys from destination definition

sent to transformer for such destination. */
if misc.Contains(customDestinations, *destType) {
shallowEventCopy.Destination.Config = nil
configsToFilter := destination.DestinationDefinition.ConfigFilters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens to range operation if this is nil?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConfigFilters won't be nil as its type Array when initialized it will be an empty array. But we can do a nil check before iterating

Copy link
Member Author

@utsabc utsabc Oct 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2022-10-31 at 10 41 26 AM
Lint is marking it as not needed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes looks like nil is handled by range so we don't need to worry about: https://play.golang.com/p/iymc4sfOdcw

…efinitionT and checks before accessing values
sent to transformer for such destination. */
if misc.Contains(customDestinations, *destType) {
shallowEventCopy.Destination.Config = nil
configsToFilter := destination.DestinationDefinition.ConfigFilters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes looks like nil is handled by range so we don't need to worry about: https://play.golang.com/p/iymc4sfOdcw

…ub.com:rudderlabs/rudder-server into feat.support-for-config-to-custom-destinations
processor/processor.go Outdated Show resolved Hide resolved
processor/processor.go Outdated Show resolved Hide resolved
@chandumlg chandumlg force-pushed the feat.support-for-config-to-custom-destinations branch from 8130004 to bf60abe Compare November 1, 2022 15:21
@utsabc
Copy link
Member Author

utsabc commented Nov 1, 2022

Is it possible to add tests?

Added unit test cases


func filterConfig(eventCopy *transformer.TransformerEventT, destination *backendconfig.DestinationT) {
if configsToFilterI, ok := destination.DestinationDefinition.Config["configFilters"]; ok {
if configsToFilter, ok := configsToFilterI.([]string); ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice, casting to []string has no chances for success, since this config will be populated through json unmarshalling.
https://go.dev/play/p/BLqiaLRfgO-

  • Please adapt relevant tests to use proper, unmarshalled configs
  • Make sure to typecheck the next casting that will be introduced too (k, ok := configKey.(string); ok) as a slice of any type can literally hold any type

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it addressed the same, added unit test cases as well

…to consider array of interface and casting individual types
@@ -509,7 +508,7 @@ func loadConfig() {
config.RegisterBoolConfigVariable(false, &enableEventSchemasAPIOnly, true, "EventSchemas.enableEventSchemasAPIOnly")
config.RegisterIntConfigVariable(10000, &maxEventsToProcess, true, 1, "Processor.maxLoopProcessEvents")

batchDestinations, customDestinations = misc.LoadDestinations()
batchDestinations, _ = misc.LoadDestinations()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since misc.LoadDestinations is only used here and we don't really care about custom destinations, please simplify it by renaming it to misc.BatchDestinations and only return a single value

Suggested change
batchDestinations, _ = misc.LoadDestinations()
batchDestinations = misc.BatchDestinations()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

Comment on lines +2423 to +2425
Config: map[string]interface{}{
"configFilters": []interface{}{"long_config1", "long_config2"},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least once we should use the outcome of json.Unmarshal in our tests, by unmarshalling a json string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

@utsabc utsabc merged commit cb230b0 into master Nov 2, 2022
@utsabc utsabc deleted the feat.support-for-config-to-custom-destinations branch November 2, 2022 08:43
Copy link
Collaborator

@fracasula fracasula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@utsabc linting was not passing when you merged. can you please open a PR to fix the linting warnings? https://github.com/rudderlabs/rudder-server/actions/runs/3375866788/jobs/5602936742

@utsabc
Copy link
Member Author

utsabc commented Nov 2, 2022

@utsabc linting was not passing when you merged. can you please open a PR to fix the linting warnings? https://github.com/rudderlabs/rudder-server/actions/runs/3375866788/jobs/5602936742

Sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants