Skip to content

Handle processing_service_name parameters in requests from workers#1117

Open
carlosgjs wants to merge 8 commits intoRolnickLab:mainfrom
uw-ssec:carlosg/servname2
Open

Handle processing_service_name parameters in requests from workers#1117
carlosgjs wants to merge 8 commits intoRolnickLab:mainfrom
uw-ssec:carlosg/servname2

Conversation

@carlosgjs
Copy link
Collaborator

@carlosgjs carlosgjs commented Feb 5, 2026

Summary

This pull request introduces a new optional query parameter, processing_service_name, to several job-related API endpoints. This parameter allows clients to specify the name of the processing service making the request, which is then logged for auditing and debugging purposes. The change also removes unused OpenAPI parameter definitions in ami/utils/requests.py (previously moved to ami/jobs/schemas.py).

The parameter is optional for easier deployment of this and the corresponding change in the worker, see:

RolnickLab/ami-data-companion#108

Related Issues

Closes #1112
Support for #1087

Testing Logs

Logs:

[2026-02-04 17:49:15] INFO Job 60 result received from processing service: AMI Data Companion (Carloss-MacBook-Pro.local)
[2026-02-04 17:49:13] INFO Job 60 tasks (4) requested by processing service: AMI Data Companion (Carloss-MacBook-Pro.local)

Deployment Notes

Include instructions if this PR requires specific steps for its deployment (database migrations, config changes, etc.)

Checklist

  • I have tested these changes appropriately.
  • I have added and/or modified relevant tests.
  • I updated relevant documentation or comments.
  • I have verified that this PR follows the project's coding standards.
  • Any dependent changes have already been merged to main.

Summary by CodeRabbit

  • New Features
    • API endpoints now accept an optional processing_service_name parameter; it is documented and logged to improve request traceability.
  • Behavior Changes
    • Classification default resolution can now honor request-scoped settings, which may affect default threshold selection.
  • Tests
    • Added tests covering the processing_service_name parameter across job endpoints.

@netlify
Copy link

netlify bot commented Feb 5, 2026

👷 Deploy request for antenna-ssec pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 5b53380

@netlify
Copy link

netlify bot commented Feb 5, 2026

Deploy Preview for antenna-preview canceled.

Name Link
🔨 Latest commit 5b53380
🔍 Latest deploy log https://app.netlify.com/projects/antenna-preview/deploys/698676955649f80008d86289

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

Adds a new optional processing_service_name query parameter to job endpoints (list, tasks, result) with logging of its value; updates default classification threshold resolution to be request-aware and removes four module-level OpenAPI parameter exports; tests added for the new query parameter.

Changes

Cohort / File(s) Summary
Processing Service Name
ami/jobs/schemas.py, ami/jobs/views.py, ami/jobs/tests.py
Introduce processing_service_name_param OpenApiParameter, document it on list, tasks, and result endpoints, add _log_processing_service_name helper and log calls; add tests exercising the query parameter.
Request-aware Default Threshold
ami/utils/requests.py
Update get_default_classification_threshold(project=None, request=None) to accept request and resolve thresholds from request/apply-defaults logic; remove four module-level OpenAPI parameter exports (project_id_doc_param, ids_only_param, incomplete_only_param, batch_param).

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant API as API (Django)
    participant JobView as JobViewSet
    participant Logger as Logger

    Client->>API: GET /jobs?processing_service_name=worker-A
    API->>JobView: dispatch request -> list/tasks/result
    JobView->>JobView: extract "processing_service_name"
    JobView->>Logger: _log_processing_service_name(context, "list/tasks/result")
    Logger-->>JobView: acknowledged
    JobView-->>API: return 200 response
    API-->>Client: 200 OK (payload)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

backend

Suggested reviewers

  • mihow

Poem

🐰 I hopped into the job queue tonight,
A name from workers now shines so bright,
I logged each caller with a joyful nudge,
Streams whisper secrets, no longer a grudge.
Hop hop — munched carrots, now back to my burrow light.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding support for handling processing_service_name parameters in worker requests.
Description check ✅ Passed The PR description includes a clear summary, list of changes, related issues, testing evidence (log examples), and a relevant checklist with most items completed.
Linked Issues check ✅ Passed The code changes fully implement the objective from issue #1112 by adding processing_service_name parameter logging to job endpoints (list, tasks, result) for improved worker visibility and auditing.
Out of Scope Changes check ✅ Passed All code changes are directly related to the processing_service_name feature and cleanup of unused OpenAPI parameters as described in the PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@carlosgjs carlosgjs marked this pull request as ready for review February 5, 2026 01:29
Copilot AI review requested due to automatic review settings February 5, 2026 01:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds logging capabilities to track which processing services are making requests to job-related API endpoints. The changes introduce an optional processing_service_name query parameter to the list, tasks, and result endpoints, which is logged when provided. The PR also consolidates OpenAPI parameter definitions by moving them from ami/utils/requests.py to ami/jobs/schemas.py.

Changes:

  • Added processing_service_name query parameter to job list, tasks, and result endpoints
  • Created _log_processing_service_name() helper function to log service names from requests
  • Removed unused OpenAPI parameter imports and definitions from ami/utils/requests.py

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
ami/utils/requests.py Removed unused OpenAPI imports and parameter definitions that were moved to ami/jobs/schemas.py
ami/jobs/schemas.py Added processing_service_name_param OpenAPI parameter definition
ami/jobs/views.py Imported new parameter, added logging calls in list/tasks/result endpoints, implemented _log_processing_service_name() helper function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 24 to 29
processing_service_name_param = OpenApiParameter(
name="processing_service_name",
description="Inform the name of the calling processing service",
required=False,
type=str,
)
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new processing_service_name parameter lacks test coverage. Since the repository has comprehensive test coverage for job endpoints (see existing tests for tasks and result endpoints in ami/jobs/tests.py), tests should be added to verify that the parameter is correctly logged when provided and that the endpoints work correctly when the parameter is omitted.

Copilot uses AI. Check for mistakes.
]
)
def list(self, request, *args, **kwargs):
_ = _log_processing_service_name(request, "list requested", logger)
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The context string format is inconsistent across different endpoints. The "list" endpoint uses "list requested" without job information, while "tasks" uses "tasks ({batch}) requested for job {job.pk}" and "result" uses "result received for job {job.pk}". Consider standardizing the format to either include job information consistently or use a more descriptive context that produces clearer log messages. For example: "Job {job.pk}: {action}" format would be clearer.

Suggested change
_ = _log_processing_service_name(request, "list requested", logger)
_ = _log_processing_service_name(request, "Jobs: list requested", logger)

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@ami/jobs/views.py`:
- Around line 335-351: The function _log_processing_service_name can return None
when the "processing_service_name" query param is missing, so update its return
type annotation from -> str to include None (either -> str | None for Python
3.10+ or -> Optional[str] with "from typing import Optional" for older
versions); ensure you add the Optional import if used and run a quick type-check
to confirm no other callers require changes.

@carlosgjs carlosgjs requested a review from mihow February 5, 2026 01:37
return default_threshold


project_id_doc_param = OpenApiParameter(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding a good home for these parameters!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: PSv2 - Have visibility into which workers are subscribed to a job

3 participants