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-14102] fix api level and endpoint level cache migration #6931

Merged
merged 16 commits into from
Mar 13, 2025

Conversation

edsonmichaque
Copy link
Contributor

@edsonmichaque edsonmichaque commented Mar 10, 2025

User description

TT-14102
Summary [OAS migration] Cache and Advanced Cache combined
Type Bug Bug
Status In Dev
Points N/A
Labels -

Description

This PR ensures that OAS cache is migrated correctly from the classic API. Values are imported from the API-level configuration (lower priority) and/or endpoint-level configurations (higher priority). For timeout, a default value of 60 is used if neither the API-level nor endpoint-level configuration specifies one.

Related Issue

https://tyktech.atlassian.net/browse/TT-14102

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • I ensured that the documentation is up to date
  • I explained why this PR updates go.mod in detail with reasoning why it's required
  • I would like a code coverage CI quality gate exception and have explained why

PR Type

  • Enhancement

Description

  • Added debug logs to trace cache metadata.

  • Logged response codes and timeout values.

  • Aided testing of advanced cache behavior.


Changes walkthrough 📝

Relevant files
Enhancement
mw_redis_cache.go
Add debug logs in Redis cache middleware.                               

gateway/mw_redis_cache.go

  • Inserted log for cacheMeta details.
  • Logged cacheOnlyResponseCodes value.
  • Logged timeout parameter.
  • +5/-0     

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @buger
    Copy link
    Member

    buger commented Mar 10, 2025

    Let's make that PR title a 💯 shall we? 💪

    Your PR title and story title look slightly different. Just checking in to know if it was intentional!

    Story Title [OAS migration] Cache and Advanced Cache combined
    PR Title [TT-14102] fix cache migration

    Check out this guide to learn more about PR best-practices.

    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

    Logging

    Review the newly added logging statements to ensure they are intentional and use an appropriate log level. Excessive debug logging in production could lead to performance issues or unwanted information exposure.

    	log.Printf("CACHE META: %#+v", cacheMeta)
    
    	// override api level Timout by endpoint level if provided
    	if cacheMeta.Timeout > 0 {
    		timeout = cacheMeta.Timeout
    	}
    }
    
    log.Printf("RESPONSE CODES: %#+v", cacheOnlyResponseCodes)
    log.Printf("TIMEOUT: %#+v", timeout)

    Copy link
    Contributor

    github-actions bot commented Mar 10, 2025

    API Changes

    --- prev.txt	2025-03-13 11:49:42.810654206 +0000
    +++ current.txt	2025-03-13 11:49:38.216655683 +0000
    @@ -96,6 +96,8 @@
     )
     const (
     	ResponseProcessorResponseBodyTransform = "response_body_transform"
    +	// DefaultCacheTimeout is the default cache TTL in seconds if not specified for api and endpoint level caching
    +	DefaultCacheTimeout int64 = 60
     )
     
     VARIABLES

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    conditionally log debug info

    Wrap debug logging within a conditional to avoid verbose production logging.

    gateway/mw_redis_cache.go [204-213]

    -log.Printf("CACHE META: %#+v", cacheMeta)
    -log.Printf("RESPONSE CODES: %#+v", cacheOnlyResponseCodes)
    -log.Printf("TIMEOUT: %#+v", timeout)
    +if isDebugEnabled() {
    +	log.Printf("CACHE META: %#+v", cacheMeta)
    +	log.Printf("RESPONSE CODES: %#+v", cacheOnlyResponseCodes)
    +	log.Printf("TIMEOUT: %#+v", timeout)
    +}
    Suggestion importance[1-10]: 6

    __

    Why: The suggestion correctly identifies that wrapping debug log statements in a conditional may prevent unwanted verbosity in production. However, since the logs to be wrapped appear in two different parts of the hunk (line 204 and lines 212–213), applying the change could require additional refactoring; thus, it is a sensible but moderately impactful improvement.

    Low

    @edsonmichaque edsonmichaque changed the title [TT-14102] fix cache migration [TT-14102] fix api level and endpoint level cache migration Mar 11, 2025
    @edsonmichaque edsonmichaque enabled auto-merge (squash) March 13, 2025 13:20
    @edsonmichaque edsonmichaque merged commit 44969bb into master Mar 13, 2025
    40 of 41 checks passed
    @edsonmichaque edsonmichaque deleted the fix/TT-14102-advanced-cache branch March 13, 2025 13:25
    @edsonmichaque
    Copy link
    Contributor Author

    /release to release-5.8

    Copy link

    tykbot bot commented Mar 13, 2025

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

    tykbot bot pushed a commit that referenced this pull request Mar 13, 2025
    ### **User description**
    <details open>
    <summary><a href="https://tyktech.atlassian.net/browse/TT-14102"
    title="TT-14102" target="_blank">TT-14102</a></summary>
      <br />
      <table>
        <tr>
          <th>Summary</th>
          <td>[OAS migration] Cache and Advanced Cache combined</td>
        </tr>
        <tr>
          <th>Type</th>
          <td>
    <img alt="Bug"
    src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium"
    />
            Bug
          </td>
        </tr>
        <tr>
          <th>Status</th>
          <td>In Dev</td>
        </tr>
        <tr>
          <th>Points</th>
          <td>N/A</td>
        </tr>
        <tr>
          <th>Labels</th>
          <td>-</td>
        </tr>
      </table>
    </details>
    <!--
      do not remove this marker as it will break jira-lint's functionality.
      added_by_jira_lint
    -->
    
    ---
    
    <!-- Provide a general summary of your changes in the Title above -->
    
    ## Description
    
    This PR ensures that `OAS` cache is migrated correctly from the
    `classic` API. Values are imported from the API-level configuration
    (lower priority) and/or endpoint-level configurations (higher priority).
    For timeout, a default value of `60` is used if neither the API-level
    nor endpoint-level configuration specifies one.
    
    <!-- Describe your changes in detail -->
    
    ## Related Issue
    
    <!-- This project only accepts pull requests related to open issues. -->
    <!-- If suggesting a new feature or change, please discuss it in an
    issue first. -->
    <!-- If fixing a bug, there should be an issue describing it with steps
    to reproduce. -->
    <!-- OSS: Please link to the issue here. Tyk: please create/link the
    JIRA ticket. -->
    
    https://tyktech.atlassian.net/browse/TT-14102
    
    ## Motivation and Context
    
    <!-- Why is this change required? What problem does it solve? -->
    
    ## How This Has Been Tested
    
    <!-- Please describe in detail how you tested your changes -->
    <!-- Include details of your testing environment, and the tests -->
    <!-- you ran to see how your change affects other areas of the code,
    etc. -->
    <!-- This information is helpful for reviewers and QA. -->
    
    ## Screenshots (if appropriate)
    
    ## Types of changes
    
    <!-- What types of changes does your code introduce? Put an `x` in all
    the boxes that apply: -->
    
    - [ ] Bug fix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Breaking change (fix or feature that would cause existing
    functionality to change)
    - [ ] Refactoring or add test (improvements in base code or adds test
    coverage to functionality)
    
    ## Checklist
    
    <!-- Go over all the following points, and put an `x` in all the boxes
    that apply -->
    <!-- If there are no documentation updates required, mark the item as
    checked. -->
    <!-- Raise up any additional concerns not covered by the checklist. -->
    
    - [ ] I ensured that the documentation is up to date
    - [ ] I explained why this PR updates go.mod in detail with reasoning
    why it's required
    - [ ] I would like a code coverage CI quality gate exception and have
    explained why
    
    
    ___
    
    ### **PR Type**
    - Enhancement
    
    
    
    ___
    
    ### **Description**
    - Added debug logs to trace cache metadata.
    
    - Logged response codes and timeout values.
    
    - Aided testing of advanced cache behavior.
    
    
    ___
    
    
    
    ### **Changes walkthrough** 📝
    <table><thead><tr><th></th><th align="left">Relevant
    files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>mw_redis_cache.go</strong><dd><code>Add debug logs in
    Redis cache middleware.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </dd></summary>
    <hr>
    
    gateway/mw_redis_cache.go
    
    <li>Inserted log for <code>cacheMeta</code> details.<br> <li> Logged
    <code>cacheOnlyResponseCodes</code> value.<br> <li> Logged
    <code>timeout</code> parameter.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6931/files#diff-6266e0dbd16cef89e6de86a2c893114ba07799c804e2138172f9f94b08cdded8">+5/-0</a>&nbsp;
    &nbsp; &nbsp; </td>
    
    </tr>
    </table></td></tr></tr></tbody></table>
    
    ___
    
    > <details> <summary> Need help?</summary><li>Type <code>/help how to
    ...</code> in the comments thread for any questions about PR-Agent
    usage.</li><li>Check out the <a
    href="https://qodo-merge-docs.qodo.ai/usage-guide/">documentation</a>
    for more information.</li></details>
    
    (cherry picked from commit 44969bb)
    Copy link

    tykbot bot commented Mar 13, 2025

    @edsonmichaque Seems like there is conflict and it require manual merge.

    edsonmichaque added a commit that referenced this pull request Mar 13, 2025
    …ache migration (#6931) (#6950)
    
    ### **User description**
    [TT-14102] fix api level and endpoint level cache migration (#6931)
    
    ### **User description**
    <details open>
    <summary><a href="https://tyktech.atlassian.net/browse/TT-14102"
    title="TT-14102" target="_blank">TT-14102</a></summary>
      <br />
      <table>
        <tr>
          <th>Summary</th>
          <td>[OAS migration] Cache and Advanced Cache combined</td>
        </tr>
        <tr>
          <th>Type</th>
          <td>
    <img alt="Bug"
    
    src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium"
    />
            Bug
          </td>
        </tr>
        <tr>
          <th>Status</th>
          <td>In Dev</td>
        </tr>
        <tr>
          <th>Points</th>
          <td>N/A</td>
        </tr>
        <tr>
          <th>Labels</th>
          <td>-</td>
        </tr>
      </table>
    </details>
    <!--
      do not remove this marker as it will break jira-lint's functionality.
      added_by_jira_lint
    -->
    
    ---
    
    <!-- Provide a general summary of your changes in the Title above -->
    
    ## Description
    
    This PR ensures that `OAS` cache is migrated correctly from the
    `classic` API. Values are imported from the API-level configuration
    (lower priority) and/or endpoint-level configurations (higher priority).
    For timeout, a default value of `60` is used if neither the API-level
    nor endpoint-level configuration specifies one.
    
    <!-- Describe your changes in detail -->
    
    ## Related Issue
    
    <!-- This project only accepts pull requests related to open issues. -->
    <!-- If suggesting a new feature or change, please discuss it in an
    issue first. -->
    <!-- If fixing a bug, there should be an issue describing it with steps
    to reproduce. -->
    <!-- OSS: Please link to the issue here. Tyk: please create/link the
    JIRA ticket. -->
    
    https://tyktech.atlassian.net/browse/TT-14102
    
    ## Motivation and Context
    
    <!-- Why is this change required? What problem does it solve? -->
    
    ## How This Has Been Tested
    
    <!-- Please describe in detail how you tested your changes -->
    <!-- Include details of your testing environment, and the tests -->
    <!-- you ran to see how your change affects other areas of the code,
    etc. -->
    <!-- This information is helpful for reviewers and QA. -->
    
    ## Screenshots (if appropriate)
    
    ## Types of changes
    
    <!-- What types of changes does your code introduce? Put an `x` in all
    the boxes that apply: -->
    
    - [ ] Bug fix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Breaking change (fix or feature that would cause existing
    functionality to change)
    - [ ] Refactoring or add test (improvements in base code or adds test
    coverage to functionality)
    
    ## Checklist
    
    <!-- Go over all the following points, and put an `x` in all the boxes
    that apply -->
    <!-- If there are no documentation updates required, mark the item as
    checked. -->
    <!-- Raise up any additional concerns not covered by the checklist. -->
    
    - [ ] I ensured that the documentation is up to date
    - [ ] I explained why this PR updates go.mod in detail with reasoning
    why it's required
    - [ ] I would like a code coverage CI quality gate exception and have
    explained why
    
    
    ___
    
    ### **PR Type**
    - Enhancement
    
    
    
    ___
    
    ### **Description**
    - Added debug logs to trace cache metadata.
    
    - Logged response codes and timeout values.
    
    - Aided testing of advanced cache behavior.
    
    
    ___
    
    
    
    ### **Changes walkthrough** 📝
    <table><thead><tr><th></th><th align="left">Relevant
    
    files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>mw_redis_cache.go</strong><dd><code>Add debug logs in
    Redis cache middleware.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </dd></summary>
    <hr>
    
    gateway/mw_redis_cache.go
    
    <li>Inserted log for <code>cacheMeta</code> details.<br> <li> Logged
    <code>cacheOnlyResponseCodes</code> value.<br> <li> Logged
    <code>timeout</code> parameter.
    
    
    </details>
    
    
      </td>
    <td><a
    
    href="https://github.com/TykTechnologies/tyk/pull/6931/files#diff-6266e0dbd16cef89e6de86a2c893114ba07799c804e2138172f9f94b08cdded8">+5/-0</a>&nbsp;
    &nbsp; &nbsp; </td>
    
    </tr>
    </table></td></tr></tr></tbody></table>
    
    ___
    
    > <details> <summary> Need help?</summary><li>Type <code>/help how to
    ...</code> in the comments thread for any questions about PR-Agent
    usage.</li><li>Check out the <a
    href="https://qodo-merge-docs.qodo.ai/usage-guide/">documentation</a>
    for more information.</li></details>
    
    [TT-14102]:
    https://tyktech.atlassian.net/browse/TT-14102?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
    
    
    ___
    
    ### **PR Type**
    - Bug fix
    - Enhancement
    
    
    
    ___
    
    ### **Description**
    - Migrate simple cache settings to advanced config.
    
    - Introduce helper createAdvancedCacheConfig function.
    
    - Update middleware to apply default cache timeout.
    
    - Add extensive tests and fixtures for cache migration.
    
    
    ___
    
    
    
    ### **Changes walkthrough** 📝
    <table><thead><tr><th></th><th align="left">Relevant
    files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>migration.go</strong><dd><code>Migrate cache config
    using helper function.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    apidef/migration.go
    
    <li>Added DefaultCacheTimeout constant.<br> <li> Replaced basic cache
    migration with createAdvancedCacheConfig.<br> <li> Appended advanced
    cache config to preserve existing settings.<br> <li> Cleared old simple
    cache configuration.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6950/files#diff-e1d9b55a26f9d6225d56d6f0161959217308e5ad4d6934e7d7df4595d9c2a130">+39/-14</a>&nbsp;
    </td>
    
    </tr>
    </table></td></tr><tr><td><strong>Tests</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>migration_test.go</strong><dd><code>Enhance cache
    migration tests.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </dd></summary>
    <hr>
    
    apidef/migration_test.go
    
    <li>Removed outdated TestAPIDefinition_MigrateCachePlugin.<br> <li>
    Added new tests for cache migration behavior.<br> <li> Included tests
    for multiple cache paths and helper function.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6950/files#diff-d79d77f814074b9e483554e36687e22fda759045141c3b094b039428744ff94c">+326/-39</a></td>
    
    </tr>
    
    <tr>
      <td>
        <details>
    <summary><strong>middleware_test.go</strong><dd><code>Add comprehensive
    tests for CachePlugin.Fill.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/middleware_test.go
    
    <li>Introduced multiple tests for CachePlugin.Fill.<br> <li> Covered
    scenarios for default timeout, disabled cache, and regex <br>presence.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6950/files#diff-0af31cb29ae298a6ac3e402b283ab364a6fd793fd04f253ef7c4983234c17bef">+124/-0</a>&nbsp;
    </td>
    
    </tr>
    
    <tr>
      <td>
        <details>
    <summary><strong>cache.yml</strong><dd><code>Add cache fixture for
    integration testing.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </dd></summary>
    <hr>
    
    apidef/oas/testdata/fixtures/cache.yml
    
    <li>Added new cache test fixture configuration.<br> <li> Included
    scenarios for classic and advanced cache entries.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6950/files#diff-3938aa8840266a6527f058f3a7682ef6ce5279ddc3cdbef2be8317f3065beeb6">+98/-0</a>&nbsp;
    &nbsp; </td>
    
    </tr>
    </table></td></tr><tr><td><strong>Bug fix</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>middleware.go</strong><dd><code>Update middleware
    default timeout logic.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/middleware.go
    
    <li>Updated Fill function to set default timeout.<br> <li> Enabled
    default cache timeout if none provided.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6950/files#diff-992ec7c28d25fd54f6491d295389757705cd114bc869a35cba50d42e548cdc6e">+5/-0</a>&nbsp;
    &nbsp; &nbsp; </td>
    
    </tr>
    </table></td></tr></tr></tbody></table>
    
    ___
    
    > <details> <summary> Need help?</summary><li>Type <code>/help how to
    ...</code> in the comments thread for any questions about PR-Agent
    usage.</li><li>Check out the <a
    href="https://qodo-merge-docs.qodo.ai/usage-guide/">documentation</a>
    for more information.</li></details>
    
    Co-authored-by: Edson Michaque <[email protected]>
    @edsonmichaque
    Copy link
    Contributor Author

    /release to release-5.8.0

    Copy link

    tykbot bot commented Mar 13, 2025

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

    tykbot bot pushed a commit that referenced this pull request Mar 13, 2025
    ### **User description**
    <details open>
    <summary><a href="https://tyktech.atlassian.net/browse/TT-14102"
    title="TT-14102" target="_blank">TT-14102</a></summary>
      <br />
      <table>
        <tr>
          <th>Summary</th>
          <td>[OAS migration] Cache and Advanced Cache combined</td>
        </tr>
        <tr>
          <th>Type</th>
          <td>
    <img alt="Bug"
    src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium"
    />
            Bug
          </td>
        </tr>
        <tr>
          <th>Status</th>
          <td>In Dev</td>
        </tr>
        <tr>
          <th>Points</th>
          <td>N/A</td>
        </tr>
        <tr>
          <th>Labels</th>
          <td>-</td>
        </tr>
      </table>
    </details>
    <!--
      do not remove this marker as it will break jira-lint's functionality.
      added_by_jira_lint
    -->
    
    ---
    
    <!-- Provide a general summary of your changes in the Title above -->
    
    ## Description
    
    This PR ensures that `OAS` cache is migrated correctly from the
    `classic` API. Values are imported from the API-level configuration
    (lower priority) and/or endpoint-level configurations (higher priority).
    For timeout, a default value of `60` is used if neither the API-level
    nor endpoint-level configuration specifies one.
    
    <!-- Describe your changes in detail -->
    
    ## Related Issue
    
    <!-- This project only accepts pull requests related to open issues. -->
    <!-- If suggesting a new feature or change, please discuss it in an
    issue first. -->
    <!-- If fixing a bug, there should be an issue describing it with steps
    to reproduce. -->
    <!-- OSS: Please link to the issue here. Tyk: please create/link the
    JIRA ticket. -->
    
    https://tyktech.atlassian.net/browse/TT-14102
    
    ## Motivation and Context
    
    <!-- Why is this change required? What problem does it solve? -->
    
    ## How This Has Been Tested
    
    <!-- Please describe in detail how you tested your changes -->
    <!-- Include details of your testing environment, and the tests -->
    <!-- you ran to see how your change affects other areas of the code,
    etc. -->
    <!-- This information is helpful for reviewers and QA. -->
    
    ## Screenshots (if appropriate)
    
    ## Types of changes
    
    <!-- What types of changes does your code introduce? Put an `x` in all
    the boxes that apply: -->
    
    - [ ] Bug fix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Breaking change (fix or feature that would cause existing
    functionality to change)
    - [ ] Refactoring or add test (improvements in base code or adds test
    coverage to functionality)
    
    ## Checklist
    
    <!-- Go over all the following points, and put an `x` in all the boxes
    that apply -->
    <!-- If there are no documentation updates required, mark the item as
    checked. -->
    <!-- Raise up any additional concerns not covered by the checklist. -->
    
    - [ ] I ensured that the documentation is up to date
    - [ ] I explained why this PR updates go.mod in detail with reasoning
    why it's required
    - [ ] I would like a code coverage CI quality gate exception and have
    explained why
    
    
    ___
    
    ### **PR Type**
    - Enhancement
    
    
    
    ___
    
    ### **Description**
    - Added debug logs to trace cache metadata.
    
    - Logged response codes and timeout values.
    
    - Aided testing of advanced cache behavior.
    
    
    ___
    
    
    
    ### **Changes walkthrough** 📝
    <table><thead><tr><th></th><th align="left">Relevant
    files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>mw_redis_cache.go</strong><dd><code>Add debug logs in
    Redis cache middleware.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </dd></summary>
    <hr>
    
    gateway/mw_redis_cache.go
    
    <li>Inserted log for <code>cacheMeta</code> details.<br> <li> Logged
    <code>cacheOnlyResponseCodes</code> value.<br> <li> Logged
    <code>timeout</code> parameter.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6931/files#diff-6266e0dbd16cef89e6de86a2c893114ba07799c804e2138172f9f94b08cdded8">+5/-0</a>&nbsp;
    &nbsp; &nbsp; </td>
    
    </tr>
    </table></td></tr></tr></tbody></table>
    
    ___
    
    > <details> <summary> Need help?</summary><li>Type <code>/help how to
    ...</code> in the comments thread for any questions about PR-Agent
    usage.</li><li>Check out the <a
    href="https://qodo-merge-docs.qodo.ai/usage-guide/">documentation</a>
    for more information.</li></details>
    
    (cherry picked from commit 44969bb)
    Copy link

    tykbot bot commented Mar 13, 2025

    @edsonmichaque Seems like there is conflict and it require manual merge.

    edsonmichaque added a commit that referenced this pull request Mar 13, 2025
    … cache migration (#6931) (#6951)
    
    ### **User description**
    [TT-14102] fix api level and endpoint level cache migration (#6931)
    
    ### **User description**
    <details open>
    <summary><a href="https://tyktech.atlassian.net/browse/TT-14102"
    title="TT-14102" target="_blank">TT-14102</a></summary>
      <br />
      <table>
        <tr>
          <th>Summary</th>
          <td>[OAS migration] Cache and Advanced Cache combined</td>
        </tr>
        <tr>
          <th>Type</th>
          <td>
    <img alt="Bug"
    
    src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium"
    />
            Bug
          </td>
        </tr>
        <tr>
          <th>Status</th>
          <td>In Dev</td>
        </tr>
        <tr>
          <th>Points</th>
          <td>N/A</td>
        </tr>
        <tr>
          <th>Labels</th>
          <td>-</td>
        </tr>
      </table>
    </details>
    <!--
      do not remove this marker as it will break jira-lint's functionality.
      added_by_jira_lint
    -->
    
    ---
    
    <!-- Provide a general summary of your changes in the Title above -->
    
    ## Description
    
    This PR ensures that `OAS` cache is migrated correctly from the
    `classic` API. Values are imported from the API-level configuration
    (lower priority) and/or endpoint-level configurations (higher priority).
    For timeout, a default value of `60` is used if neither the API-level
    nor endpoint-level configuration specifies one.
    
    <!-- Describe your changes in detail -->
    
    ## Related Issue
    
    <!-- This project only accepts pull requests related to open issues. -->
    <!-- If suggesting a new feature or change, please discuss it in an
    issue first. -->
    <!-- If fixing a bug, there should be an issue describing it with steps
    to reproduce. -->
    <!-- OSS: Please link to the issue here. Tyk: please create/link the
    JIRA ticket. -->
    
    https://tyktech.atlassian.net/browse/TT-14102
    
    ## Motivation and Context
    
    <!-- Why is this change required? What problem does it solve? -->
    
    ## How This Has Been Tested
    
    <!-- Please describe in detail how you tested your changes -->
    <!-- Include details of your testing environment, and the tests -->
    <!-- you ran to see how your change affects other areas of the code,
    etc. -->
    <!-- This information is helpful for reviewers and QA. -->
    
    ## Screenshots (if appropriate)
    
    ## Types of changes
    
    <!-- What types of changes does your code introduce? Put an `x` in all
    the boxes that apply: -->
    
    - [ ] Bug fix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Breaking change (fix or feature that would cause existing
    functionality to change)
    - [ ] Refactoring or add test (improvements in base code or adds test
    coverage to functionality)
    
    ## Checklist
    
    <!-- Go over all the following points, and put an `x` in all the boxes
    that apply -->
    <!-- If there are no documentation updates required, mark the item as
    checked. -->
    <!-- Raise up any additional concerns not covered by the checklist. -->
    
    - [ ] I ensured that the documentation is up to date
    - [ ] I explained why this PR updates go.mod in detail with reasoning
    why it's required
    - [ ] I would like a code coverage CI quality gate exception and have
    explained why
    
    
    ___
    
    ### **PR Type**
    - Enhancement
    
    
    
    ___
    
    ### **Description**
    - Added debug logs to trace cache metadata.
    
    - Logged response codes and timeout values.
    
    - Aided testing of advanced cache behavior.
    
    
    ___
    
    
    
    ### **Changes walkthrough** 📝
    <table><thead><tr><th></th><th align="left">Relevant
    
    files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>mw_redis_cache.go</strong><dd><code>Add debug logs in
    Redis cache middleware.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </dd></summary>
    <hr>
    
    gateway/mw_redis_cache.go
    
    <li>Inserted log for <code>cacheMeta</code> details.<br> <li> Logged
    <code>cacheOnlyResponseCodes</code> value.<br> <li> Logged
    <code>timeout</code> parameter.
    
    
    </details>
    
    
      </td>
    <td><a
    
    href="https://github.com/TykTechnologies/tyk/pull/6931/files#diff-6266e0dbd16cef89e6de86a2c893114ba07799c804e2138172f9f94b08cdded8">+5/-0</a>&nbsp;
    &nbsp; &nbsp; </td>
    
    </tr>
    </table></td></tr></tr></tbody></table>
    
    ___
    
    > <details> <summary> Need help?</summary><li>Type <code>/help how to
    ...</code> in the comments thread for any questions about PR-Agent
    usage.</li><li>Check out the <a
    href="https://qodo-merge-docs.qodo.ai/usage-guide/">documentation</a>
    for more information.</li></details>
    
    [TT-14102]:
    https://tyktech.atlassian.net/browse/TT-14102?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
    
    
    ___
    
    ### **PR Type**
    - Enhancement
    - Tests
    
    
    
    ___
    
    ### **Description**
    - Introduce DefaultCacheTimeout constant and helper function.
    
    - Refactor MigrateCachePlugin to build advanced cache config.
    
    - Enhance CachePlugin.Fill to apply default timeout.
    
    - Add comprehensive tests and fixtures for caching.
    
    
    ___
    
    
    
    ### **Changes walkthrough** 📝
    <table><thead><tr><th></th><th align="left">Relevant
    files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>migration.go</strong><dd><code>Refactor cache migration
    logic with helper function.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </dd></summary>
    <hr>
    
    apidef/migration.go
    
    <li>Add DefaultCacheTimeout constant.<br> <li> Refactor
    MigrateCachePlugin to use createAdvancedCacheConfig.<br> <li> Introduce
    createAdvancedCacheConfig helper.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6951/files#diff-e1d9b55a26f9d6225d56d6f0161959217308e5ad4d6934e7d7df4595d9c2a130">+39/-14</a>&nbsp;
    </td>
    
    </tr>
    
    <tr>
      <td>
        <details>
    <summary><strong>middleware.go</strong><dd><code>Enhance middleware Fill
    with default timeout.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/middleware.go
    
    <li>Update CachePlugin.Fill to assign default timeout.<br> <li> Ensure
    proper handling when caching is enabled.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6951/files#diff-992ec7c28d25fd54f6491d295389757705cd114bc869a35cba50d42e548cdc6e">+5/-0</a>&nbsp;
    &nbsp; &nbsp; </td>
    
    </tr>
    </table></td></tr><tr><td><strong>Tests</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>migration_test.go</strong><dd><code>Add tests for
    advanced cache migration.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    apidef/migration_test.go
    
    <li>Add new tests for cache migration.<br> <li> Test multiple methods
    and configuration scenarios.<br> <li> Introduce
    TestCreateAdvancedCacheConfig.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6951/files#diff-d79d77f814074b9e483554e36687e22fda759045141c3b094b039428744ff94c">+326/-39</a></td>
    
    </tr>
    
    <tr>
      <td>
        <details>
    <summary><strong>middleware_test.go</strong><dd><code>Test enhancement
    for CachePlugin.Fill.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/middleware_test.go
    
    <li>Add tests for CachePlugin.Fill behavior.<br> <li> Validate default
    timeout and response code handling.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6951/files#diff-0af31cb29ae298a6ac3e402b283ab364a6fd793fd04f253ef7c4983234c17bef">+124/-0</a>&nbsp;
    </td>
    
    </tr>
    
    <tr>
      <td>
        <details>
    <summary><strong>cache.yml</strong><dd><code>Add cache configuration
    fixture.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/testdata/fixtures/cache.yml
    
    <li>Add fixture file for cache configuration tests.<br> <li> Define
    multiple advanced cache entries scenarios.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6951/files#diff-3938aa8840266a6527f058f3a7682ef6ce5279ddc3cdbef2be8317f3065beeb6">+98/-0</a>&nbsp;
    &nbsp; </td>
    
    </tr>
    </table></td></tr></tr></tbody></table>
    
    ___
    
    > <details> <summary> Need help?</summary><li>Type <code>/help how to
    ...</code> in the comments thread for any questions about PR-Agent
    usage.</li><li>Check out the <a
    href="https://qodo-merge-docs.qodo.ai/usage-guide/">documentation</a>
    for more information.</li></details>
    
    Co-authored-by: Edson Michaque <[email protected]>
    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