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

feat: makes ip address of request available in application layer #2939

Open
wants to merge 48 commits into
base: main
Choose a base branch
from

Conversation

konstantinabl
Copy link
Collaborator

@konstantinabl konstantinabl commented Sep 4, 2024

Description:

Makes the ip of the sender of a request, available in the application layer. Also makes requestIdPrefix required, since we need to always have it for logging purposes

Related issue(s):

Fixes #2867
Fixes #2940

@konstantinabl konstantinabl force-pushed the 2867-make-the-ip-address-of-the-request-available-in-the-application-layer branch from b81e167 to e946dbf Compare September 4, 2024 12:10
Copy link

github-actions bot commented Sep 4, 2024

Acceptance Tests

0 tests   0 ✔️  0s ⏱️
0 suites  0 💤
0 files    0

Results for commit c7e1ea1.

♻️ This comment has been updated with latest results.

@konstantinabl konstantinabl force-pushed the 2867-make-the-ip-address-of-the-request-available-in-the-application-layer branch 2 times, most recently from fbaf5ca to 2bcdac1 Compare September 9, 2024 13:45
@konstantinabl konstantinabl changed the title Makes ip address of request available in application layer feat: makes ip address of request available in application layer Sep 9, 2024
@konstantinabl konstantinabl added the enhancement New feature or request label Sep 9, 2024
@konstantinabl konstantinabl added this to the 0.56.0 milestone Sep 9, 2024
@konstantinabl konstantinabl force-pushed the 2867-make-the-ip-address-of-the-request-available-in-the-application-layer branch 2 times, most recently from dc0bb30 to 2b4d451 Compare September 9, 2024 17:04
Copy link

github-actions bot commented Sep 9, 2024

Tests

       3 files     272 suites   19s ⏱️
1 276 tests 1 275 ✔️ 1 💤 0
1 288 runs  1 287 ✔️ 1 💤 0

Results for commit 4289cd3.

♻️ This comment has been updated with latest results.

packages/relay/src/lib/poller.ts Outdated Show resolved Hide resolved
packages/relay/src/index.ts Outdated Show resolved Hide resolved
packages/relay/src/lib/clients/mirrorNodeClient.ts Outdated Show resolved Hide resolved
packages/relay/src/lib/types/IRequestDetails.ts Outdated Show resolved Hide resolved
@konstantinabl konstantinabl force-pushed the 2867-make-the-ip-address-of-the-request-available-in-the-application-layer branch 3 times, most recently from 2b1d1d0 to e16946e Compare September 11, 2024 10:22
@konstantinabl konstantinabl self-assigned this Sep 11, 2024
@konstantinabl konstantinabl force-pushed the 2867-make-the-ip-address-of-the-request-available-in-the-application-layer branch 4 times, most recently from 0f4c413 to fe08a97 Compare September 16, 2024 13:18
@victor-yanev victor-yanev mentioned this pull request Sep 16, 2024
2 tasks
@konstantinabl konstantinabl force-pushed the 2867-make-the-ip-address-of-the-request-available-in-the-application-layer branch 4 times, most recently from e4a641d to dd3f2d4 Compare September 17, 2024 10:24
@quiet-node quiet-node modified the milestones: 0.56.0, 0.57.0 Sep 17, 2024
Copy link
Collaborator

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big change.
Left some thoughts

@@ -0,0 +1,150 @@
apiVersion: v1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: please revert this configmap file addition

@@ -106,6 +109,7 @@ export default class KoaJsonRpc {
rpcApp(): (ctx: Koa.Context, _next: Koa.Next) => Promise<void> {
return async (ctx: Koa.Context, _next: Koa.Next) => {
this.requestId = ctx.state.reqId;
this.requestIpAddress = ctx.request.ip;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: should we only set this if the relay operator plans to rate limit by IP?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nana-EC the idea here is that we need this for the hbar limiter and spending plan, so we always want to have the sender's ip in order to check if its a part of the spending plan of a partner. so its not related to rate limiting but hbar limiting and we need it passed to sdkClient and the functions there

const requestDetails = app.getRequestDetails();
logger.debug('Method name: ' + methodName);
logger.debug('Request id: ' + requestDetails.requestId);
logger.debug('Request ip: ' + requestDetails.ipAddress);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop this line for now

const requestIdPrefix = requestId ? formatRequestIdMessage(requestId) : '';
const logAndHandleResponse = async (methodName: string, methodParams: any[], methodFunction: any) => {
const requestDetails = app.getRequestDetails();
logger.debug('Method name: ' + methodName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Squash this into 1 line if needed.
That being said do we need it?
We should have a log that covers the method name no as well as the result

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this was needed for debugging purposes only. will remove it

victor-yanev and others added 18 commits September 20, 2024 13:53
Signed-off-by: Victor Yanev <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Victor Yanev <[email protected]>
Signed-off-by: Victor Yanev <[email protected]>
Signed-off-by: Victor Yanev <[email protected]>
Signed-off-by: Victor Yanev <[email protected]>
Signed-off-by: Victor Yanev <[email protected]>
Signed-off-by: Victor Yanev <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
@konstantinabl konstantinabl force-pushed the 2867-make-the-ip-address-of-the-request-available-in-the-application-layer branch from 1f9c448 to 633e385 Compare September 20, 2024 11:37
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
@konstantinabl konstantinabl marked this pull request as ready for review September 20, 2024 16:10
Copy link

sonarcloud bot commented Sep 20, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
6.5% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

Copy link

codecov bot commented Sep 20, 2024

Codecov Report

Attention: Patch coverage is 74.22907% with 117 lines in your changes missing coverage. Please review.

Project coverage is 78.94%. Comparing base (acd8f4a) to head (c7e1ea1).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/server/src/server.ts 1.19% 83 Missing ⚠️
packages/relay/src/lib/clients/sdkClient.ts 52.00% 12 Missing ⚠️
packages/relay/src/lib/eth.ts 93.24% 10 Missing ⚠️
packages/relay/src/lib/clients/mirrorNodeClient.ts 91.17% 3 Missing ⚠️
packages/server/src/koaJsonRpc/index.ts 40.00% 3 Missing ⚠️
packages/relay/src/lib/poller.ts 60.00% 2 Missing ⚠️
...kages/relay/src/lib/clients/cache/localLRUCache.ts 83.33% 1 Missing ⚠️
packages/relay/src/lib/relay.ts 66.66% 1 Missing ⚠️
.../lib/services/ethService/ethFilterService/index.ts 91.66% 1 Missing ⚠️
...ay/src/lib/services/metricService/metricService.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2939       +/-   ##
===========================================
- Coverage   90.14%   78.94%   -11.20%     
===========================================
  Files          42       60       +18     
  Lines        3185     4027      +842     
  Branches      641      805      +164     
===========================================
+ Hits         2871     3179      +308     
- Misses        270      808      +538     
+ Partials       44       40        -4     
Flag Coverage Δ
23.61% <5.26%> (?)
relay 90.15% <91.50%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/relay/src/formatters.ts 41.78% <ø> (ø)
packages/relay/src/index.ts 100.00% <ø> (ø)
packages/relay/src/lib/clients/cache/redisCache.ts 92.39% <100.00%> (ø)
...barLimiter/ethAddressHbarSpendingPlanRepository.ts 100.00% <100.00%> (ø)
...sitories/hbarLimiter/hbarSpendingPlanRepository.ts 100.00% <100.00%> (ø)
...hbarLimiter/ipAddressHbarSpendingPlanRepository.ts 100.00% <100.00%> (ø)
packages/relay/src/lib/hbarlimiter/index.ts 100.00% <100.00%> (ø)
packages/relay/src/lib/precheck.ts 94.79% <100.00%> (-0.36%) ⬇️
...elay/src/lib/services/cacheService/cacheService.ts 95.48% <100.00%> (ø)
...kages/relay/src/lib/services/debugService/index.ts 80.88% <100.00%> (ø)
... and 15 more

... and 15 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Tasks In Progress
4 participants