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(experiments): add mgmt cmd to generate experiment data #26770

Merged
merged 10 commits into from
Dec 20, 2024

Conversation

andehen
Copy link
Contributor

@andehen andehen commented Dec 9, 2024

Problem

make it easy to generate data with known statistics.

It can be further improved, but it's already very useful so I would like to merge this to master as I use it a lot already.
Then we can iterate from there.

Changes

added mgmt cmd that generates events, so now you can do

 ./manage.py generate_experiment_data --type funnel --experiment-id funnel-test-1
 ./manage.py generate_experiment_data --type trends --experiment-id trends-test-1

to generate with the default configs.

Or you can do

./manage.py generate_experiment_data --type funnel --init-config funnel-conf.json
./manage.py generate_experiment_data --config exp-conf.json --experiment-id funnel-test

the json conf file can easily be edited to suite your test purpose.

the default currently looks like this:

{
  "number_of_users": 1000,
  "start_timestamp": "2024-12-03T07:04:51.286943",
  "end_timestamp": "2024-12-10T07:04:51.286949",
  "variants": {
    "control": {
      "weight": 0.5,
      "actions": [
        {
          "event": "$pageview",
          "count": 1,
          "probability": 0.75
        }
      ]
    },
    "test": {
      "weight": 0.5,
      "actions": [
        {
          "event": "$pageview",
          "count": 1,
          "probability": 1.0
        }
      ]
    }
  }
}

How did you test this code?

  • ran the cmd and tested with this query in clickhouse
SELECT 
	properties_group_feature_flags['$feature/test-1'] as variant,
	event,
	count(*)
FROM events
WHERE mapContains(properties_group_feature_flags, '$feature/test-1)
GROUP BY all;
  • used product analytics to visualize the funnel and verified that the numbers added up
  • verified by looking at experiment results
Screenshot 2024-12-18 at 11 27 05

@andehen andehen changed the title feat(experiments): add mgmt cmd to mock experiment data feat(experiments): add mgmt cmd to generate experiment test data Dec 10, 2024
@danielbachhuber
Copy link
Contributor

Nice!

What do you think about including a few sample configurations too, so you don't necessarily have to futz with a JSON file each time?

@andehen
Copy link
Contributor Author

andehen commented Dec 10, 2024

Nice!

What do you think about including a few sample configurations too, so you don't necessarily have to futz with a JSON file each time?

Good idea! We can add the typical cases that we need during development.

@andehen andehen force-pushed the mock-experiment-data branch from 23ea359 to d81ee0d Compare December 17, 2024 12:10
@andehen andehen marked this pull request as ready for review December 18, 2024 09:08
@andehen andehen requested a review from a team December 18, 2024 09:09
@jurajmajerik
Copy link
Contributor

Neither of the default commands work for me 🤔 I'm getting the following:

(env) ➜  posthog git:(mock-experiment-data) DEBUG=1 ./manage.py generate_experiment_data --type funnels --experiment-id funnel-test-1 
...
manage.py generate_experiment_data: error: unrecognized arguments: --type funnels
(env) ➜  posthog git:(mock-experiment-data) DEBUG=1 ./manage.py generate_experiment_data --type trends --experiment-id trends-test-1
...
manage.py generate_experiment_data: error: unrecognized arguments: --type trends

@andehen
Copy link
Contributor Author

andehen commented Dec 18, 2024

Neither of the default commands work for me 🤔 I'm getting the following:

(env) ➜  posthog git:(mock-experiment-data) DEBUG=1 ./manage.py generate_experiment_data --type funnels --experiment-id funnel-test-1 
...
manage.py generate_experiment_data: error: unrecognized arguments: --type funnels
(env) ➜  posthog git:(mock-experiment-data) DEBUG=1 ./manage.py generate_experiment_data --type trends --experiment-id trends-test-1
...
manage.py generate_experiment_data: error: unrecognized arguments: --type trends

yeah, I had forgotten to push the latest commits, sorry about that

@andehen andehen force-pushed the mock-experiment-data branch from c8cbcf3 to a669c95 Compare December 19, 2024 14:14
Copy link
Contributor

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

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

💅 Fancy!

CleanShot 2024-12-19 at 13 36 14@2x

Copy link
Contributor

@jurajmajerik jurajmajerik left a comment

Choose a reason for hiding this comment

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

Works great!

Where would be a good place to put an example config file so it's easy to reference?

@andehen andehen changed the title feat(experiments): add mgmt cmd to generate experiment test data feat(experiments): add mgmt cmd to generate experiment data Dec 20, 2024
@andehen andehen merged commit 5d7fb8b into master Dec 20, 2024
92 checks passed
@andehen andehen deleted the mock-experiment-data branch December 20, 2024 06:47
@andehen
Copy link
Contributor Author

andehen commented Dec 20, 2024

Works great!

Where would be a good place to put an example config file so it's easy to reference?

Locally you mean, or to share between us?

@jurajmajerik
Copy link
Contributor

@andehen It's an open question - if I'm going to run this command, how do I know what the input config file should look like?

For example, we could add a help flag to the command, which will tell you where to find an example config (could be a github gist).

Or maybe we could store a couple of example config files somewhere in the posthog repo, so it's easy to reference them them locally.

@andehen
Copy link
Contributor Author

andehen commented Dec 20, 2024

@andehen It's an open question - if I'm going to run this command, how do I know what the input config file should look like?

For example, we could add a help flag to the command, which will tell you where to find an example config (could be a github gist).

Or maybe we could store a couple of example config files somewhere in the posthog repo, so it's easy to reference them them locally.

Ah, it's baked into the code so you generate one with the default values like this

./manage.py generate_experiment_data --type funnel --init-config funnel-conf.json

and then you can modify that as you like. There is also a -h option that explains this

DEBUG=1 ./manage.py generate_experiment_data -h

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