### **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)
<img width="1243" alt="Screenshot 2024-05-23 at 17 08 11"
src="https://github.com/TykTechnologies/tyk/assets/31618778/3cdd5f66-60ea-47e2-83be-6be229ac6c8d">
<img width="1244" alt="Screenshot 2024-05-23 at 17 08 24"
src="https://github.com/TykTechnologies/tyk/assets/31618778/2eaa844c-9ceb-46ed-9c34-aa841ea2745a">
<img width="1242" alt="Screenshot 2024-05-23 at 17 08 44"
src="https://github.com/TykTechnologies/tyk/assets/31618778/5a88b36d-eceb-4752-9e53-1cf812417954">
<img width="1240" alt="Screenshot 2024-05-23 at 17 10 32"
src="https://github.com/TykTechnologies/tyk/assets/31618778/60b7e298-30dc-4b7a-bb53-e02d5f8550d9">
## 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)
- [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
<!-- 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**
- 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** 📝
<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>coprocess.go</strong><dd><code>Add `cached` parameter
to `RecordHit` function call.</code>
</dd></summary>
<hr>
gateway/coprocess.go
- Updated `RecordHit` function call to include a `cached` parameter.
</details>
</td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6308/files#diff-9cbfe628982b2afb94d1e9a5200fc9a4fdc00cb58fe65d1090a3725e4e4c5953">+1/-1</a>
</td>
</tr>
<tr>
<td>
<details>
<summary><strong>handler_success.go</strong><dd><code>Enhance
`RecordHit` function to tag cached responses.</code>
</dd></summary>
<hr>
gateway/handler_success.go
<li>Modified <code>RecordHit</code> function to accept a
<code>cached</code> parameter.<br> <li> Added logic to append
<code>cached-response</code> tag if <code>cached</code> is true.<br>
<li> Updated <code>ServeHTTP</code> and <code>ServeHTTPWithCache</code>
functions to call <code>RecordHit</code> <br>with <code>cached</code>
parameter.<br>
</details>
</td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6308/files#diff-45135957493eca37f2e3e9a81079577777133c53b27cf95ea2ff0329c05bd006">+7/-3</a>
</td>
</tr>
<tr>
<td>
<details>
<summary><strong>mw_go_plugin.go</strong><dd><code>Add `cached`
parameter to `RecordHit` function call.</code>
</dd></summary>
<hr>
gateway/mw_go_plugin.go
- Updated `RecordHit` function call to include a `cached` parameter.
</details>
</td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6308/files#diff-0f31abef73bf795e1a8d331202330c73011a74d10fd66e49b9359716a6d18fd9">+1/-1</a>
</td>
</tr>
<tr>
<td>
<details>
<summary><strong>mw_redis_cache.go</strong><dd><code>Tag responses from
Redis cache as cached.</code>
</dd></summary>
<hr>
gateway/mw_redis_cache.go
<li>Updated <code>RecordHit</code> function call to include a
<code>cached</code> parameter set to <br>true.<br>
</details>
</td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6308/files#diff-6266e0dbd16cef89e6de86a2c893114ba07799c804e2138172f9f94b08cdded8">+1/-1</a>
</td>
</tr>
<tr>
<td>
<details>
<summary><strong>mw_virtual_endpoint.go</strong><dd><code>Add `cached`
parameter to `RecordHit` function call.</code>
</dd></summary>
<hr>
gateway/mw_virtual_endpoint.go
- Updated `RecordHit` function call to include a `cached` parameter.
</details>
</td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6308/files#diff-daf72ac3b29609a9f2a77cccf648f91ba62b2ad977a7c5a44602c72b2a28b2e5">+1/-1</a>
</td>
</tr>
</table></td></tr></tr></tbody></table>
___
> 💡 **PR-Agent usage**:
>Comment `/help` on the PR to get a list of all available PR-Agent tools
and their descriptions
Co-authored-by: joshblakeley <[email protected]>
Co-authored-by: Sredny M <[email protected]>
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
Screenshots (if appropriate)
Types of changes
Checklist
PR Type
Enhancement
Description
RecordHitfunction to accept acachedparameter.cached-responseif they are served from the cache.cachedparameter toRecordHit.Changes walkthrough 📝
coprocess.go
Add `cached` parameter to `RecordHit` function call.gateway/coprocess.go
RecordHitfunction call to include acachedparameter.handler_success.go
Enhance `RecordHit` function to tag cached responses.gateway/handler_success.go
RecordHitfunction to accept acachedparameter.cached-responsetag ifcachedis true.ServeHTTPandServeHTTPWithCachefunctions to callRecordHitwith
cachedparameter.mw_go_plugin.go
Add `cached` parameter to `RecordHit` function call.gateway/mw_go_plugin.go
RecordHitfunction call to include acachedparameter.mw_redis_cache.go
Tag responses from Redis cache as cached.gateway/mw_redis_cache.go
RecordHitfunction call to include acachedparameter set totrue.
mw_virtual_endpoint.go
Add `cached` parameter to `RecordHit` function call.gateway/mw_virtual_endpoint.go
RecordHitfunction call to include acachedparameter.