-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHT-669: extracting kg updater and repository
- Loading branch information
1 parent
c3a336b
commit cc7ba63
Showing
35 changed files
with
126 additions
and
118 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains 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,25 @@ | ||
from typing import List | ||
|
||
import asyncio | ||
|
||
from app.core.repository.metricstore_client import MetricStoreClient | ||
from app.core.repository.types import MetricQuery | ||
from app.core.types import MetricValue | ||
|
||
|
||
class MetricRepository: | ||
client: MetricStoreClient | ||
|
||
def __init__(self, client: MetricStoreClient): | ||
self.client = client | ||
|
||
async def query_many( | ||
self, now: int, queries: List[MetricQuery] | ||
) -> List[MetricValue]: | ||
query_futures = [self.query_one(now, query) for query in queries] | ||
query_results: List[List[MetricValue]] = await asyncio.gather(*query_futures) | ||
return [element for elements in query_results for element in elements] | ||
|
||
async def query_one(self, now: int, query: MetricQuery) -> List[MetricValue]: | ||
result_parser = query.result_parser.get_by_name() | ||
return await self.client.query(query.query, result_parser) |
4 changes: 2 additions & 2 deletions
4
app/clients/influxdb/metricstore_client.py → app/core/repository/metricstore_client.py
This file contains 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 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 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 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,34 @@ | ||
from typing import Any, Optional | ||
|
||
import importlib | ||
from dataclasses import dataclass | ||
from enum import StrEnum | ||
|
||
|
||
class ResultParserId(StrEnum): | ||
SIMPLE_RESULT_PARSER = ( | ||
"app.clients.influxdb.simple_result_parser.SimpleResultParser" | ||
) | ||
|
||
def get_by_name(self) -> Any: | ||
if self.name == "SIMPLE_RESULT_PARSER": | ||
return self.instantiate(self.value) | ||
else: | ||
raise Exception(f"Unknown parser for {self}") | ||
|
||
def instantiate(self, clazz: str) -> Any: | ||
idx = clazz.rfind(".") | ||
module, class_name = clazz[:idx], clazz[idx + 1 :] | ||
ClassObj = getattr(importlib.import_module(module), class_name) | ||
return ClassObj() | ||
|
||
|
||
@dataclass | ||
class MetricQuery: | ||
measurement_id: str | ||
subresource: Optional[str] | ||
source: str | ||
unit: str | ||
property: str | ||
query: str | ||
result_parser: ResultParserId |
This file contains 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 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
Empty file.
This file contains 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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
app/core/kg_tuple_parser.py → app/core/updater/kg_tuple_parser.py
This file contains 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 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 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
2 changes: 1 addition & 1 deletion
2
app/core/test_kg_tuple_parser.py → app/core/updater/test_kg_tuple_parser.py
This file contains 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 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.