-
Notifications
You must be signed in to change notification settings - Fork 0
comments #7
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
base: main
Are you sure you want to change the base?
comments #7
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,10 +22,10 @@ | |
| from redis.exceptions import RedisError | ||
|
|
||
| # Global config | ||
| REDIS_PREFIX = "metric:" | ||
| REDIS_PREFIX = "metric:" #ENV VAR!? | ||
| DEFAULT_TTL = int(os.getenv("DEFAULT_TTL", "7200")) # 2 hours | ||
|
|
||
| logging.basicConfig(level=logging.INFO) | ||
| logging.basicConfig(level=logging.INFO) # LOGLEVEL SET VIA ENV VAR?! OR -v -vv -vvv... | ||
|
Contributor
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. done via env var |
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
|
|
@@ -57,7 +57,7 @@ def _make_key(name: str, labels: Dict[str, str]) -> str: | |
|
|
||
|
|
||
| def _parse_ttl(labels: Dict[str, str]) -> int: | ||
| ttl_label = "pushgw_ttl" | ||
| ttl_label = "pushgw_ttl" #NAMING CONSITENCY pushgw vs pushgateway | ||
|
Contributor
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. done with backward compatibility |
||
| ttl_raw = labels.pop(ttl_label, "0") | ||
| try: | ||
| ttl = int(ttl_raw) | ||
|
|
@@ -72,7 +72,7 @@ def _parse_ttl(labels: Dict[str, str]) -> int: | |
|
|
||
| @asynccontextmanager | ||
| async def lifespan(app: FastAPI) -> AsyncIterator[None]: | ||
| global redis_client | ||
| global redis_client # must be global var? cannot be passed as param to this async func? global client is ok, but not global variable | ||
|
Contributor
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. done |
||
|
|
||
| REDIS_HOST = os.getenv("REDIS_HOST", "localhost") | ||
| REDIS_PORT = int(os.getenv("REDIS_PORT", "6379")) | ||
|
|
@@ -176,7 +176,7 @@ async def get_metrics() -> PlainTextResponse: | |
| keys = await redis_client.keys(f"{REDIS_PREFIX}*") | ||
|
|
||
| for key in keys: | ||
| if await redis_client.type(key) != "string": | ||
| if await redis_client.type(key) != "string": # type checking via string? is there somthing like redis.STRING to compare with? | ||
|
Contributor
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. done, there is no such option as redis.STRING |
||
| continue | ||
| try: | ||
| entry_raw = await redis_client.get(key) | ||
|
|
@@ -190,6 +190,7 @@ async def get_metrics() -> PlainTextResponse: | |
| metrics_by_name[name].append((labels, value)) | ||
| type_by_name[name] = mtype | ||
| except Exception: | ||
| # log execetion every time, now it makes you blind | ||
|
Contributor
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. done |
||
| continue | ||
|
|
||
| for name, entries in metrics_by_name.items(): | ||
|
|
@@ -212,6 +213,7 @@ async def get_metrics() -> PlainTextResponse: | |
| filtered = {k: labels.get(k, "") for k in label_keys} | ||
| g.labels(**filtered).set(value) | ||
| except ValueError: | ||
| # log execetion every time, now it makes you blind, but less then case before, because it was generic exception | ||
|
Contributor
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. done |
||
| # metric already exists (e.g. from other Redis key) | ||
| continue | ||
|
|
||
|
|
@@ -220,3 +222,5 @@ async def get_metrics() -> PlainTextResponse: | |
| redis_metrics = generate_latest(redis_registry).decode("utf-8") | ||
|
|
||
| return PlainTextResponse(internal_metrics + redis_metrics, media_type="text/plain") | ||
|
|
||
| #LOGGING IN BETWEEN WITH DEBUG LEVEL | ||
|
Contributor
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. done |
||
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.
done