Apply new uri to resource normalization rules#928
Merged
Conversation
…or private functions
labbati
commented
Jun 19, 2020
| return array_map( | ||
| function ($entry) { | ||
| return strtolower(trim($entry)); | ||
| return trim($entry); |
Member
Author
There was a problem hiding this comment.
This is a generic getter and should not make assumptions about case sensitive vs case insensitive. Also, this function was not used by other settings so it is good to be changed as it is only used by the newly added functions.
…path fragment regex
SammyK
reviewed
Jun 19, 2020
SammyK
reviewed
Jun 22, 2020
SammyK
approved these changes
Jun 22, 2020
Merged
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR provide a new method to customize uri to resource mapping.
Problem
Http requests that corresponds to URI
GET http://example.com/user/123/permissionshas a resource name in the format ofGET /user/?/permissions. Identifying the variable part123and converting it into?is what we call resource normalization. With resource normalization in place we make sure that requests toGET http://example.com/user/123/permissionsandGET http://example.com/user/456/permissionsare grouped under the very same resource nameGET http://example.com/user/?/permissionsin our UI.We adopt 2 strategies to normalize
GET /user/123/permissionsintoGET /user/?/permissions:There are 2 use cases that the above strategies do not fully cover:
Assume you have the following set of uris
/always/using/<7 CHARS HEX>/as/id/everywhere/always/using/?/as/id/everywhere/cities/london/rivers/cities/?/rivers/articles/slug-of-title/articles/?This PR offers the possibility to cover the remaining cases above via new settings.
DD_TRACE_RESOURCE_URI_FRAGMENT_REGEX: lets you provide a list of regex that are applied to every FULL path fragment. By FULL path fragment we mean what is inside to/chars in a uri path. E.g. in/cities/london/riverswe have three path fragments:cities,london,rivers. A list of regexes can be provided separated by comma,. With env you would address the first use case.DD_TRACE_RESOURCE_URI_FRAGMENT_REGEX=^[a-f0-9]{7}$will find and replace ALL path fragments that are a 7 chars HEX word with?.This setting applies to both incoming and outgoing requests.
DD_TRACE_RESOURCE_URI_MAPPING_INCOMING: lets you cover the cases when you cannot provide a regex (e.g. to normalizelondonandrome) but you know that a given identifier appears always after a known word, e.g. in this casecities. In this case you would normalize the latter two examples in the table above viaDD_TRACE_RESOURCE_URI_MAPPING_INCOMING=cities/*,articles/*. Note that in this case the provided values are NOT regexes, but they recognize the*replacement char.DD_TRACE_RESOURCE_URI_MAPPING_OUTGOING: Same asDD_TRACE_RESOURCE_URI_MAPPING_INCOMINGbut for outgoing requests.*NOTE: THIS PR DEPRECATES SETTING
DD_TRACE_RESOURCE_URI_MAPPINGReadiness checklist
Reviewer checklist