-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
ref(MDC): EntityKey enum to class #3109
Conversation
This reverts commit 653e514.
Codecov ReportBase: 92.50% // Head: 92.84% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #3109 +/- ##
==========================================
+ Coverage 92.50% 92.84% +0.33%
==========================================
Files 672 673 +1
Lines 30858 30873 +15
==========================================
+ Hits 28545 28663 +118
+ Misses 2313 2210 -103
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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.
Looks pretty good to me, did we test running subscription schedulers + executors + other CLI things that depend on entities? Sometimes that can catch errors
assert REGISTERED_ENTITY_KEYS == { | ||
"GENERIC_METRICS_DISTRIBUTIONS": "generic_metrics_distributions", | ||
"GENERIC_METRICS_SETS": "generic_metrics_sets", | ||
} |
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.
I don't love that this is going to require changing for every entity added to snuba/datasets/configuration/
. Not sure of a better way to test this behavior but I think that we should not assume the entity list will be so static
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.
We will definitely need to figure this out, because it also implies that if a product person wants to add a new entity they will also have to edit this test. The point of the configuration is that changing them doesn't require Python changes.
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.
some questions
|
||
|
||
def test_entity_key() -> None: | ||
reset_entity_factory() |
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.
Does this function only exist for testing? I can't imagine any other reason why it would need to.
If you need a blank entity factory for a test, just mock the _ent_factory
function to return what you want
snuba/snuba/datasets/entities/factory.py
Line 120 in 53fadad
def _ent_factory() -> _EntityFactory: |
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 reset method shouldn't exist because it invites mutability into global state, which we should not have.
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 was introduced as part of #3065 and I just used it here, I can use initialize instead but the change to remove the reset function should be a different PR (cc @enochtangg)
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 was introduced purely for testing the multithreaded race condition. As opposed to spawning new threads and accessing the entity factory in a test case, the test was revised to ensure the entity factory initialization and the entity mapping attribute creation are not decoupled.
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.
(off-topic for this PR)
It's best to keep testing functions within tests especially for things like this which work with global state. Having a function that alters global state, should not be used in normal operation of the system, in the public api of a module introduces more surface area for issues.
This is a usecase for the python mocking library which can inject these kinds of corner conditions into the runtime of the test but without changing the way the system operates
@@ -245,6 +245,7 @@ | |||
|
|||
# File path glob for configs | |||
STORAGE_CONFIG_FILES_GLOB = f"{CONFIG_FILES_PATH}/**/storages/*.yaml" | |||
ENTITY_CONFIG_FILES_GLOB = f"{CONFIG_FILES_PATH}/**/entities/*.yaml" |
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.
We're going to need a better way of doing this I think. I feel like this works now because there is only one folder in the config file path.
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.
I believe the **
should recursively travel through all folders under CONFIG_FILES_PATH
. If it doesn't work on the next dataset we config we can change it, but it should work.
assert REGISTERED_ENTITY_KEYS == { | ||
"GENERIC_METRICS_DISTRIBUTIONS": "generic_metrics_distributions", | ||
"GENERIC_METRICS_SETS": "generic_metrics_sets", | ||
} |
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.
We will definitely need to figure this out, because it also implies that if a product person wants to add a new entity they will also have to edit this test. The point of the configuration is that changing them doesn't require Python changes.
Overview
EntityKey
enum with a simple class which will be slowly phased out as more entities are made into configMost of this PR consists of updated import statements:
from snuba.datasets.entities import EntityKey
->from snuba.datasets.entities.entity_key import EntityKey
Relevant file changes to review are the following:
snuba/datasets/configuration/entity_builder.py
snuba/datasets/entities/__init__.py
EntityKey
enum removedsnuba/datasets/entities/entity_key.py
EntityKey
class createdsnuba/datasets/entities/factory.py
snuba/datasets/pluggable_entity.py
name
withentity_key
snuba/datasets/storages/storage_key.py
snuba/settings/__init__.py
snuba/subscriptions/entity_subscription.py
tests/datasets/entities/test_entity_key.py