Skip to content

Commit

Permalink
Merge pull request #3188 from danswer-ai/hotfix/v0.14-confluence-retries
Browse files Browse the repository at this point in the history
Merge hotfix/v0.14-confluence-retries into release/v0.14
  • Loading branch information
rkuo-danswer authored Nov 21, 2024
2 parents f752b9e + a21104d commit b11a3ad
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
17 changes: 17 additions & 0 deletions backend/danswer/connectors/confluence/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import Any
from urllib.parse import quote

from atlassian import Confluence # type: ignore

from danswer.configs.app_configs import CONFLUENCE_CONNECTOR_LABELS_TO_SKIP
from danswer.configs.app_configs import CONTINUE_ON_CONNECTOR_FAILURE
from danswer.configs.app_configs import INDEX_BATCH_SIZE
Expand Down Expand Up @@ -116,6 +118,21 @@ def load_credentials(self, credentials: dict[str, Any]) -> dict[str, Any] | None
is_cloud=self.is_cloud,
wiki_base=self.wiki_base,
)

client_without_retries = Confluence(
api_version="cloud" if self.is_cloud else "latest",
url=self.wiki_base.rstrip("/"),
username=credentials["confluence_username"] if self.is_cloud else None,
password=credentials["confluence_access_token"] if self.is_cloud else None,
token=credentials["confluence_access_token"] if not self.is_cloud else None,
)
spaces = client_without_retries.get_all_spaces(limit=1)
if not spaces:
raise RuntimeError(
f"No spaces found at {self.wiki_base}! "
"Check your credentials and wiki_base and make sure "
"is_cloud is set correctly."
)
return None

def _get_comment_string_for_page_id(self, page_id: str) -> str:
Expand Down
6 changes: 5 additions & 1 deletion backend/danswer/connectors/confluence/onyx_confluence.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def handle_confluence_rate_limit(confluence_call: F) -> F:
def wrapped_call(*args: list[Any], **kwargs: Any) -> Any:
MAX_RETRIES = 5

TIMEOUT = 3600
TIMEOUT = 600
timeout_at = time.monotonic() + TIMEOUT

for attempt in range(MAX_RETRIES):
Expand All @@ -99,6 +99,10 @@ def wrapped_call(*args: list[Any], **kwargs: Any) -> Any:
return confluence_call(*args, **kwargs)
except HTTPError as e:
delay_until = _handle_http_error(e, attempt)
logger.warning(
f"HTTPError in confluence call. "
f"Retrying in {delay_until} seconds..."
)
while time.monotonic() < delay_until:
# in the future, check a signal here to exit
time.sleep(1)
Expand Down
2 changes: 1 addition & 1 deletion backend/danswer/connectors/confluence/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,6 @@ def build_confluence_client(
password=credentials_json["confluence_access_token"] if is_cloud else None,
token=credentials_json["confluence_access_token"] if not is_cloud else None,
backoff_and_retry=True,
max_backoff_retries=60,
max_backoff_retries=10,
max_backoff_seconds=60,
)
21 changes: 19 additions & 2 deletions backend/ee/danswer/external_permissions/confluence/group_sync.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from atlassian import Confluence # type: ignore

from danswer.connectors.confluence.onyx_confluence import OnyxConfluence
from danswer.connectors.confluence.utils import build_confluence_client
from danswer.connectors.confluence.utils import get_user_email_from_username__server
Expand Down Expand Up @@ -32,11 +34,26 @@ def _get_group_members_email_paginated(
def confluence_group_sync(
cc_pair: ConnectorCredentialPair,
) -> list[ExternalUserGroup]:
credentials = cc_pair.credential.credential_json
is_cloud = cc_pair.connector.connector_specific_config.get("is_cloud", False)
wiki_base = cc_pair.connector.connector_specific_config["wiki_base"]

# test connection with direct client, no retries
confluence_client = Confluence(
api_version="cloud" if is_cloud else "latest",
url=wiki_base.rstrip("/"),
username=credentials["confluence_username"] if is_cloud else None,
password=credentials["confluence_access_token"] if is_cloud else None,
token=credentials["confluence_access_token"] if not is_cloud else None,
)
spaces = confluence_client.get_all_spaces(limit=1)
if not spaces:
raise RuntimeError(f"No spaces found at {wiki_base}!")

confluence_client = build_confluence_client(
credentials_json=cc_pair.credential.credential_json,
credentials_json=credentials,
is_cloud=is_cloud,
wiki_base=cc_pair.connector.connector_specific_config["wiki_base"],
wiki_base=wiki_base,
)

# Get all group names
Expand Down

0 comments on commit b11a3ad

Please sign in to comment.