Skip to content

Commit

Permalink
Merge pull request #26 from semiotic-ai/qps_fix
Browse files Browse the repository at this point in the history
Fix query count measurements
  • Loading branch information
aasseman authored Nov 4, 2022
2 parents b66133d + 45774c1 commit 44609bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions autoagora/query_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
)


class HTTPError(Exception):
"""Catch-all for HTTP errors"""


@backoff.on_exception(
backoff.expo, aiohttp.ClientError, max_time=30, logger=logging.root
)
Expand Down Expand Up @@ -52,12 +56,13 @@ async def query_counts() -> Dict[str, int]:


@backoff.on_exception(
backoff.expo, aiohttp.ClientError, max_time=30, logger=logging.root
backoff.expo, (aiohttp.ClientError, HTTPError), max_time=30, logger=logging.root
)
async def subgraph_query_count(subgraph: str) -> int:
async with aiohttp.ClientSession() as session:
async with session.get(args.indexer_service_metrics_endpoint) as response:
assert response.status == 200
if response.status != 200:
raise HTTPError(response.status)

results = re.findall(
r'indexer_service_queries_ok{{deployment="{subgraph}"}} ([0-9]*)'.format(
Expand Down
4 changes: 2 additions & 2 deletions autoagora/subgraph_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ async def queries_per_second(self, average_duration: float = 1):
if time_since_last_change < SubgraphWrapper.GATEWAY_DELAY:
await sleep(SubgraphWrapper.GATEWAY_DELAY - time_since_last_change)

timestamp_1 = time()
query_count_1 = await subgraph_query_count(self.subgraph)
timestamp_1 = time()

await sleep(average_duration)

timestamp_2 = time()
query_count_2 = await subgraph_query_count(self.subgraph)
timestamp_2 = time()

queries_per_second = (query_count_2 - query_count_1) / (
timestamp_2 - timestamp_1
Expand Down

0 comments on commit 44609bc

Please sign in to comment.