-
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
[Fleet] Fix incorrect conversion of string to numeric values in agent YAML #90371
Conversation
… they were strings originally
Pinging @elastic/fleet (Team:Fleet) |
Pinging @elastic/fleet (Feature:Fleet) |
I am wondering if we could fix it when we generate the template if have this kind of template this will not work
Could we escape the string when we generate the template like this ? and does it solve our issue?
|
Good catch @nchaulet, I'll modify the test case...
Do you mean after we compile the template? Could you suggest a way to do this? |
@jen-huang I think it could work with something like this, not sure on the complexity this is adding diff --git a/x-pack/plugins/fleet/server/services/epm/agent/agent.ts b/x-pack/plugins/fleet/server/services/epm/agent/agent.ts
index 6b1d84ea28b..c706f2a5ffe 100644
--- a/x-pack/plugins/fleet/server/services/epm/agent/agent.ts
+++ b/x-pack/plugins/fleet/server/services/epm/agent/agent.ts
@@ -84,6 +84,13 @@ function buildTemplateVariables(variables: PackagePolicyConfigRecord, templateSt
const yamlKeyPlaceholder = `##${key}##`;
varPart[lastKeyPart] = `"${yamlKeyPlaceholder}"`;
yamlValues[yamlKeyPlaceholder] = recordEntry.value ? safeLoad(recordEntry.value) : null;
+ } else if (recordEntry.type && recordEntry.type === 'text') {
+ if (Array.isArray(recordEntry.value)) {
+ varPart[lastKeyPart] = recordEntry.value.map((val) => `"${recordEntry.value}"`);
+ } else {
+ // TODO escape double quote
+ varPart[lastKeyPart] = `"${recordEntry.value}"`;
+ }
} else {
varPart[lastKeyPart] = recordEntry.value;
}
(END) |
@nchaulet Thanks for the suggestion. I'll take a closer look to make sure this works for values which are already strings (and don't need escaping). |
@nchaulet I've adjusted this PR to take most of your suggestion but restricting it to only numeric strings. Could you take another look? |
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.
🚀
💚 Build SucceededMetrics [docs]
History
To update your PR or re-run it, just comment with: |
* master: (55 commits) [APM-UI][E2E] use githubNotify step (elastic#90514) [APM] Export ProcessorEvent type (elastic#90540) [Lens] Retain column config (elastic#90048) [Data Table] Add unit tests (elastic#90173) Migrate most plugins to synchronous lifecycle (elastic#89562) skip flaky suite (elastic#90555) skip flaky suite (elastic#64473) [actions] improve email action doc (elastic#90020) [Fleet] Support Fleet server system indices (elastic#89372) skip flaky suite (elastic#90552) Bump immer dependencies (elastic#90267) Unrevert "Migrations v2: don't auto-create indices + FTR/esArchiver support (elastic#85778)" (elastic#89992) [Search Sessions] Use sync config (elastic#90138) chore(NA): add safe guard to remove bazelisk from yarn global at bootstrap (elastic#90538) [test] Await retry.waitFor (elastic#90456) chore(NA): integrate build buddy with our bazel setup and remote cache for ci (elastic#90116) Skip failing suite (elastic#90526) [Fleet] Fix incorrect conversion of string to numeric values in agent YAML (elastic#90371) [Docs] Update reporting troubleshooting for arm rhel/centos (elastic#90385) chore(NA): build bazel projects all at once in the distributable build process (elastic#90328) ...
Summary
Resolves #89955. If the user enters an all-numeric value for an integration configuration field that should be text, even though Fleet does save the value correctly as a string in the saved object, it ends up as a number instead of string in the final agent yaml. This is due to the way we compile the agent yaml templates and convert it back to a JS object. Here's an example:
This PR adds another condition to our pre-compilation processing of template variables so that all-numeric values which should be treated as strings are escaped with quotes so that the compiled yaml has quotes around the value too.