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

chore(integrations): register integration domains in initializer #80212

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cathteng
Copy link
Member

@cathteng cathteng commented Nov 4, 2024

Instead of hardcoding the integration domains and their keys, we can specify the domain inside each respective IntegrationProvider. When the provider gets registered in initializer.py, we can dynamically construct the mapping of domains to keys, and vice versa.

domain is optional as there are some integrations that we haven't classified yet. If/when we emit metrics, we can classify these under "unknown".

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 4, 2024
Copy link

codecov bot commented Nov 4, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 5 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/integrations/manager.py 70.58% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #80212      +/-   ##
==========================================
- Coverage   78.08%   78.08%   -0.01%     
==========================================
  Files        7179     7179              
  Lines      317130   317148      +18     
  Branches    43724    43727       +3     
==========================================
+ Hits       247637   247639       +2     
- Misses      63148    63158      +10     
- Partials     6345     6351       +6     

@cathteng cathteng requested a review from a team November 4, 2024 22:26
@@ -311,6 +311,7 @@ def search_issues(self, query: str | None, **kwargs) -> dict[str, Any]:
class GitHubIntegrationProvider(IntegrationProvider):
key = "github"
name = "GitHub"
domain = IntegrationDomain.SOURCE_CODE_MANAGEMENT
Copy link
Member

Choose a reason for hiding this comment

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

This is definitely a bit nicer. Tying the domain to the provider class really solidifies what an integration's responsibility is at instantiation time. I also remember @ameliahsu mentioning turning this into an array, which should work for the multiple domains on a single integration problem, but is the issue that we need a single "primary" domain per integration?

Comment on lines +21 to +23
self.__integration_domains: dict[str, IntegrationDomain] = (
{}
) # map of integration to domain
Copy link
Member

Choose a reason for hiding this comment

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

Minor nit: I think it's fine to generate this on the fly from the list of integration providers instead of storing it on the class. I don't think it'll add too much overhead and reduces our need to remove them when something unregisters.

@@ -36,6 +43,9 @@ def exists(self, key: str) -> bool:

def register(self, cls: type[IntegrationProvider]) -> None:
self.__values[cls.key] = cls
if cls.domain:
self.__domain_integrations[cls.domain].append(cls.key)
self.__integration_domains[cls.key] = cls.domain

def unregister(self, cls: type[IntegrationProvider]) -> None:
try:
Copy link
Member

Choose a reason for hiding this comment

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

If you do decide to keep the domain dictionaries around, you'll need to remove integrations from them here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants