-
Notifications
You must be signed in to change notification settings - Fork 574
feat(experimentation): publish warehouse connections to Redis and apply delivery status #8551
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7f471ad
feat(experimentation): publish warehouse connections to Redis and app…
gagantrivedi afe51e6
refactor(core): move warehouse credential encryption out of the field…
gagantrivedi 82a2525
refactor(experimentation): move EncryptedJSONField and credential enc…
gagantrivedi f4a49cc
docs(experimentation): drop the WarehouseDeliveryStatus docstring, th…
gagantrivedi 86786d2
refactor(experimentation): split the warehouse-delivery Redis contrac…
gagantrivedi 11bcdc0
feat(experimentation): show delivery failures on fetch instead of cop…
gagantrivedi b5949c6
docs(experimentation): shorten the delivery status overlay docstring
gagantrivedi 38438dd
fix(experimentation): forget stale delivery outcomes, fall back when …
gagantrivedi b881bed
Merge remote-tracking branch 'origin/main' into feat/warehouse-connec…
gagantrivedi 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| from typing import Any | ||
|
|
||
| import structlog | ||
| from cryptography.fernet import InvalidToken | ||
| from django.db import models | ||
|
|
||
| from experimentation.warehouse_credentials import ( | ||
| decrypt_warehouse_credentials, | ||
| encrypt_warehouse_credentials, | ||
| ) | ||
|
|
||
| logger = structlog.get_logger("experimentation") | ||
|
|
||
|
|
||
| class EncryptedJSONField(models.TextField[Any, Any]): | ||
| """Stores a JSON value as Fernet ciphertext keyed on | ||
| WAREHOUSE_CREDENTIALS_SECRET. Used for a warehouse connection's | ||
| credentials, so the same ciphertext can be handed to the warehouse-delivery | ||
| service.""" | ||
|
|
||
| def get_prep_value(self, value: Any) -> str | None: | ||
| if value is None: | ||
| return None | ||
| return encrypt_warehouse_credentials(value) | ||
|
|
||
| def from_db_value( | ||
| self, | ||
| value: str | None, | ||
| expression: object, | ||
| connection: object, | ||
| ) -> Any: | ||
| if value is None: | ||
| return None | ||
| try: | ||
| return decrypt_warehouse_credentials(value) | ||
| except InvalidToken: | ||
| logger.warning("encrypted_field.decrypt_failed", exc_info=True) | ||
| return None | ||
|
|
||
| def get_lookup(self, lookup_name: str) -> Any: | ||
| if lookup_name != "isnull": | ||
| raise NotImplementedError( | ||
| "EncryptedJSONField only supports isnull lookups." | ||
| ) | ||
| return super().get_lookup(lookup_name) |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| from functools import lru_cache | ||
|
|
||
| from django.conf import settings | ||
| from redis.cluster import RedisCluster | ||
|
|
||
| SOCKET_TIMEOUT = 1 | ||
|
|
||
|
|
||
| @lru_cache(maxsize=1) | ||
| def get_client() -> RedisCluster: | ||
| """The Redis the ingestion server and the warehouse-delivery service read | ||
| their configuration from and, for the latter, write outcomes to.""" | ||
| return RedisCluster.from_url( # type: ignore[no-any-return] | ||
| settings.INGESTION_REDIS_URL, | ||
| socket_timeout=SOCKET_TIMEOUT, | ||
| socket_keepalive=True, | ||
| ) | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.