- Change manifests for Prometheus installation

- Change instructions for deploying Prometheus stack and Pushgateway
- Additional grouping to pushgateway to avoid overwriting of metrics in different pods / processes
- Bugfix to ensure good retrieval of css en js files in eveai_app
This commit is contained in:
Josako
2025-09-30 14:56:08 +02:00
parent a76f87ba75
commit fa452e4934
14 changed files with 179 additions and 109 deletions

View File

@@ -559,12 +559,24 @@ class BusinessEvent:
self._log_buffer = []
def _push_to_gateway(self):
# Push metrics to the gateway
# Push metrics to the gateway with grouping key to avoid overwrites across pods/processes
try:
# Determine grouping labels
pod_name = current_app.config.get('POD_NAME', current_app.config.get('COMPONENT_NAME', 'dev'))
pod_namespace = current_app.config.get('POD_NAMESPACE', current_app.config.get('FLASK_ENV', 'dev'))
worker_id = str(os.getpid())
grouping_key = {
'instance': pod_name,
'namespace': pod_namespace,
'process': worker_id,
}
push_to_gateway(
current_app.config['PUSH_GATEWAY_URL'],
job=current_app.config['COMPONENT_NAME'],
registry=REGISTRY
registry=REGISTRY,
grouping_key=grouping_key,
)
except Exception as e:
current_app.logger.error(f"Failed to push metrics to Prometheus Push Gateway: {e}")

View File

@@ -110,28 +110,39 @@ def get_pagination_html(pagination, endpoint, **kwargs):
def asset_url(logical_path: str):
"""
Resolve an asset logical path to a hashed URL using Parcel manifest when available.
Fallback to the original logical path under /static/ if manifest is missing.
Return a URL that respects STATIC_URL (CDN) when configured; otherwise serve from /static/.
Examples:
- asset_url('dist/chat-client.js') -> '/static/dist/chat-client.abc123.js'
- asset_url('dist/chat-client.css') -> '/static/dist/chat-client.def456.css'
- asset_url('dist/chat-client.js') -> 'https://cdn/.../dist/chat-client.abc123.js' (when STATIC_URL set)
- asset_url('dist/chat-client.css') -> '/static/dist/chat-client.def456.css' (when STATIC_URL not set)
"""
if not logical_path:
return logical_path
try:
from common.utils.asset_manifest import resolve_asset
resolved = resolve_asset(logical_path)
if not resolved:
return f"/static/{logical_path.lstrip('/')}"
# If resolved is already an absolute URL starting with /static or http(s), return as is
if resolved.startswith('/static/') or resolved.startswith('http://') or resolved.startswith('https://'):
# Resolve logical to possibly hashed path
resolved = resolve_asset(logical_path) or logical_path
# If manifest returns an absolute URL, return as-is
if resolved.startswith('http://') or resolved.startswith('https://'):
return resolved
# If it starts with 'dist/', prefix /static/
if resolved.startswith('dist/'):
return '/static/' + resolved
# Otherwise, best effort: ensure it lives under /static/
return '/static/' + resolved.lstrip('/')
# Normalize: strip any leading '/static/' and leading '/'
if resolved.startswith('/static/'):
rel = resolved[len('/static/'):]
else:
rel = resolved.lstrip('/')
# Build with STATIC_URL if configured
static_base = (current_app.config.get('STATIC_URL') or '').rstrip('/')
if static_base:
return f"{static_base}/{rel}"
# Fallback to app static
return f"/static/{rel}"
except Exception:
return f"/static/{logical_path.lstrip('/')}"
# Conservative fallback also respecting STATIC_URL
static_base = (current_app.config.get('STATIC_URL') or '').rstrip('/')
rel = logical_path.lstrip('/')
return f"{static_base}/{rel}" if static_base else f"/static/{rel}"
def register_filters(app):