-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Synthetics] Template string syntax breaks inline monitors when running against the service #176094
base: main
Are you sure you want to change the base?
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
e5743d5
to
668ae4c
Compare
/oblt-deploy |
1 similar comment
/oblt-deploy |
668ae4c
to
d0f96d9
Compare
Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services) |
x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.ts
Outdated
Show resolved
Hide resolved
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.
Code LGTM
7da0905
to
45246c2
Compare
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.
I just checked the core zip part, added some comments. Mostly LGTM
const locMonitors = await Promise.all( | ||
bucketsByLocation[location.id].splice(0, PER_PAGE).map(async (monitorData) => { | ||
// no inline script data, sync without further processing | ||
if (!monitorData?.['source.inline.script']) return monitorData; |
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.
ques: why are we not setting [ConfigKey.SOURCE_INLINE]: undefined
here?
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.
Fair question - in this case there is no inline script so there's no reason to modify the monitor in any way.
This means it's either lightweight or already a project monitor, so basically we let those objects pass through unchanged.
…ail-to-run-migrate-to-project-monitor
…ail-to-run-migrate-to-project-monitor
x-pack/plugins/observability_solution/synthetics/server/common/inline_to_zip.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/observability_solution/synthetics/server/common/inline_to_zip.ts
Show resolved
Hide resolved
x-pack/plugins/observability_solution/synthetics/server/common/inline_to_zip.ts
Show resolved
Hide resolved
x-pack/plugins/observability_solution/synthetics/server/common/inline_to_zip.ts
Show resolved
Hide resolved
b0060b1
to
7d6ae2b
Compare
This reverts commit 716c2b2.
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.
Bundling part LGTM
…ail-to-run-migrate-to-project-monitor
…ail-to-run-migrate-to-project-monitor
/oblt-deploy |
…ail-to-run-migrate-to-project-monitor
…ail-to-run-migrate-to-project-monitor
…ail-to-run-migrate-to-project-monitor
💔 Build Failed
Failed CI StepsTest Failures
Metrics [docs]History
|
Summary
Fixes #169963.
Code is in WIP state.Makes it so inline monitor scripts can make use of JavaScript template strings.
This PR will migrate data from the inline fields to use the project fields instead. This approach combined with b64 encoding will allow us to avoid the instance where we try to put JS template strings in dynamic YML, which breaks the YML syntax.
Testing instructions
Pre-requisites
Testing the fix
This covers the fix for the bug. As part of this patch, we also made some changes to the ways monitors are stored/transmitted to the service. I'll add more detail in a footnote section below explaining what we did and why. The TLDR; of this, however is: we need to verify the add/edit functionality still works after these changes.
Verify edits still work
Feel free to do any additional checking you might think is appropriate.
Additional testing note
I left it off the main testing instructions because it's significantly more effort to set up, but an important code path to test is for an existing, failing monitor, to be fixed by this change. To perform this test, I created a local Stack hitting a locally-running Synthetics Service. I made a monitor with template strings that would fail, and verified it broke on my local service:
Then, I swapped Kibana into this branch and verified that after its next sync, the monitor succeeded:
In this case, the monitor data is never being stored as zipped, but the pre-existing script is being zipped on the fly before the monitor is transmitted to the service.
Why and How does this work
On the Agent side of this bug, Heartbeat generates dynamic YAML when executing inline journeys. Unfortunately, there's no easy way to escape template strings users add in JS code for inline monitors, and this breaks the YAML syntax when Heartbeat tries to parse the config code.
The workaround is to use a field normally reserved for project monitors. This patch takes the user-provided script content and zips/b64-encodes it, storing that data in the project source field we normally use for a project. When we transmit the monitor data for an inline test run, Kibana now drops the plaintext monitor script and only transmits the zipped data. When Heartbeat evaluates the fields it receives, it will treat the monitor as a project and execute it in a different manner, thus un-breaking this bug.
We elected to zip the data for inline monitors in the persist stage to avoid requiring the Kibana server to handle the added burden of re-zipping all inline monitors every time it proceeds to transmit them. In the worst case this could be 250 monitors per transmission, and we'd be re-zipping and re-encoding them each time Kibana sync'd with the service.
One caveat to this change is that it is not retroactive. For any existing inline monitor that is not zipped at the time this code starts to run, the Kibana server will be required to perform the zip at transmission time, until the monitor is edited again.
Checklist
Delete any items that are not applicable to this PR.
For maintainers