-
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.
Merge branch 'add_metrics_counter' into 'main'
Prepare utils for metrics counters See merge request oss/imalive!11
- Loading branch information
Showing
13 changed files
with
74 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.6.1 | ||
3.6.2 |
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,4 @@ | ||
class ImaliveHTTPException(Exception): | ||
def __init__(self, status_code: int, message: dict): | ||
self.status_code = status_code | ||
self.message = message |
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,16 +1,21 @@ | ||
from fastapi import APIRouter | ||
|
||
from utils.cid import get_current_cid | ||
from utils.counter import create_counter, increment_counter | ||
from utils.otel import get_otel_tracer | ||
from utils.health import health | ||
|
||
router = APIRouter() | ||
_counter = create_counter("health_api_counter", "Health API counter") | ||
|
||
@router.get("") | ||
def get_health(): | ||
with get_otel_tracer().start_as_current_span("imalive-health-get-route"): | ||
increment_counter(_counter, get_current_cid()) | ||
return health() | ||
|
||
@router.post("") | ||
def post_health(): | ||
with get_otel_tracer().start_as_current_span("imalive-health-post-route"): | ||
increment_counter(_counter, get_current_cid()) | ||
return health() |
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,11 +1,15 @@ | ||
from fastapi import APIRouter | ||
|
||
from utils.cid import get_current_cid | ||
from utils.counter import create_counter, increment_counter | ||
from utils.otel import get_otel_tracer | ||
from utils.metrics import all_metrics | ||
|
||
router = APIRouter() | ||
_counter = create_counter("metrics_api_counter", "Health API counter") | ||
|
||
@router.get("") | ||
def get_metrics(): | ||
with get_otel_tracer().start_as_current_span("imalive-metrics-route"): | ||
increment_counter(_counter, get_current_cid()) | ||
return all_metrics() |
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,13 @@ | ||
from uuid import uuid4 | ||
from asgi_correlation_id import correlation_id | ||
|
||
from utils.common import is_empty | ||
|
||
def get_current_cid(): | ||
try: | ||
cid = correlation_id.get() | ||
if is_empty(cid): | ||
cid = "{}".format(uuid4()) | ||
return cid | ||
except Exception: | ||
return "{}".format(uuid4()) |
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,11 @@ | ||
from utils.otel import get_otel_meter | ||
|
||
def create_counter(name, description): | ||
return get_otel_meter().create_counter( | ||
name = name, | ||
description = description, | ||
unit = "1" | ||
) | ||
|
||
def increment_counter(counter, tid): | ||
counter.add(1, {"tid": tid}) |
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