Skip to content

Commit

Permalink
fixed clickhouse client, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
akimrx committed Oct 1, 2023
1 parent 472fe91 commit 40fcbf1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion tracker_exporter/__version__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pylint: disable=C0103,W0622
version = "0.1.18"
version = "0.1.19"
url = "https://github.com/akimrx/yandex-tracker-exporter"
download_url = "https://pypi.org/project/tracker-exporter/"
appname = "yandex_tracker_exporter"
Expand Down
42 changes: 25 additions & 17 deletions tracker_exporter/services/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,39 +43,47 @@ def __init__(self, # pylint: disable=W0102
self.serverless_proxy_id = serverless_proxy_id
self.params = params
self.timeout = int(http_timeout)
self.headers = {"Content-Type": "application/json"}
self.headers = {
"Content-Type": "application/json",
"X-Clickhouse-User": self.user
}

if self.password is not None:
self.headers["X-Clickhouse-Key"] = self.password

if self.proto == ClickhouseProto.HTTPS:
assert self.cacert is not None

@retry((NetworkError, TimedOut))
def execute(self, query: str) -> Union[None, Response]:
url = f"{self.proto}://{self.host}:{self.port}"
def _prepare_query_params(self):
params = self.params.copy()

if self.proto != ClickhouseProto.HTTPS:
url += f"?user={self.user}"
if self.password is not None:
url += f"&password={self.password}"
else:
self.headers["X-Clickhouse-User"] = self.user
self.headers["X-Clickhouse-Key"] = self.password
if params.get("user") is not None:
logger.warning("Removed 'user' key:value from params, please pass 'user' via arg")
del params["user"]

if params.get("password") is not None:
logger.warning("Removed 'password' key:value from params, please pass 'password' via arg")
del params["password"]

if self.serverless_proxy_id:
self.params["database"] = self.serverless_proxy_id

if self.params:
params = "&".join([f"{k}={v}" for k, v in self.params.items()])
url += f"&{params}" if self.proto != ClickhouseProto.HTTPS else f"?{params}"
return params

@retry((NetworkError, TimedOut))
def execute(self, query: str) -> Union[None, Response]:
url = f"{self.proto}://{self.host}:{self.port}"
params = self._prepare_query_params()

try:
if self.proto == ClickhouseProto.HTTPS:
response = requests.post(
url=url, headers=self.headers, data=query,
timeout=self.timeout, verify=self.cacert
url=url, headers=self.headers, params=params,
data=query, timeout=self.timeout, verify=self.cacert
)
else:
response = requests.post(
url=url, headers=self.headers, data=query, timeout=self.timeout
url=url, headers=self.headers, params=params, data=query, timeout=self.timeout
)
except requests.Timeout as exc:
raise TimedOut() from exc
Expand Down
1 change: 1 addition & 0 deletions tracker_exporter/services/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def get_comments(self, issue_key: str) -> IssueComments:

@monitoring.send_time_metric("issues_search_time_seconds")
def search_issues(self, query: str, limit: int = 100) -> List[Issues]:
# FIXME: chunked search, tracker issues result hard limit is 10000
found_issues = self.client.issues.find(query, per_page=limit)
logger.info(f"Found {len(found_issues)} issues by query '{query}'")
return found_issues
Expand Down

0 comments on commit 40fcbf1

Please sign in to comment.