-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[APM] Encode spaces when creating ML job #63683
Conversation
Closes elastic#62370. Per https://github.com/elastic/elasticsearch/blob/95a7eed9aa35f47b228e402508709b5bd6703cf4/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlStrings.java#L20-L26, spaces are not supported in job and group ids.
💚 Build SucceededTo update your PR or re-run it, just comment with: |
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.
LGTM
Closes elastic#62370. Per https://github.com/elastic/elasticsearch/blob/95a7eed9aa35f47b228e402508709b5bd6703cf4/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlStrings.java#L20-L26, spaces are not supported in job and group ids.
* master: (40 commits) [APM]Upgrade apm-rum agent to latest version to fix full page reload (elastic#63723) add deprecation warning for legacy 3rd party plugins (elastic#62401) Migrate timelion vis (elastic#62819) Replacebad scope link with actual values (elastic#63444) Index pattern management UI -> TypeScript and New Platform Ready (create_index_pattern_wizard) (elastic#63111) [SIEM] Threat hunting enhancements: Filter for/out value, Show top field, Copy to Clipboard, Draggable chart legends (elastic#61207) [Maps] fix term join agg key collision (elastic#63324) [Ingest] Fix agent config key sorting (elastic#63488) [Monitoring] Fixed server response errors (elastic#63181) update elastic charts to 18.3.0 (elastic#63732) Start services (elastic#63720) [APM] Encode spaces when creating ML job (elastic#63683) Uptime 7.7 docs (elastic#62228) [DOCS] Updates remote cluster and ccr docs (elastic#63517) [Maps] Add 3rd party vector tile support (elastic#62084) [Endpoint][EPM] Retrieve Index Pattern from Ingest Manager (elastic#63016) [Endpoint] Host Details Policy Response Panel (elastic#63518) [Uptime] Certificate expiration threshold settings (elastic#63682) Refactor saved object types to use `namespaceType` (elastic#63217) [SIEM][CASE] Create comments sequentially (elastic#63692) ...
Closes #62370. Per https://github.com/elastic/elasticsearch/blob/95a7eed9aa35f47b228e402508709b5bd6703cf4/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlStrings.java#L20-L26, spaces are not supported in job and group ids.
@@ -16,3 +16,7 @@ export function getMlJobId(serviceName: string, transactionType?: string) { | |||
export function getMlIndex(serviceName: string, transactionType?: string) { | |||
return `.ml-anomalies-${getMlJobId(serviceName, transactionType)}`; | |||
} | |||
|
|||
export function encodeForMlApi(value: string) { | |||
return value.replace(/\s+/g, '_').toLowerCase(); |
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.
What about using encodeURIComponent
? With this change service a
and service_a
are now the same (although it's very much an edge case).
Btw. A comment would probably be useful later (eg. "ML doesn't allow spaces in group
properties")
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.
Btw. are there other characters that we should be aware of that ML doesn't support?
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 didn't consider that! But unfortunately %
is not supported either. Not sure how we could solve this issue. See https://github.com/elastic/elasticsearch/blob/95a7eed9aa35f47b228e402508709b5bd6703cf4/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlStrings.java#L20-L26 for the regex.
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.
Ah, okay. Not sure how to fix then. Let's leave it for now.
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 is the function we use to validate an ML job/group ID in the UI.
export function isJobIdValid(jobId) { |
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.
Thanks for chiming in @jgowdyelastic.
We use a slightly more liberal regex: ^[a-zA-Z0-9 _-]+$
(alphanumeric characters, spaces, underscores, and dashes).
https://www.elastic.co/guide/en/apm/get-started/current/agents.html#choose-service-name
// it must also start and end with an alphanumeric character'
Sounds like we might run into problems with service names that start or end with non-alphanumeric character eg. service-a-
or _internal_service
.
Either we should find a fix on our side, or perhaps you can allow this?
What's the background for this limitation?
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.
There are a few reasons why we don't allow non-alphanumeric chars at the start and end of the ID. They are mainly to do with the ID being used as part of our endpoint URIs.
We follow elasticsearch's naming convention and do now allow -
or _
a the start. .
is use for "hidden" indices etc.
Some url parsing systems don't like .
chars at the end, e.g. slack will not auto add it to a link.
It's reasons like this why we've gone with this fairly strict rule.
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.
Makes sense. I don't anticipate that this will be common in service names either but currently we do allow it meaning we'll have to handle it somehow.
The easy solution would be to strip non-alphanumeric chars at the beginning and end, but that would create the same problem as I mentioned before, where _service-A
and service-A
are now identical (very edge casey as well)
Tested:
|
Closes #62370.
Per https://github.com/elastic/elasticsearch/blob/95a7eed9aa35f47b228e402508709b5bd6703cf4/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlStrings.java#L20-L26, spaces are not supported in job and group ids.