-
Notifications
You must be signed in to change notification settings - Fork 1
Fix appName option and count billing events via dailyEvents #575
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
Open
Kuchizu
wants to merge
4
commits into
master
Choose a base branch
from
perf/mongo-optimizations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+392
−20
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0516eb3
Fix appName option ignored by mongodb driver 3.x
Kuchizu 244212d
Count billing events via dailyEvents daily counters
Kuchizu a7dcbb6
Fix limiter worker tests for boundary-day counting
Kuchizu 12ee807
Add opt-in dailyEvents limiter counter
Kuchizu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,12 @@ const NOTIFY_ABOUT_LIMIT = [ | |
| 0.95, | ||
| ]; | ||
|
|
||
| /** | ||
| * Enables dailyEvents-based quota counting for listed workspaces. | ||
| * Use comma-separated workspace ids or `*` to enable it for every workspace. | ||
| */ | ||
| const DAILY_EVENTS_COUNTER_WORKSPACE_IDS = process.env.LIMITER_DAILY_EVENTS_COUNTER_WORKSPACE_IDS || ''; | ||
|
|
||
| /** | ||
| * Worker for checking current total events count in workspaces and limits events receiving if workspace exceed the limit | ||
| */ | ||
|
|
@@ -266,7 +272,7 @@ export default class LimiterWorker extends Worker { | |
|
|
||
| const since = Math.floor(new Date(workspace.lastChargeDate).getTime() / MS_IN_SEC); | ||
|
|
||
| const workspaceEventsCount = await this.dbHelper.getEventsCountByProjects(projects, since); | ||
| const workspaceEventsCount = await this.getWorkspaceEventsCount(workspace, projects, since); | ||
|
|
||
| this.logger.info(`workspace ${workspace._id} events count since last charge date: ${workspaceEventsCount}`); | ||
|
|
||
|
|
@@ -328,6 +334,48 @@ export default class LimiterWorker extends Worker { | |
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Returns workspace events count using the default raw counter or the | ||
| * dailyEvents-based counter when it is explicitly enabled for the workspace. | ||
| * | ||
| * @param workspace - workspace to count events for | ||
| * @param projects - workspace projects | ||
| * @param since - timestamp of the time from which we count the events | ||
| */ | ||
| private async getWorkspaceEventsCount( | ||
| workspace: WorkspaceWithTariffPlan, | ||
| projects: ProjectDBScheme[], | ||
| since: number | ||
| ): Promise<number> { | ||
| if (!this.shouldUseDailyEventsCounter(workspace._id.toString())) { | ||
| return this.dbHelper.getEventsCountByProjects(projects, since); | ||
| } | ||
|
Comment on lines
+350
to
+352
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets compute both counters for such workspaces to be able to compare them. |
||
|
|
||
| try { | ||
| return await this.dbHelper.getEventsCountByProjectsUsingDailyEvents(projects, since); | ||
| } catch (error) { | ||
| HawkCatcher.send(error, { | ||
| workspaceId: workspace._id.toString(), | ||
| }); | ||
|
|
||
| return this.dbHelper.getEventsCountByProjects(projects, since); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Checks whether dailyEvents-based quota counting is enabled for the workspace. | ||
| * | ||
| * @param workspaceId - workspace id | ||
| */ | ||
| private shouldUseDailyEventsCounter(workspaceId: string): boolean { | ||
| const enabledWorkspaceIds = DAILY_EVENTS_COUNTER_WORKSPACE_IDS | ||
| .split(',') | ||
| .map(id => id.trim()) | ||
| .filter(Boolean); | ||
|
|
||
| return enabledWorkspaceIds.includes('*') || enabledWorkspaceIds.includes(workspaceId); | ||
| } | ||
|
|
||
| /** | ||
| * Method that formats project list to html used in report messages | ||
| * | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.