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

NEOS-570: custom code transformer - updated protos #988

Merged
merged 23 commits into from
Jan 2, 2024

Conversation

evisdrenova
Copy link
Contributor

No description provided.

Copy link

vercel bot commented Dec 28, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
neosync-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 2, 2024 11:53pm
neosync-marketing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 2, 2024 11:53pm

Copy link

codecov bot commented Dec 28, 2023

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (f179496) 58.52% compared to head (e23041f) 58.85%.
Report is 11 commits behind head on main.

Files Patch % Lines
...mgmt/v1alpha1/transformers-service/transformers.go 83.78% 4 Missing and 2 partials ⚠️
...er/pkg/workflows/datasync/activities/activities.go 94.11% 3 Missing and 1 partial ⚠️
...g/workflows/datasync/activities/benthos-builder.go 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #988      +/-   ##
==========================================
+ Coverage   58.52%   58.85%   +0.33%     
==========================================
  Files          84       84              
  Lines        8581     8672      +91     
==========================================
+ Hits         5022     5104      +82     
- Misses       2939     2946       +7     
- Partials      620      622       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@nickzelei nickzelei left a comment

Choose a reason for hiding this comment

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

Left a number of comments. Please review. Probably want to chat more about the javascript code implementation.

@@ -54,7 +56,7 @@ const (
Passthrough Transformation = "passthrough"
Null Transformation = "null"
Invalid Transformation = "invalid"
Javascript Transformation = "javascript"
Javascript Transformation = "transform_javascript"
Copy link
Member

Choose a reason for hiding this comment

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

Probably want to change this property to TransformJavascript as well as I think we will also want a javascript generator.

Copy link
Member

Choose a reason for hiding this comment

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

This doesnt look like it was resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved

Copy link
Member

Choose a reason for hiding this comment

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

I was referring to the property name itself.

Suggested change
Javascript Transformation = "transform_javascript"
TransformJavascript Transformation = "transform_javascript"

worker/pkg/workflows/datasync/activities/activities.go Outdated Show resolved Hide resolved
worker/pkg/workflows/datasync/activities/activities.go Outdated Show resolved Hide resolved
@@ -620,6 +640,14 @@ func parseJavascriptForColumnName(jsCode, targetWord, replacementWord string) st
return strings.ReplaceAll(jsCode, targetWord, replacementWord)
}

func constructJavascriptCode(jsCode, col string) string {
if jsCode != "" {
return fmt.Sprintf(`function fn1(value){%s};const input = benthos.v0_msg_as_structured();const output = { ...input };output["%[2]s"] = fn1(input["%[2]s"]);benthos.v0_msg_set_structured(output)`, jsCode, col)
Copy link
Member

Choose a reason for hiding this comment

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

Please use newlines here. this is not very readable.

Copy link
Member

Choose a reason for hiding this comment

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

Also this still isn't quite right. You need to take all of the columns that are using a js processor and build a single script that processes all of them at once. We dont want to split that across N processors. Minimize benthos overhead by having a single processor for handling javascript.

Copy link
Contributor Author

@evisdrenova evisdrenova Dec 29, 2023

Choose a reason for hiding this comment

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

it's producing this as an output:

processors:
    - javascript:
        code: |-
            (() => {
            function fnname(value) {
                var payload = value+=" hello";return payload;
            };
            const input = benthos.v0_msg_as_structured();
            const output = { ...input };
            output["name"] = fnname(input["name"]);
            benthos.v0_msg_set_structured(output);


            function fnfirst_name(value) {
                var payload = value+=" firstname";return payload;
            };
            const input = benthos.v0_msg_as_structured();
            const output = { ...input };
            output["first_name"] = fnfirst_name(input["first_name"]);
            benthos.v0_msg_set_structured(output);
            })();

where both transformers for different columns (name & first_name) are in the same javascript processor.

Comment on lines 239 to 224
(() => {
function fn1(value){
var a = value + "test";
return a };
const input = benthos.v0_msg_as_structured();
const output = { ...input };
output["name"] = fn1(input["name"]);
benthos.v0_msg_set_structured(output);
})();
Copy link
Member

Choose a reason for hiding this comment

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

We need a test here that shows what this looks like with multiple columns being transformed.

Also it would be great if this were formatted better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a test to the benthos_builder_test file called Test_ProcessorConfigMultiJavascript

Comment on lines 225 to 201
r, w, _ := os.Pipe()
os.Stdout = w
Copy link
Member

Choose a reason for hiding this comment

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

idk about this. Looks like you are using the global Stdout to be this os.Pipe for a single test.
How does this work for the rest of the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i was trying to come up with a way to actually test the transformed value output and since benthos writes to stdout for codec:lines i'm piping that and then getting the resulting value. I wasn't able to find anywhere else where we were actually processing the benthos config and checking the output vs. just the formatting and structure of the benthos config. Open to other ideas.

Copy link
Member

Choose a reason for hiding this comment

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

yea you're right we don't have any tests today that test the benthos output at an integration level.
A better approach here might be to have benthos output to a file in the temp directory that you can then read from afterwards to verify the output. That way there is no need to hijack the stdout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@evisdrenova evisdrenova merged commit cfcd5d2 into main Jan 2, 2024
21 checks passed
@evisdrenova evisdrenova deleted the custom-code-transformer branch January 2, 2024 23:55
@evisdrenova evisdrenova restored the custom-code-transformer branch January 3, 2024 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants