-
-
Notifications
You must be signed in to change notification settings - Fork 736
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: unique connection counting #9074
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
Dependency ReviewThe following issues were found:
OpenSSF Scorecard
Scanned Files
|
@@ -66,6 +66,11 @@ export function responseTimeMetrics( | |||
req.query.appName; | |||
} | |||
|
|||
const connectionId = req.headers['x-unleash-connection-id']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is where it starts. on each detected connection id received we let the interested parties know
this.activeHour = new Date().getHours(); | ||
} | ||
|
||
listen() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this service is interested in new connection ids received
|
||
async count(connectionId: string) { | ||
if (!this.flagResolver.isEnabled('uniqueSdkTracking')) return; | ||
this.hll.add(HyperLogLog.hash(connectionId)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this data structure tracks unique connections
@@ -179,4 +180,10 @@ export const scheduleServices = async ( | |||
minutesToMilliseconds(15), | |||
'cleanUpIntegrationEvents', | |||
); | |||
|
|||
schedulerService.schedule( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sync in-memory HyperLogLogs with DB
this.hll.add(HyperLogLog.hash(connectionId)); | ||
} | ||
|
||
async sync(): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this logic will get detailed coverage. We track current and previous HyperLogLog in 2 DB rows. If we found the hour has changed we start a new current bucket and copy current to previous. We have to accommodate for multiple pods where any pod can be the first one to start a current bucket.
( | ||
id VARCHAR(255) NOT NULL, | ||
updated_at TIMESTAMP DEFAULT now(), | ||
hll BYTEA NOT NULL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hyperlog is a buffer that we translate to BYTEA type in postgres
About the changes
E2E POC for unique connection counting using windowed HyperLogLog. We want to know how many unique connections from SDKs we had in the previous hour and in the current hour.
Algorithm:
Followup:
Important files
Discussion points