-
Notifications
You must be signed in to change notification settings - Fork 29
[DPE-7316] Additive changes for stereo mode #1648
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
Open
dragomirp
wants to merge
1
commit into
16/edge
Choose a base branch
from
stereo-mode-additive-code
base: 16/edge
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,18 +12,15 @@ | |
| import re | ||
| import shutil | ||
| import subprocess | ||
| from asyncio import as_completed, create_task, run, wait | ||
| from contextlib import suppress | ||
| from functools import cached_property | ||
| from pathlib import Path | ||
| from ssl import CERT_NONE, create_default_context | ||
| from typing import TYPE_CHECKING, Any, Literal, TypedDict | ||
|
|
||
| import psutil | ||
| import requests | ||
| import tomli | ||
| from charmlibs import snap | ||
| from httpx import AsyncClient, BasicAuth, HTTPError | ||
| from httpx import BasicAuth | ||
| from jinja2 import Template | ||
| from ops import BlockedStatus | ||
| from pysyncobj.utility import TcpUtility, UtilityException | ||
|
|
@@ -58,7 +55,7 @@ | |
| POSTGRESQL_LOGS_PATH, | ||
| TLS_CA_BUNDLE_FILE, | ||
| ) | ||
| from utils import _change_owner, label2name, render_file | ||
| from utils import _change_owner, label2name, parallel_patroni_get_request, render_file | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -249,9 +246,28 @@ def cached_cluster_status(self): | |
|
|
||
| def cluster_status(self, alternative_endpoints: list | None = None) -> list[ClusterMember]: | ||
| """Query the cluster status.""" | ||
| if not self._patroni_async_auth: | ||
| raise RetryError( | ||
| last_attempt=Future.construct(1, Exception("Unable to reach any units"), True) | ||
| ) | ||
|
|
||
| # TODO we don't know the other cluster's ca | ||
| verify = not bool(alternative_endpoints) | ||
|
Contributor
Author
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. Async rel doesn't share CAs. Existing behaviour. |
||
| if alternative_endpoints: | ||
| endpoints = alternative_endpoints | ||
| else: | ||
| endpoints = [] | ||
| if self.unit_ip: | ||
| endpoints.append(self.unit_ip) | ||
| for peer_ip in self.peers_ips: | ||
| endpoints.append(peer_ip) | ||
| # Request info from cluster endpoint (which returns all members of the cluster). | ||
| if response := self.parallel_patroni_get_request( | ||
| f"/{PATRONI_CLUSTER_STATUS_ENDPOINT}", alternative_endpoints | ||
| if response := parallel_patroni_get_request( | ||
| f"/{PATRONI_CLUSTER_STATUS_ENDPOINT}", | ||
| endpoints, | ||
| f"{PATRONI_CONF_PATH}/{TLS_CA_BUNDLE_FILE}", | ||
| self._patroni_async_auth, | ||
| verify, | ||
| ): | ||
| logger.debug("API cluster_status: %s", response["members"]) | ||
| return response["members"] | ||
|
|
@@ -295,54 +311,6 @@ def get_member_status(self, member_name: str) -> str: | |
| return member["state"] | ||
| return "" | ||
|
|
||
| async def _httpx_get_request(self, url: str, verify: bool = True) -> dict[str, Any] | None: | ||
| if not self._patroni_async_auth: | ||
| return None | ||
| ssl_ctx = create_default_context() | ||
| if verify: | ||
| with suppress(FileNotFoundError): | ||
| ssl_ctx.load_verify_locations(cafile=f"{PATRONI_CONF_PATH}/{TLS_CA_BUNDLE_FILE}") | ||
| else: | ||
| ssl_ctx.check_hostname = False | ||
| ssl_ctx.verify_mode = CERT_NONE | ||
| async with AsyncClient( | ||
| auth=self._patroni_async_auth, timeout=API_REQUEST_TIMEOUT, verify=ssl_ctx | ||
| ) as client: | ||
| try: | ||
| return (await client.get(url)).raise_for_status().json() | ||
| except (HTTPError, ValueError): | ||
| return None | ||
|
|
||
| async def _async_get_request( | ||
| self, uri: str, endpoints: list[str], verify: bool = True | ||
| ) -> dict[str, Any] | None: | ||
| tasks = [ | ||
| create_task(self._httpx_get_request(f"https://{ip}:8008{uri}", verify)) | ||
| for ip in endpoints | ||
| ] | ||
| for task in as_completed(tasks): | ||
| if result := await task: | ||
| for task in tasks: | ||
| task.cancel() | ||
| await wait(tasks) | ||
| return result | ||
|
|
||
| def parallel_patroni_get_request( | ||
| self, uri: str, endpoints: list[str] | None = None | ||
| ) -> dict[str, Any] | None: | ||
| """Call all possible patroni endpoints in parallel.""" | ||
| if not endpoints: | ||
| endpoints = [] | ||
| if self.unit_ip: | ||
| endpoints.append(self.unit_ip) | ||
| for peer_ip in self.peers_ips: | ||
| endpoints.append(peer_ip) | ||
| verify = True | ||
| else: | ||
| # TODO we don't know the other cluster's ca | ||
| verify = False | ||
| return run(self._async_get_request(uri, endpoints, verify)) | ||
|
|
||
| def get_primary( | ||
| self, unit_name_pattern=False, alternative_endpoints: list[str] | None = None | ||
| ) -> str | None: | ||
|
|
||
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.
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.
To maintain the current behaviour.