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: implement an interface to collect data of tracked users #4826

Merged
merged 10 commits into from
Jul 3, 2024

Conversation

mihir20
Copy link
Contributor

@mihir20 mihir20 commented Jun 20, 2024

Description

  • POC Implementation of MTU tracking

Implementing an interface to collect data of tracked user's userID and anonymousID. This data will used to estimate number of unique users we are tracking. We will not store the raw userIDs and anonymousIDs directly for tracking count. We will store IDs in a probabilistic data structure called HyperLogLog. which will help us to estimate the cardinality.

For some events will have userIDs where user is known and for some events user is not known so we will have anonymousID. for some unknown users earlier which are also known know we will have both userID and anonymousID. Then count of unique users tracked will be equal to no of unique userID + number of unique anonymousID - number of unique combinations of (userID+anonymousID).

Linear Ticket

pipe-1200

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Copy link
Contributor

coderabbitai bot commented Jun 20, 2024

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jun 20, 2024

Codecov Report

Attention: Patch coverage is 78.90625% with 27 lines in your changes missing coverage. Please review.

Project coverage is 74.40%. Comparing base (da8ada7) to head (20004ff).

Files Patch % Lines
enterprise/trackedusers/users_reporter.go 78.90% 14 Missing and 13 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4826      +/-   ##
==========================================
+ Coverage   74.36%   74.40%   +0.04%     
==========================================
  Files         418      419       +1     
  Lines       48998    49126     +128     
==========================================
+ Hits        36435    36553     +118     
- Misses      10183    10184       +1     
- Partials     2380     2389       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mihir20 mihir20 requested a review from lvrach June 20, 2024 10:49
enterprise/trackedusers/data_collector.go Outdated Show resolved Hide resolved
Comment on lines 59 to 67
m := &migrator.Migrator{
Handle: dbHandle,
MigrationsTable: "tracked_users_reports_migrations",
ShouldForceSetLowerVersion: config.GetBool("SQLMigrator.forceSetLowerVersion", true),
}
err = m.Migrate("tracked_users")
if err != nil {
return nil, fmt.Errorf("could not run tracked_users_reports migrations: %w", err)
}
Copy link
Member

Choose a reason for hiding this comment

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

I would avoid running a migration as part of new.

We could instead:

  1. Expose a separate method for running migration. Expecting users of the method to call it.
  2. or use sync.once on CollectData to ensure it run the first time CollectData call was made, but makes error handling a bit more complicated.

We should pass a context to migration as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

migrator currently do not takes context as a param, I can create a new task for adding support for context while running migrations.

enterprise/trackedusers/data_collector.go Outdated Show resolved Hide resolved
@@ -0,0 +1,192 @@
package trackedusers
Copy link
Member

Choose a reason for hiding this comment

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

[subjective] I would go with mtu for package name. As it seems the dominant name used among business and engineering to refer to this feature. It is also short and unique.

Suggested change
package trackedusers
package mtu

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer not to use abbreviations, as when a new person looks at the code he might not know what mtu is. Also want to avoid using monthly as we are not doing anything monthly in the code.

Wanted to keep engineering and business use cases separate as business requirements might change more frequently.

enterprise/trackedusers/data_collector.go Outdated Show resolved Hide resolved
enterprise/trackedusers/data_collector.go Outdated Show resolved Hide resolved
@@ -0,0 +1,192 @@
package trackedusers

//go:generate mockgen -destination=./mocks/mock_data_collector.go -package=mockdatacollector github.com/rudderlabs/rudder-server/enterprise/trackedusers DataCollector
Copy link
Member

Choose a reason for hiding this comment

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

I would avoid using mockgen for now.

It has simple enough interface that makes it easy to create a custom mock. Usually, the generated mock is not very convenient to use, and leading to partial testing in practise.

A good mock for the MTU collector could count the number of unique IDs per workspace per anon/user/identify call. Thus instead of asserting if method was called with the correct arguments, we can test the outcome.

Also consider exposing a NOOP implementation, it would be useful for disabling the functionality and for tests that don't require testing mtu.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in this particular using mocks makes more sense as we just want to make sure that this methods are correctly called with correct parameters in unit tests, additional logic can be tested in integration tests.

enterprise/trackedusers/data_collector.go Outdated Show resolved Hide resolved
Comment on lines 42 to 44
type DataCollector interface {
CollectData(ctx context.Context, jobs []*jobsdb.JobT, tx *txn.Tx) error
}
Copy link
Member

Choose a reason for hiding this comment

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

[subjective]

Suggested change
type DataCollector interface {
CollectData(ctx context.Context, jobs []*jobsdb.JobT, tx *txn.Tx) error
}
type UserTracker interface {
Track(ctx context.Context, tx *txn.Tx, jobs []*jobsdb.JobT) error
}
  • Data is a bit generic, I do prefer the more applicable User term.
  • Track sounds better than Collect, as we do keep any of the jobs rather use them to infer some 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.

Track feels like we are tracking user activity
how about ?

type UsersReporter interface {
	ReportUsers(ctx context.Context, reports []*UsersReport, tx *txn.Tx) error
}

@mihir20 mihir20 requested review from lvrach and ktgowtham June 26, 2024 16:12
enterprise/trackedusers/users_reporter.go Show resolved Hide resolved
enterprise/trackedusers/users_reporter.go Outdated Show resolved Hide resolved
enterprise/trackedusers/users_reporter.go Outdated Show resolved Hide resolved
enterprise/trackedusers/users_reporter.go Outdated Show resolved Hide resolved
enterprise/trackedusers/users_reporter.go Outdated Show resolved Hide resolved
enterprise/trackedusers/users_reporter.go Outdated Show resolved Hide resolved
enterprise/trackedusers/users_reporter_test.go Outdated Show resolved Hide resolved
enterprise/trackedusers/users_reporter_test.go Outdated Show resolved Hide resolved
enterprise/trackedusers/users_reporter_test.go Outdated Show resolved Hide resolved
enterprise/trackedusers/users_reporter_test.go Outdated Show resolved Hide resolved
Copy link
Member

@lvrach lvrach left a comment

Choose a reason for hiding this comment

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

Overall, things look great. I like the approach.

I left some non-blocking comments. I would like to emphasise the ones regarding testing.

@mihir20 mihir20 merged commit 18e4e4f into master Jul 3, 2024
52 checks passed
@mihir20 mihir20 deleted the mihir/pipe-1200 branch July 3, 2024 17:46
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.

None yet

3 participants