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

First integration with rate-limiter service: log warning only #932

Merged
merged 2 commits into from
Aug 29, 2022

Conversation

adshmh
Copy link
Contributor

@adshmh adshmh commented Aug 28, 2022

Signed-off-by: Arash Deshmeh [email protected]

@height
Copy link

height bot commented Aug 28, 2022

This pull request has been linked to and will mark 1 task as "Done" when merged:

💡Tip: You can link multiple Height tasks to a pull request.

@adshmh
Copy link
Contributor Author

adshmh commented Aug 28, 2022

Link T-12166

if (!gigastakeOptions.gigastaked) {
const { shouldLimit, numRateLimitedApps } = await shouldRateLimit(application.id, this.cache)
if (numRateLimitedApps === 0) {
logger.log('warn', 'Rate-limited applications list is empty; rate-limiting disabled')
Copy link
Contributor

Choose a reason for hiding this comment

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

this warn log would appear on each relay in case the list is empty, which can occur large log ingestion charges from our log management system and is something that, from a coding side, we already know if we left the list empty. I recommend to perform the check of existing apps in rate limit in applications.ts and throw the warning there so is made only once

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review. Fixed.

@@ -428,6 +448,20 @@ export class V1Controller {
const applicationID = application.id
const applicationPublicKey = application.gatewayAAT.applicationPublicKey

const { shouldLimit, numRateLimitedApps } = await shouldRateLimit(applicationID, this.cache)
if (numRateLimitedApps === 0) {
logger.log('warn', 'Rate-limited applications list is empty; rate-limiting disabled')
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review. Fixed.

@@ -37,6 +37,7 @@ export class EnvironmentObserver implements LifeCycleObserver {
'INFLUX_ORG',
'ARCHIVAL_CHAINS',
'BLOCKED_ADDRESSES_URL',
'RATE_LIMITER_URL',
Copy link
Contributor

Choose a reason for hiding this comment

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

is this truly required? should rate limiter be on by default or should it be a toggle?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This allows:

  1. Configuration of new endpoint for rate-limiter if necessary
  2. Toggling rate-limiter on/off if any potentially urgent issues arise.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not providing the env there will cause an error on the api (as envs declared there must be provided) so I don't see how can it be toggle from there. There's another array on that same file of optional envs, you could add it to that array and check for that in applications.ts as is the file where services are boostraped and check on api boot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review. Fixed.

} as AxiosRequestConfig

const { data } = await axios(axiosConfig)
const { ApplicationIDs: rateLimitedAppsList } = data
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const { ApplicationIDs: rateLimitedAppsList } = data
const { applicationIDs: rateLimitedAppsList } = data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has to stay upper-case to match the output of rate-limiter(otherwise we will miss the output)

Copy link
Contributor

Choose a reason for hiding this comment

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

All right

return obj
}

const url = process.env.RATE_LIMITER_URL ?? ''
Copy link
Contributor

Choose a reason for hiding this comment

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

the portal-api usually reads the url as a global variable in top of the file or is passed as a function, I personally prefer the later as is more clear where the value is coming from but I recommend one of the two for consistency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review. Fixed.

@adshmh adshmh force-pushed the rate-limiter-integration-in-log-only-mode branch from 0efd069 to 3781bf4 Compare August 29, 2022 16:22
@rem1niscence
Copy link
Contributor

Lgtm

@kutoft
Copy link

kutoft commented Sep 2, 2022

Close T-12166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants