-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Pass in tenant_id to kv_store in monitoring job #3726
Merged
+26
−24
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
from onyx.configs.constants import KV_CUSTOMER_UUID_KEY | ||
from onyx.configs.constants import KV_INSTANCE_DOMAIN_KEY | ||
from onyx.configs.constants import MilestoneRecordType | ||
from onyx.db.engine import get_sqlalchemy_engine | ||
from onyx.db.engine import get_session_with_tenant | ||
from onyx.db.milestone import create_milestone_if_not_exists | ||
from onyx.db.models import User | ||
from onyx.key_value_store.factory import get_kv_store | ||
|
@@ -41,7 +41,7 @@ def _get_or_generate_customer_id_mt(tenant_id: str) -> str: | |
return str(uuid.uuid5(uuid.NAMESPACE_X500, tenant_id)) | ||
|
||
|
||
def get_or_generate_uuid(tenant_id: str | None = None) -> str: | ||
def get_or_generate_uuid(tenant_id: str | None) -> str: | ||
# TODO: split out the whole "instance UUID" generation logic into a separate | ||
# utility function. Telemetry should not be aware at all of how the UUID is | ||
# generated/stored. | ||
|
@@ -52,7 +52,7 @@ def get_or_generate_uuid(tenant_id: str | None = None) -> str: | |
if _CACHED_UUID is not None: | ||
return _CACHED_UUID | ||
|
||
kv_store = get_kv_store() | ||
kv_store = get_kv_store(tenant_id=tenant_id) | ||
|
||
try: | ||
_CACHED_UUID = cast(str, kv_store.load(KV_CUSTOMER_UUID_KEY)) | ||
|
@@ -63,18 +63,18 @@ def get_or_generate_uuid(tenant_id: str | None = None) -> str: | |
return _CACHED_UUID | ||
|
||
|
||
def _get_or_generate_instance_domain() -> str | None: # | ||
def _get_or_generate_instance_domain(tenant_id: str | None = None) -> str | None: # | ||
global _CACHED_INSTANCE_DOMAIN | ||
|
||
if _CACHED_INSTANCE_DOMAIN is not None: | ||
return _CACHED_INSTANCE_DOMAIN | ||
|
||
kv_store = get_kv_store() | ||
kv_store = get_kv_store(tenant_id=tenant_id) | ||
|
||
try: | ||
_CACHED_INSTANCE_DOMAIN = cast(str, kv_store.load(KV_INSTANCE_DOMAIN_KEY)) | ||
except KvKeyNotFoundError: | ||
with Session(get_sqlalchemy_engine()) as db_session: | ||
with get_session_with_tenant(tenant_id=tenant_id) as db_session: | ||
first_user = db_session.query(User).first() | ||
if first_user: | ||
_CACHED_INSTANCE_DOMAIN = first_user.email.split("@")[-1] | ||
|
@@ -94,16 +94,16 @@ def optional_telemetry( | |
if DISABLE_TELEMETRY: | ||
return | ||
|
||
tenant_id = tenant_id or CURRENT_TENANT_ID_CONTEXTVAR.get() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar comment here |
||
|
||
try: | ||
|
||
def telemetry_logic() -> None: | ||
try: | ||
customer_uuid = ( | ||
_get_or_generate_customer_id_mt( | ||
tenant_id or CURRENT_TENANT_ID_CONTEXTVAR.get() | ||
) | ||
_get_or_generate_customer_id_mt(tenant_id) | ||
if MULTI_TENANT | ||
else get_or_generate_uuid() | ||
else get_or_generate_uuid(tenant_id) | ||
) | ||
payload = { | ||
"data": data, | ||
|
@@ -115,7 +115,9 @@ def telemetry_logic() -> None: | |
"is_cloud": MULTI_TENANT, | ||
} | ||
if ENTERPRISE_EDITION_ENABLED: | ||
payload["instance_domain"] = _get_or_generate_instance_domain() | ||
payload["instance_domain"] = _get_or_generate_instance_domain( | ||
tenant_id | ||
) | ||
requests.post( | ||
_DANSWER_TELEMETRY_ENDPOINT, | ||
headers={"Content-Type": "application/json"}, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Slightly wary of default
None
to the current tenant ID. Elsewhere, we treat it as a valid tenant ID / asPOSTGRES_DEFAULT_SCHEMA
. Had a similar debate aroundget_session_with_tenant
(default to a sentinel if nothing passed in?, etc.) and ended up deciding on different entrypoint (get_session_with_default_tenant
)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.
#3069