Skip to content

Commit

Permalink
Adds loggers to report flow (#3872)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Klopper <[email protected]>
  • Loading branch information
madelondohmen and underdarknl authored Nov 28, 2024
1 parent c86325a commit fb59a14
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions rocky/reports/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ def create_report_recipe(
ooi=report_recipe,
observed_at=datetime.now(timezone.utc),
)
logger.info("ReportRecipe created", event_code=800091, report_recipe=report_recipe)
return report_recipe

def get_input_data(self) -> dict[str, Any]:
Expand Down
7 changes: 7 additions & 0 deletions rocky/reports/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any
from uuid import uuid4

import structlog
from django.contrib import messages
from django.utils.translation import gettext_lazy as _
from tools.ooi_helpers import create_ooi
Expand All @@ -18,6 +19,8 @@
from reports.report_types.multi_organization_report.report import MultiOrganizationReport, collect_report_data
from reports.views.base import BaseReportView, ReportDataDict

logger = structlog.get_logger(__name__)


def collect_reports(observed_at: datetime, octopoes_connector: OctopoesAPIConnector, ooi_pks: list[str], report_types):
error_reports = []
Expand Down Expand Up @@ -194,6 +197,8 @@ def save_report_data(
)

create_ooi(octopoes_api_connector, bytes_client, parent_report_ooi, observed_at)

logger.info("Report created", event_code=800071, report=parent_report_ooi)
return parent_report_ooi


Expand Down Expand Up @@ -271,6 +276,7 @@ def save_aggregate_report_data(

create_ooi(octopoes_api_connector, bytes_client, aggregate_sub_report_ooi, observed_at)

logger.info("Report created", event_code=800071, report=report_ooi)
return report_ooi


Expand Down Expand Up @@ -376,5 +382,6 @@ def save_report(self, report_names: list) -> Report:
)

create_ooi(self.octopoes_api_connector, self.bytes_client, report_ooi, observed_at)
logger.info("Report created", event_code=800071, report=report_ooi)

return report_ooi
3 changes: 3 additions & 0 deletions rocky/reports/views/report_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def run_bulk_actions(self) -> None:

def delete_reports(self, report_references: list[Reference]) -> None:
self.octopoes_api_connector.delete_many(report_references, datetime.now(timezone.utc))
logger.info("Reports deleted", event_code=800073, reports=report_references)
messages.success(self.request, _("Deletion successful."))

def rerun_reports(self, report_references: list[str]) -> None:
Expand Down Expand Up @@ -247,6 +248,7 @@ def recreate_report(
)

create_ooi(self.octopoes_api_connector, self.bytes_client, new_report_ooi, observed_at)
logger.info("Report created", event_code=800071, report=new_report_ooi)

return new_report_ooi

Expand Down Expand Up @@ -349,6 +351,7 @@ def rename_reports(self, report_references: list[str]) -> None:
error_reports.append(f'"{report_ooi.name}"')

if not error_reports:
logger.info("Reports created", event_code=800071, reports=report_references)
return messages.success(self.request, _("Reports successfully renamed."))

return messages.error(self.request, _("Report {} could not be renamed.").format(", ".join(error_reports)))
Expand Down
3 changes: 3 additions & 0 deletions rocky/rocky/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,15 @@ def patch_schedule(self, schedule_id: str, params: dict[str, Any]) -> None:
try:
response = self._client.patch(f"/schedules/{schedule_id}", json=params)
response.raise_for_status()
logger.info("Schedule updated", event_code=800082, schedule_id=schedule_id, params=params)
except (HTTPStatusError, ConnectError):
raise SchedulerHTTPError()

def post_schedule(self, schedule: ScheduleRequest) -> ScheduleResponse:
try:
res = self._client.post("/schedules", json=schedule.model_dump(exclude_none=True))
res.raise_for_status()
logger.info("Schedule created", event_code=800081, schedule=schedule)
return ScheduleResponse.model_validate_json(res.content)
except (ValidationError, HTTPStatusError, ConnectError):
raise SchedulerValidationError(extra_message="Report schedule failed: ")
Expand All @@ -314,6 +316,7 @@ def delete_schedule(self, schedule_id: str) -> None:
try:
response = self._client.delete(f"/schedules/{schedule_id}")
response.raise_for_status()
logger.info("Schedule deleted", event_code=800083, schedule_id=schedule_id)
except (HTTPStatusError, ConnectError):
raise SchedulerHTTPError()

Expand Down

0 comments on commit fb59a14

Please sign in to comment.