Skip to content

Update Bloblang playground#289

Merged
mihaitodor merged 4 commits intomainfrom
mihaitodor-update-bloblang-playground
May 13, 2025
Merged

Update Bloblang playground#289
mihaitodor merged 4 commits intomainfrom
mihaitodor-update-bloblang-playground

Conversation

@mihaitodor
Copy link
Copy Markdown
Contributor

  • Only update Benthos and Connect automatically
  • Make sure we parse the output correctly when the mapping returns a simple byte array
  • Make sure we pull in the latest wasm_exec.js
  • Update the Readme

@mihaitodor mihaitodor requested a review from JakeSCahill May 12, 2025 19:36
@netlify
Copy link
Copy Markdown

netlify bot commented May 12, 2025

Deploy Preview for docs-ui ready!

Name Link
🔨 Latest commit 46da9ac
🔍 Latest deploy log https://app.netlify.com/sites/docs-ui/deploys/6822eab8bed03f0008b2fea8
😎 Deploy Preview https://deploy-preview-289--docs-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 12, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This set of changes updates the build, dependency management, and code quality workflows for the Bloblang Playground's WebAssembly (Wasm) module and related frontend integration. The GitHub Actions workflows are modified to target specific Go dependencies for updates and to introduce Go linting. The Wasm module's Go code is refactored for improved error handling and output formatting, and its module name is changed. The frontend JavaScript handling of Wasm output is adjusted, and the build process now copies the Go runtime's wasm_exec.js script before building the Wasm binary. Additional polyfills and helper functions are introduced in the local wasm_exec.js file.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend (JS)
    participant Wasm Module (Go)
    participant GitHub Actions

    User->>Frontend (JS): Initiates Bloblang Playground action
    Frontend (JS)->>Wasm Module (Go): Calls blobl() with args
    Wasm Module (Go)->>Wasm Module (Go): Processes args, applies mapping, handles metadata
    Wasm Module (Go)->>Frontend (JS): Returns JSON result (msg, meta)
    Frontend (JS)->>Frontend (JS): Extracts msg and meta from result
    Frontend (JS)->>User: Displays output

    Note over GitHub Actions: Workflow for build/validation
    GitHub Actions->>GitHub Actions: Checkout, setup Go, update specific dependencies, tidy modules
    GitHub Actions->>GitHub Actions: Run Go linter
    GitHub Actions->>GitHub Actions: Setup Node, bundle UI
Loading

Possibly related PRs

Suggested reviewers

  • JakeSCahill

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Comment on lines +43 to +45
go get github.com/redpanda-data/benthos/v4
go get github.com/redpanda-data/connect/v4
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this should be fine... All the other dependencies are implicit so they should be updated when we update these.

"encoding/json"
"fmt"
"syscall/js"
"encoding/json"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Somehow, this file had the tabs converted to spaces in a previous PR. Not sure why...

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🔭 Outside diff range comments (1)
gulpfile.js (1)

90-107: ⚠️ Potential issue

done() is invoked twice – Gulp will error out

Both exec calls use the same callback:

  1. Copy wasm_exec.jsdone()
  2. Build .wasmdone()

When the first finishes, the task signals completion, but the second will later call done() again, causing “task callback called too many times”.

-  exec('cp "$(go env GOROOT)/lib/wasm/wasm_exec.js" ./src/js/vendor', { cwd: __dirname }, (err, stdout, stderr) => {
-    if (err) { …; done(err); return }
-    done()
-  })
-
-  exec(`go build -o "${wasmOutputPath}" .`, { cwd: wasmDir, env: envVars }, (err, stdout, stderr) => {
-    if (err) { …; done(err); return }
-
-    done()
-  })
+  exec(
+    'cp "$(go env GOROOT)/lib/wasm/wasm_exec.js" ./src/js/vendor',
+    { cwd: __dirname },
+    (copyErr, _1, copyStderr) => {
+      if (copyErr) {
+        log.error('Error copying wasm_exec.js:', copyStderr);
+        return done(copyErr);
+      }
+      exec(
+        `go build -o "${wasmOutputPath}" .`,
+        { cwd: wasmDir, env: envVars },
+        (buildErr, stdout, stderr) => {
+          if (buildErr) {
+            log.error('Error building WASM:', stderr);
+            return done(buildErr);
+          }
+          log.info('WebAssembly built successfully:', stdout);
+          done(); // called exactly once
+        }
+      );
+    }
+  );

While here, consider replacing the shell-specific cp "$(go env …)" with a Node copy (fs.copyFileSync) plus child_process.execSync('go env GOROOT'); this is portable across Windows and *nix.

🧹 Nitpick comments (1)
src/partials/bloblang-playground.hbs (1)

307-309: Verify WebAssembly integration.

The blobl function is called here, but there's no clear error handling for when the WebAssembly module isn't properly loaded. Consider adding a check before calling this function.

-    const result = blobl(getMapping(), getInput(), getInputMetadata());
+    if (typeof blobl !== 'function') {
+      throw new Error("WebAssembly module not properly loaded. Please refresh the page.");
+    }
+    const result = blobl(getMapping(), getInput(), getInputMetadata());
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3cc0ab8 and 0142fda.

📒 Files selected for processing (8)
  • .github/workflows/update-go-mod.yml (1 hunks)
  • .github/workflows/validate-build.yml (1 hunks)
  • blobl-editor/README.md (1 hunks)
  • blobl-editor/wasm/go.mod (1 hunks)
  • blobl-editor/wasm/main.go (1 hunks)
  • gulpfile.js (1 hunks)
  • src/js/vendor/wasm_exec.js (3 hunks)
  • src/partials/bloblang-playground.hbs (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/validate-build.yml

13-13: the runner of "actions/setup-go@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🪛 golangci-lint (1.64.8)
blobl-editor/wasm/main.go

6-6: could not import syscall/js (-: build constraints exclude all Go files in /tmp/go/.go-mod-cache/golang.org/[email protected]/src/syscall/js)

(typecheck)

🪛 ESLint
src/js/vendor/wasm_exec.js

[error] 17-17: Unexpected tab character.

(no-tabs)


[error] 17-17: Expected indentation of 6 spaces but found 3 tabs.

(indent)


[error] 76-76: Unexpected tab character.

(no-tabs)


[error] 76-76: Expected indentation of 2 spaces but found 1 tab.

(indent)


[error] 76-76: 'globalThis' is not defined.

(no-undef)


[error] 77-77: Unexpected tab character.

(no-tabs)


[error] 77-77: Expected indentation of 4 spaces but found 2 tabs.

(indent)


[error] 77-77: 'globalThis' is not defined.

(no-undef)


[error] 78-78: Unexpected tab character.

(no-tabs)


[error] 78-78: Expected indentation of 6 spaces but found 3 tabs.

(indent)


[error] 78-78: Missing space before function parentheses.

(space-before-function-paren)


[error] 79-79: Unexpected tab character.

(no-tabs)


[error] 79-79: Expected indentation of 8 spaces but found 4 tabs.

(indent)


[error] 79-79: Strings must use singlequote.

(quotes)


[error] 79-79: Extra semicolon.

(semi)


[error] 80-80: Unexpected tab character.

(no-tabs)


[error] 80-80: Expected indentation of 6 spaces but found 3 tabs.

(indent)


[error] 80-81: Missing trailing comma.

(comma-dangle)


[error] 81-81: Unexpected tab character.

(no-tabs)


[error] 81-81: Expected indentation of 4 spaces but found 2 tabs.

(indent)


[error] 82-82: Unexpected tab character.

(no-tabs)


[error] 82-82: Expected indentation of 2 spaces but found 1 tab.

(indent)


[error] 219-219: Unexpected tab character.

(no-tabs)


[error] 219-219: Expected indentation of 6 spaces but found 3 tabs.

(indent)


[error] 220-220: Unexpected tab character.

(no-tabs)


[error] 220-220: Expected indentation of 8 spaces but found 4 tabs.

(indent)


[error] 220-220: Extra semicolon.

(semi)


[error] 221-221: Unexpected tab character.

(no-tabs)


[error] 221-221: Expected indentation of 8 spaces but found 4 tabs.

(indent)


[error] 221-221: Extra semicolon.

(semi)


[error] 222-222: Unexpected tab character.

(no-tabs)


[error] 222-222: Expected indentation of 6 spaces but found 3 tabs.

(indent)


[error] 224-224: Unexpected tab character.

(no-tabs)


[error] 224-224: Expected indentation of 6 spaces but found 3 tabs.

(indent)


[error] 224-224: 'performance' is not defined.

(no-undef)


[error] 224-224: Extra semicolon.

(semi)


[error] 225-225: Unexpected tab character.

(no-tabs)


[error] 225-225: Expected indentation of 6 spaces but found 3 tabs.

(indent)


[error] 226-226: Unexpected tab character.

(no-tabs)


[error] 226-226: Expected indentation of 8 spaces but found 4 tabs.

(indent)


[error] 227-227: Unexpected tab character.

(no-tabs)


[error] 227-227: Expected indentation of 10 spaces but found 5 tabs.

(indent)


[error] 228-228: Unexpected tab character.

(no-tabs)


[error] 228-228: Expected indentation of 10 spaces but found 5 tabs.

(indent)

🔇 Additional comments (8)
blobl-editor/wasm/go.mod (3)

1-1: Module name change looks good.

The module name has been simplified from blobl-playground to blobl, which aligns well with the other updates in this PR. The change is simple but provides better consistency across the codebase.


8-10: Explicit dependency versioning looks good.

Direct dependencies on Benthos and Connect are clearly specified, which aligns with the PR objectives to automatically update only these components.


3-5:

Details

❓ Verification inconclusive

Confirm Go version compatibility with your deployment environment.

The file specifies Go 1.24.1 with toolchain 1.24.2, which are very recent versions of Go. Make sure your deployment environment supports these versions.


🏁 Script executed:

#!/bin/bash
# Verify Go version compatibility in deployment environments
go version

Length of output: 44


Ensure Go version consistency in go.mod (blobl-editor/wasm/go.mod lines 3–5)

Your go.mod declares:

go 1.24.1
toolchain go1.24.2

Local environment reports:

go version go1.24.1 linux/amd64

• There’s a mismatch: the toolchain directive requires Go 1.24.2, but your local (and possibly CI/deploy) is on 1.24.1.
• Either upgrade all environments (CI, containers, servers) to Go 1.24.2 to match the directive,
or change the toolchain line to go1.24.1 if you intend to stay on that version.

.github/workflows/update-go-mod.yml (1)

43-44: Improved dependency update strategy.

The workflow now explicitly updates only the Benthos and Connect packages rather than updating all dependencies recursively. This provides more controlled dependency management and aligns perfectly with the PR objectives.

src/partials/bloblang-playground.hbs (1)

314-315:

Details

✅ Verification successful

Ensure consistent message handling with the backend changes.

The code now strictly uses parsedResult.msg without falling back to the entire parsedResult object. While this change aligns with backend updates for more consistent message handling, it could potentially lead to issues if msg is not present in certain responses.


🏁 Script executed:

#!/bin/bash
# Look for places where blobl function returns values without a msg property
cd blobl-editor/wasm
grep -r "return" --include="*.go" . | grep -v "msg"

Length of output: 1825


🏁 Script executed:

#!/bin/bash
# Extract the relevant JavaScript logic around parsedResult usage
sed -n '250,350p' src/partials/bloblang-playground.hbs

Length of output: 3234


🏁 Script executed:

#!/bin/bash
# Find and print context around payload return in WASM main.go
file="blobl-editor/wasm/main.go"
match=$(grep -n "return string(payload)" "$file")
echo "$match"
if [ -n "$match" ]; then
  line=${match%%:*}
  start=$((line-10))
  end=$((line+10))
  sed -n "${start},${end}p" "$file"
fi

Length of output: 891


No changes needed for msg handling
The WASM backend always includes a top‐level msg field (it isn’t tagged omitempty), so parsedResult.msg will always be defined when JSON.parse(result) succeeds. Non‐JSON outputs and errors are handled in separate branches.

.github/workflows/validate-build.yml (1)

16-19: Go linting integration looks good.

Adding golangci-lint to validate Go code quality is a great improvement. This ensures the WebAssembly code meets quality standards before building.

blobl-editor/wasm/main.go (2)

25-32: Nice touch: converting returned errors to strings avoids JS panics

The deferred conversion guarantees the JS caller always receives a string, simplifying the playground’s error handling. 👍


72-80: Graceful fallback from structured → raw bytes is helpful

The extra AsBytes() branch ensures mappings that return plain byte arrays still render correctly, matching the PR objective. Looks good.

@mihaitodor mihaitodor force-pushed the mihaitodor-update-bloblang-playground branch 4 times, most recently from bfd6db0 to 2b9b44a Compare May 12, 2025 19:58
- Only update Benthos and Connect automatically
- Make sure we parse the output correctly when the mapping returns
a simple byte array
- Make sure we pull in the latest wasm_exec.js
- Update the Readme

Signed-off-by: Mihai Todor <[email protected]>
@mihaitodor mihaitodor force-pushed the mihaitodor-update-bloblang-playground branch from 2b9b44a to 695804f Compare May 13, 2025 02:38
@JakeSCahill JakeSCahill self-requested a review May 13, 2025 06:29
Copy link
Copy Markdown
Contributor

@JakeSCahill JakeSCahill left a comment

Choose a reason for hiding this comment

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

Amazing, thanks for the changes ❤️

@mihaitodor mihaitodor merged commit 34bc930 into main May 13, 2025
7 checks passed
@mihaitodor mihaitodor deleted the mihaitodor-update-bloblang-playground branch May 13, 2025 13:11
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