-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(release): backend monitoring changes, enable cloudfront logging,…
… optional cognito domain in ingestor lambda, make data access role optional in ingestor (#386) ### Added - [feat: enable cloudfront logging #375](#375) ### Changed/Updated None ### Fixed - [fix: backend monitoring changes #371](#371) - [fix: optional cognito domain in ingestor lambda #377](#377) - [fix: make data access role optional in ingestor #382](#382) - [fix: make data access role optional in ingest runtime #383](#383)
- Loading branch information
Showing
16 changed files
with
132 additions
and
55 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
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
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,42 +1,61 @@ | ||
"""Observability utils""" | ||
import json | ||
from typing import Callable | ||
|
||
from aws_lambda_powertools import Logger, Metrics, Tracer | ||
from aws_lambda_powertools import Logger, Metrics, Tracer, single_metric | ||
from aws_lambda_powertools.metrics import MetricUnit # noqa: F401 | ||
from src.config import ApiSettings | ||
|
||
from fastapi import Request, Response | ||
from fastapi.routing import APIRoute | ||
|
||
settings = ApiSettings() | ||
|
||
logger: Logger = Logger(service="raster-api", namespace="veda-backend") | ||
metrics: Metrics = Metrics(service="raster-api", namespace="veda-backend") | ||
metrics: Metrics = Metrics(namespace="veda-backend") | ||
metrics.set_default_dimensions(environment=settings.stage, service="raster-api") | ||
tracer: Tracer = Tracer() | ||
|
||
|
||
class LoggerRouteHandler(APIRoute): | ||
"""Extension of base APIRoute to add context to log statements, as well as record usage metricss""" | ||
"""Extension of base APIRoute to add context to log statements, as well as record usage metrics""" | ||
|
||
def get_route_handler(self) -> Callable: | ||
"""Overide route handler method to add logs, metrics, tracing""" | ||
original_route_handler = super().get_route_handler() | ||
|
||
async def route_handler(request: Request) -> Response: | ||
# Add fastapi context to logs | ||
body = await request.body() | ||
try: | ||
body_json = json.loads(body) | ||
except json.decoder.JSONDecodeError: | ||
body_json = None | ||
|
||
ctx = { | ||
"path": request.url.path, | ||
"path_params": request.path_params, | ||
"body": body_json, | ||
"route": self.path, | ||
"method": request.method, | ||
} | ||
logger.append_keys(fastapi=ctx) | ||
logger.info("Received request") | ||
metrics.add_metric( | ||
name="/".join( | ||
str(request.url.path).split("/")[:2] | ||
), # enough detail to capture search IDs, but not individual tile coords | ||
|
||
with single_metric( | ||
name="RequestCount", | ||
unit=MetricUnit.Count, | ||
value=1, | ||
) | ||
default_dimensions=metrics.default_dimensions, | ||
namespace="veda-backend", | ||
) as metric: | ||
metric.add_dimension( | ||
name="route", value=f"{request.method} {self.path}" | ||
) | ||
|
||
tracer.put_annotation(key="path", value=request.url.path) | ||
tracer.capture_method(original_route_handler)(request) | ||
|
||
return await original_route_handler(request) | ||
|
||
return route_handler |
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
Oops, something went wrong.