wso2 / carbon-apimgt

Apache License 2.0
165 stars 623 forks source link

Add userIP to faulty event #12296

Closed msm1992 closed 4 months ago

msm1992 commented 5 months ago

Fixes https://github.com/wso2/api-manager/issues/2504

When a request is failed due to a reason such as authentication failure, we do not log the user IP (X-forwarded header). With this PR the userIP is also added to faulty event response.

Without the fix

INFO ELKCounterMetric apimMetrics: apim:faulty, properties :{"apiName":"PizzaShackAPI","requestTimestamp":"2024-02-22T04:06:48.593Z","proxyResponseCode":401,"errorType":"AUTH","applicationOwner":"UNKNOWN","errorMessage":"AUTHENTICATION_FAILURE","errorCode":900902,"apiCreatorTenantDomain":"carbon.super","apiVersion":"1.0.0","gatewayType":"SYNAPSE","apiCreator":"admin","responseCacheHit":false,"regionId":"default","correlationId":"69f0ca19-3e38-4b5c-8da5-81bb4fa2a485","keyType":"UNKNOWN","applicationId":"UNKNOWN","apiId":"135cd373-56bd-4d50-952f-207bc4833fbf","apiType":"HTTP","applicationName":"UNKNOWN","targetResponseCode":-1}

With the fix

INFO ELKCounterMetric apimMetrics: apim:faulty, properties :{"apiName":"PizzaShackAPI","requestTimestamp":"2024-02-22T04:14:58.433Z","proxyResponseCode":401,"errorType":"AUTH","applicationOwner":"UNKNOWN","errorMessage":"AUTHENTICATION_FAILURE","errorCode":900902,"apiCreatorTenantDomain":"carbon.super","apiVersion":"1.0.0","gatewayType":"SYNAPSE","apiCreator":"admin","responseCacheHit":false,"regionId":"default","userIp":"127.0.0.1","correlationId":"aedea4be-0c18-4ae1-820d-ef08ce35cb7a","keyType":"UNKNOWN","applicationId":"UNKNOWN","apiId":"135cd373-56bd-4d50-952f-207bc4833fbf","apiType":"HTTP","applicationName":"UNKNOWN","properties":{},"targetResponseCode":-1}
codecov[bot] commented 5 months ago

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 47.68%. Comparing base (9390981) to head (0e012fb).

Files Patch % Lines
...cs/collectors/impl/FaultyRequestDataCollector.java 0.00% 4 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #12296 +/- ## ============================================ + Coverage 41.99% 47.68% +5.69% - Complexity 3260 4149 +889 ============================================ Files 1839 1839 Lines 135650 135654 +4 Branches 19593 19594 +1 ============================================ + Hits 56963 64690 +7727 + Misses 71826 63387 -8439 - Partials 6861 7577 +716 ``` | [Flag](https://app.codecov.io/gh/wso2/carbon-apimgt/pull/12296/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=wso2) | Coverage Δ | | |---|---|---| | [integration_tests](https://app.codecov.io/gh/wso2/carbon-apimgt/pull/12296/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=wso2) | `42.44% <0.00%> (+7.11%)` | :arrow_up: | | [unit_tests](https://app.codecov.io/gh/wso2/carbon-apimgt/pull/12296/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=wso2) | `20.56% <ø> (-0.01%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=wso2#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.