Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds loggers to report flow #3872

Merged
merged 6 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="080091", 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 @@ -17,6 +18,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 @@ -191,6 +194,8 @@ def save_report_data(
)

create_ooi(octopoes_api_connector, bytes_client, parent_report_ooi, observed_at)

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


Expand Down Expand Up @@ -246,6 +251,7 @@ def save_aggregate_report_data(
raw=ReportDataDict(data | input_data).model_dump_json().encode(), manual_mime_types={"openkat/report"}
)

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


Expand Down Expand Up @@ -351,5 +357,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="080071", 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 @@ -126,6 +126,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="080073", reports=report_references)
messages.success(self.request, _("Deletion successful."))

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

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

return new_report_ooi

Expand Down Expand Up @@ -297,6 +299,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="080071", 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="080082", 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="080081", 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="080083", schedule_id=schedule_id)
except (HTTPStatusError, ConnectError):
raise SchedulerHTTPError()

Expand Down