-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose metrics and other improvements
- Loading branch information
1 parent
44ba726
commit d4650fa
Showing
13 changed files
with
347 additions
and
190 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,19 @@ | ||
from prometheus_client import start_wsgi_server, REGISTRY, CollectorRegistry | ||
|
||
from .decorator import * | ||
from .settings import AutometricsOptions, init_settings | ||
from .tracker import set_tracker, get_tracker_type | ||
|
||
|
||
def init(**kwargs: AutometricsOptions): | ||
"""Initialize autometrics with the given options.""" | ||
init_settings(**kwargs) | ||
tracker_type = get_tracker_type() | ||
set_tracker(tracker_type) | ||
|
||
|
||
def start_http_server( | ||
port: int = 9464, addr: str = "0.0.0.0", registry: CollectorRegistry = REGISTRY | ||
): | ||
"""Starts a WSGI server for prometheus metrics as a daemon thread.""" | ||
start_wsgi_server(port) |
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,69 @@ | ||
import os | ||
|
||
from typing import TypedDict, Optional | ||
|
||
from .objectives import ObjectiveLatency | ||
|
||
|
||
class AutometricsSettings(TypedDict): | ||
"""Settings for autometrics.""" | ||
|
||
histogram_buckets: "list[float]" | ||
tracker: str | ||
enable_exemplars: bool | ||
service_name: str | ||
commit: str | ||
version: str | ||
branch: str | ||
|
||
|
||
class AutometricsOptions(AutometricsSettings, total=False): | ||
"""Optional settings for autometrics.""" | ||
|
||
|
||
def get_objective_boundaries(): | ||
"""Get the objective latency boundaries as float values in seconds (instead of strings)""" | ||
return list(map(lambda c: float(c.value), ObjectiveLatency)) | ||
|
||
|
||
settings: Optional[AutometricsSettings] = None | ||
|
||
|
||
def init_settings(**overrides: Optional[AutometricsOptions]): | ||
config: AutometricsSettings = AutometricsSettings( | ||
{ | ||
"histogram_buckets": overrides.get("histogram_buckets") | ||
or get_objective_boundaries(), | ||
"tracker": overrides.get("tracker") | ||
or os.getenv("AUTOMETRICS_TRACKER") | ||
or "opentelemetry", | ||
"enable_exemplars": overrides.get( | ||
"enable_exemplars", os.getenv("AUTOMETRICS_EXEMPLARS") == "true" | ||
), | ||
"service_name": overrides.get( | ||
"service_name", | ||
os.getenv( | ||
"AUTOMETRICS_SERVICE_NAME", | ||
os.getenv("OTEL_SERVICE_NAME", __package__.rsplit(".", 1)[0]), | ||
), | ||
), | ||
"commit": overrides.get( | ||
"commit", os.getenv("AUTOMETRICS_COMMIT", os.getenv("COMMIT_SHA", "")) | ||
), | ||
"branch": overrides.get( | ||
"branch", os.getenv("AUTOMETRICS_BRANCH", os.getenv("BRANCH_NAME", "")) | ||
), | ||
"version": overrides.get("version", os.getenv("AUTOMETRICS_VERSION", "")), | ||
} | ||
) | ||
global settings | ||
settings = config | ||
return settings | ||
|
||
|
||
def get_settings() -> AutometricsSettings: | ||
"""Get the current settings.""" | ||
global settings | ||
if settings is None: | ||
return init_settings() | ||
return settings |
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
Oops, something went wrong.