tyk icon indicating copy to clipboard operation
tyk copied to clipboard

feat/TT-9462/tag-cached-response

Open joshblakeley opened this issue 9 months ago • 5 comments

User description

Description

For users of our redis cache there is currently no simple way to slice the analytics or log data in the dashboard by whether that traffic is cached from Tyk or not.

This feat adds a simple case that adds the tag "cached-response" anytime a response is served from our redis cache.

Related Issue

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

How This Has Been Tested

  1. Create API and enable caching - all safe request or per endpoint is a good option to test. It doesnt not make any difference which you choose.
  2. send more than one request to the API
  3. Check analytics and logs in Tyk dashboard, you can filter graphs by tag "cached-response" to split cached and non cached counters
  4. Check log browser, response will contain "cached-response" tag when the cache hit occurs

Screenshots (if appropriate)

Screenshot 2024-05-23 at 17 08 11 Screenshot 2024-05-23 at 17 08 24 Screenshot 2024-05-23 at 17 08 44 Screenshot 2024-05-23 at 17 10 32

Types of changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] 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

  • Enhanced the RecordHit function to accept a cached parameter.
  • Added logic to tag responses with cached-response if they are served from the cache.
  • Updated various middleware components to pass the cached parameter to RecordHit.

Changes walkthrough 📝

Relevant files
Enhancement
coprocess.go
Add `cached` parameter to `RecordHit` function call.         

gateway/coprocess.go

  • Updated RecordHit function call to include a cached parameter.
+1/-1     
handler_success.go
Enhance `RecordHit` function to tag cached responses.       

gateway/handler_success.go

  • Modified RecordHit function to accept a cached parameter.
  • Added logic to append cached-response tag if cached is true.
  • Updated ServeHTTP and ServeHTTPWithCache functions to call RecordHit
    with cached parameter.
  • +7/-3     
    mw_go_plugin.go
    Add `cached` parameter to `RecordHit` function call.         

    gateway/mw_go_plugin.go

    • Updated RecordHit function call to include a cached parameter.
    +1/-1     
    mw_redis_cache.go
    Tag responses from Redis cache as cached.                               

    gateway/mw_redis_cache.go

  • Updated RecordHit function call to include a cached parameter set to
    true.
  • +1/-1     
    mw_virtual_endpoint.go
    Add `cached` parameter to `RecordHit` function call.         

    gateway/mw_virtual_endpoint.go

    • Updated RecordHit function call to include a cached parameter.
    +1/-1     

    💡 PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    joshblakeley avatar May 23 '24 16:05 joshblakeley