Skip to content
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

[TT-12871, DX-1784] Add explanation of path ordering before pattern matching #5812

Merged
merged 9 commits into from
Jan 6, 2025

Conversation

andyo-tyk
Copy link
Contributor

@andyo-tyk andyo-tyk commented Dec 9, 2024

DX-1784

Preview Link

https://deploy-preview-5812--tyk-docs.netlify.app/docs/nightly/getting-started/key-concepts/url-matching/#pattern-ordering

Description

Adding explanation of URL ordering algorithm


PR Type

Documentation


Description

  • Added a new section on "Path ordering" to explain how Tyk orders APIs and endpoints before matching requests.
  • Detailed the steps and rules used for ordering, including handling of custom domains, path lengths, and dynamic segments.
  • Included examples to clarify the ordering logic and its impact on routing.
  • Enhanced the explanation of the structure of API requests with a reference to RFC 3986 for better understanding.
  • Improved documentation to help users avoid accidental routing to incorrect endpoints.

Changes walkthrough 📝

Relevant files
Documentation
url-matching.md
Added detailed documentation on path ordering and URL matching.

tyk-docs/content/getting-started/key-concepts/url-matching.md

  • Added explanation for handling similar paths in URL matching.
  • Introduced a new section on "Path ordering" with detailed steps on how
    Tyk orders APIs and endpoints.
  • Provided examples and rules for path ordering and matching logic.
  • Clarified the structure of API requests with a reference to RFC 3986.
  • +26/-1   

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    @andyo-tyk andyo-tyk requested a review from titpetric December 9, 2024 15:49
    @andyo-tyk andyo-tyk changed the title Initial draft [TT-12871] Initial draft Dec 9, 2024
    Copy link

    netlify bot commented Dec 9, 2024

    PS. Pls add /docs/nightly to the end of url

    Name Link
    🔨 Latest commit 2b9c62d
    🔍 Latest deploy log https://app.netlify.com/sites/tyk-docs/deploys/6757119608e58a000826d906
    😎 Deploy Preview https://deploy-preview-5812--tyk-docs.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    1 similar comment
    Copy link

    netlify bot commented Dec 9, 2024

    PS. Pls add /docs/nightly to the end of url

    Name Link
    🔨 Latest commit 2b9c62d
    🔍 Latest deploy log https://app.netlify.com/sites/tyk-docs/deploys/6757119608e58a000826d906
    😎 Deploy Preview https://deploy-preview-5812--tyk-docs.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    @andyo-tyk andyo-tyk requested a review from andrei-tyk December 9, 2024 15:52
    Copy link

    netlify bot commented Dec 9, 2024

    PS. Pls add /docs/nightly to the end of url

    Name Link
    🔨 Latest commit f3ed593
    🔍 Latest deploy log https://app.netlify.com/sites/tyk-docs/deploys/677ba155a491840008f1831d
    😎 Deploy Preview https://deploy-preview-5812--tyk-docs.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    @andyo-tyk andyo-tyk changed the title [TT-12871] Initial draft [TT-12871] Add explanation of path ordering before pattern matching Dec 20, 2024
    @andyo-tyk andyo-tyk marked this pull request as ready for review December 20, 2024 16:51
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Clarity of Path Ordering Explanation

    The newly added "Path ordering" section introduces a detailed explanation of the URL ordering algorithm. It is important to ensure that the explanation is clear, unambiguous, and easy to follow, especially for users unfamiliar with the topic. Verify that the examples provided effectively illustrate the rules and steps described.

    ## Path ordering
    
    Before attempting to [match](#pattern-matching) the incoming request to the various APIs deployed on Tyk to determine which route should be taken, Tyk will first place all the APIs in order. The order is important because the routing logic will compare the incoming request against each in turn until it finds a match (or returns `HTTP 404` if no match is found).
    
    On receipt of an API request Tyk firstly creates a list of all APIs and then iterates through the list for each of the following steps:
    1. APIs that don't have a custom domain defined are moved to the end of the list
    2. Then among each section (custom domain/no custom domain) it will sort by listen path length (longer paths first)
    - note that (dynamic) path parameters are not resolved at this stage so `/api/{category}/user` will rank higher than `/api/123/user`
    3. Then, for each listen path it will sort the endpoints using these rules:
    - remove path parameters (dynamic segments) in the listen path - for example `/{id}` will be replaced with `/`
    - order by the number of segments (count of `/`) from most to least - e.g. `/api/user/profile` before `/api/user`
    - if two endpoints differ only by parameters, the non-parameterized goes first - e.g. `/api/user` before `/api/{userId}`
    - if two endpoints have the same number of segments, the longer path goes first - e.g. `/api/user-access` before `/api/user`
    - for equal length paths, lexicographical order is applied - e.g. `/api/aba` before `/api/abc`
    
    Having created the ordered list, Tyk will attempt to match the request against the paths (patterns) in the list, starting from the top and moving down the list.
    If a match is found, no further checks will be perfomed, so it is important to understand how Tyk orders the patterns to ensure there is no accidental routing to the wrong endpoint.
    

    Copy link
    Contributor

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    @andyo-tyk andyo-tyk changed the title [TT-12871] Add explanation of path ordering before pattern matching [TT-12871, DX-1784] Add explanation of path ordering before pattern matching Dec 20, 2024
    @andyo-tyk andyo-tyk requested a review from sharadregoti January 6, 2025 09:15
    @sharadregoti sharadregoti merged commit f7ce399 into master Jan 6, 2025
    9 checks passed
    @sharadregoti sharadregoti deleted the url-ordering branch January 6, 2025 09:28
    @sharadregoti
    Copy link
    Contributor

    /release to release-5.7

    Copy link

    tykbot bot commented Jan 6, 2025

    Working on it! Note that it can take a few minutes.

    Copy link

    tykbot bot commented Jan 6, 2025

    @sharadregoti Succesfully merged PR

    buger added a commit that referenced this pull request Jan 6, 2025
    …rdering before pattern matching (#5812)
    
    [TT-12871, DX-1784] Add explanation of path ordering before pattern matching (#5812)
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants