-
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 'opentelemtry' into 'main'
Prepare OTEL support for imalive See merge request oss/imalive!10
- Loading branch information
Showing
21 changed files
with
287 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
receivers: | ||
otlp: | ||
protocols: | ||
grpc: | ||
http: | ||
|
||
exporters: | ||
debug: | ||
prometheus: | ||
endpoint: "0.0.0.0:8889" | ||
const_labels: | ||
otel: otel | ||
otlp: | ||
endpoint: "jaeger:4317" | ||
tls: | ||
insecure: true | ||
|
||
service: | ||
pipelines: | ||
metrics: | ||
receivers: [otlp] | ||
exporters: [prometheus] | ||
traces: | ||
receivers: [otlp] | ||
exporters: [otlp] |
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,12 @@ | ||
global: | ||
scrape_interval: 10s | ||
|
||
scrape_configs: | ||
- job_name: 'imalive' | ||
static_configs: | ||
- targets: ['imalive-api:8080'] | ||
metrics_path: '/v1/prom' | ||
scheme: http | ||
- job_name: 'opentelemetry' | ||
static_configs: | ||
- targets: ['otel-collector:8889'] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.5.2 | ||
3.6.0 |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
from utils.health import health | ||
from fastapi import APIRouter | ||
|
||
from utils.otel import get_otel_tracer | ||
from utils.health import health | ||
|
||
router = APIRouter() | ||
|
||
@router.get("") | ||
def get_health(): | ||
return health() | ||
with get_otel_tracer().start_as_current_span("imalive-health-get-route"): | ||
return health() | ||
|
||
@router.post("") | ||
def post_health(): | ||
return health() | ||
with get_otel_tracer().start_as_current_span("imalive-health-post-route"): | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
from fastapi import APIRouter | ||
from fastapi.responses import JSONResponse | ||
|
||
from utils.otel import get_otel_tracer | ||
from utils.manifests import get_manifest_as_dict | ||
|
||
router = APIRouter() | ||
|
||
@router.get("") | ||
def get_manifest(): | ||
manifest = get_manifest_as_dict() | ||
with get_otel_tracer().start_as_current_span("imalive-manifest-route"): | ||
manifest = get_manifest_as_dict() | ||
|
||
if manifest['status'] == 'error': | ||
return JSONResponse(content=manifest, status_code=500) | ||
else: | ||
return manifest | ||
if manifest['status'] == 'error': | ||
return JSONResponse(content=manifest, status_code=500) | ||
else: | ||
return manifest |
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,8 +1,11 @@ | ||
from utils.metrics import all_metrics | ||
from fastapi import APIRouter | ||
|
||
from utils.otel import get_otel_tracer | ||
from utils.metrics import all_metrics | ||
|
||
router = APIRouter() | ||
|
||
@router.get("") | ||
def get_metrics(): | ||
return all_metrics() | ||
with get_otel_tracer().start_as_current_span("imalive-metrics-route"): | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
from utils.health import health | ||
from fastapi import APIRouter | ||
|
||
from utils.otel import get_otel_tracer | ||
from utils.health import health | ||
|
||
router = APIRouter() | ||
|
||
@router.get("/") | ||
def get_root(): | ||
return health() | ||
with get_otel_tracer().start_as_current_span("imalive-root-route"): | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import re | ||
|
||
from prometheus_client import Gauge | ||
from opentelemetry.metrics import Observation | ||
|
||
from utils.otel import get_otel_meter | ||
|
||
_numeric_value_pattern = r"-?\d+\.\d+" | ||
_current_gauge_values = {} | ||
|
||
def create_gauge(name, description): | ||
_current_gauge_values[name] = { | ||
'val': 0.0, | ||
'desc': description | ||
} | ||
|
||
def observable_gauge_func(_): | ||
yield Observation(_current_gauge_values[name]['val']) | ||
|
||
get_otel_meter().create_observable_gauge( | ||
name = name, | ||
description = description, | ||
callbacks=[observable_gauge_func] | ||
) | ||
|
||
return Gauge( | ||
name, | ||
description | ||
) | ||
|
||
def set_gauge(gauge, value): | ||
match = re.search(_numeric_value_pattern, "{}".format(value)) | ||
|
||
if match: | ||
val = float(match.group()) | ||
gauge.set(val) | ||
_current_gauge_values[gauge._name]['val'] = val |
Oops, something went wrong.