-
Notifications
You must be signed in to change notification settings - Fork 13
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
Engine: Limit payload sizes of events #890
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d011f82
engine: force a limit on payloads exiting the engine
josephjclark f843bfc
engine: add redacted flag to redacted events
josephjclark b9ae9aa
worker: remove payload validation logic
josephjclark fa26a91
typing
josephjclark f474ed7
fix eventing
josephjclark 99f1183
typing
josephjclark 6a09c09
tweak error message
josephjclark 7055332
integration test
josephjclark ebe8082
prefer Buffer .byteLength to new Blob()
josephjclark d50c05d
changeset
josephjclark 4ed0685
remove clutter
josephjclark ff54f2c
engine: optionally return the run result
josephjclark 3d236c1
tweak error message
josephjclark deb7293
extra engine changeset
josephjclark e6a38b3
typo
josephjclark 9336ab4
engine: remove debug code
josephjclark 0f5ca29
version: [email protected]
josephjclark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
# @openfn/integration-tests-worker | ||
|
||
## 1.0.79 | ||
|
||
### Patch Changes | ||
|
||
- Updated dependencies [deb7293] | ||
- Updated dependencies [d50c05d] | ||
- @openfn/[email protected] | ||
- @openfn/[email protected] | ||
- @openfn/[email protected] | ||
|
||
## 1.0.78 | ||
|
||
### Patch Changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "@openfn/integration-tests-worker", | ||
"private": true, | ||
"version": "1.0.78", | ||
"version": "1.0.79", | ||
"description": "Lightning WOrker integration tests", | ||
"author": "Open Function Group <[email protected]>", | ||
"license": "ISC", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -974,6 +974,45 @@ test.serial('Redact logs which exceed the payload limit', (t) => { | |
}); | ||
}); | ||
|
||
test.serial("Don't return dataclips which exceed the payload limit", (t) => { | ||
return new Promise(async (done) => { | ||
if (!worker.destroyed) { | ||
await worker.destroy(); | ||
} | ||
|
||
({ worker } = await initWorker(lightningPort, { | ||
maxWorkers: 1, | ||
// use the dummy repo to remove autoinstall | ||
repoDir: path.resolve('./dummy-repo'), | ||
})); | ||
|
||
const run = { | ||
id: crypto.randomUUID(), | ||
jobs: [ | ||
{ | ||
adaptor: '@openfn/[email protected]', | ||
body: `fn(() => ({ data: 'abdef' }))`, | ||
}, | ||
], | ||
options: { | ||
payload_limit_mb: 0, | ||
}, | ||
}; | ||
|
||
lightning.on('step:complete', (evt) => { | ||
t.is(evt.payload.output_dataclip_error, 'DATACLIP_TOO_LARGE'); | ||
t.falsy(evt.payload.output_dataclip_id); | ||
t.falsy(evt.payload.output_dataclip); | ||
}); | ||
|
||
lightning.enqueueRun(run); | ||
|
||
lightning.once('run:complete', () => { | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
test.serial( | ||
"Don't send job logs to stdout when job_log_level is set to none", | ||
(t) => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
export const REDACTED_STATE = { | ||
data: '[REDACTED_STATE]', | ||
_$REDACTED$_: true, | ||
}; | ||
|
||
export const REDACTED_LOG = { | ||
message: ['[REDACTED: Message length exceeds payload limit]'], | ||
_$REDACTED$_: true, | ||
}; | ||
|
||
export const verify = (value: any, limit_mb: number = 10) => { | ||
if (value && !isNaN(limit_mb)) { | ||
let size_mb = 0; | ||
try { | ||
const str = typeof value === 'string' ? value : JSON.stringify(value); | ||
const size_bytes = Buffer.byteLength(str, 'utf8'); | ||
size_mb = size_bytes / 1024 / 1024; | ||
} catch (e) { | ||
// do nothing | ||
} | ||
|
||
if (size_mb > limit_mb) { | ||
const e = new Error(); | ||
// @ts-ignore | ||
e.name = 'PAYLOAD_TOO_LARGE'; | ||
e.message = `The payload exceeded the size limit of ${limit_mb}mb`; | ||
throw e; | ||
} | ||
} | ||
}; | ||
|
||
export default (payload: any, limit_mb: number = 10) => { | ||
const newPayload = { ...payload }; | ||
|
||
// The payload could be any of the runtime events | ||
// The bits we might want to redact are state and message | ||
try { | ||
verify(payload.state, limit_mb); | ||
} catch (e) { | ||
newPayload.state = REDACTED_STATE; | ||
newPayload.redacted = true; | ||
} | ||
try { | ||
verify(payload.log, limit_mb); | ||
} catch (e) { | ||
Object.assign(newPayload.log, REDACTED_LOG); | ||
newPayload.redacted = true; | ||
} | ||
return newPayload; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part 1: this file has been moved from the worker to the engine, and lightly modified.
Note that it selectively validates payload objects so that it can generate an appropriate "fix"