Skip to content

feat(git-integration): add metrics to service executions#3517

Merged
mbani01 merged 2 commits into
mainfrom
feat/save_metrics_for_serviceExecutions
Oct 15, 2025
Merged

feat(git-integration): add metrics to service executions#3517
mbani01 merged 2 commits into
mainfrom
feat/save_metrics_for_serviceExecutions

Conversation

@mbani01
Copy link
Copy Markdown
Contributor

@mbani01 mbani01 commented Oct 15, 2025

This pull request introduces a new metrics field to the serviceExecutions table and the associated data model, enabling the storage and querying of service-specific execution metrics (such as commit counts or AI cost). The changes include database migrations, model and CRUD updates, and logic to collect and persist relevant metrics in both commit and maintainer services.

Database schema changes:

  • Added a metrics column of type JSONB to the serviceExecutions table, with a GIN index for efficient querying, and provided a corresponding down migration for rollback. [1] [2]

Model and persistence updates:

  • Updated the ServiceExecution model to include a metrics dictionary, and modified the to_db_dict method and CRUD logic to serialize and persist this field. [1] [2] [3] [4] [5]

Commit service metrics tracking:

  • Enhanced the commit processing logic to track and update metrics such as total_commits, processed_commits, bad_commits, and total_activities, and to save these in the metrics field of each execution. [1] [2] [3] [4] [5]

Maintainer service metrics tracking:

  • Updated the maintainer processing logic to track and save ai_cost and maintainers_found in the metrics field, including capturing ai_cost on errors. [1] [2] [3] [4]

@mbani01 mbani01 requested a review from Copilot October 15, 2025 12:49
@mbani01 mbani01 self-assigned this Oct 15, 2025
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

Copy link
Copy Markdown
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 PR adds a metrics field to the serviceExecutions table to track service-specific execution metrics such as commit counts and AI costs. The changes enable better observability and monitoring of service operations by persisting structured metrics data alongside execution records.

Key changes:

  • Added metrics JSONB column to serviceExecutions table with GIN index for efficient querying
  • Updated data model and persistence layer to serialize and store metrics as JSON
  • Instrumented commit service to track total/processed/bad commits and activity counts
  • Instrumented maintainer service to track AI costs and maintainer counts

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
backend/src/database/migrations/V1760530860__addMetricsToServiceExecution.sql Adds metrics JSONB column with GIN index to serviceExecutions table
backend/src/database/migrations/U1760530860__addMetricsToServiceExecution.sql Down migration to remove metrics column and index
services/apps/git_integration/src/crowdgit/models/service_execution.py Adds metrics field to ServiceExecution model with JSON serialization
services/apps/git_integration/src/crowdgit/database/crud.py Updates save_service_execution to persist metrics column
services/apps/git_integration/src/crowdgit/services/commit/commit_service.py Adds commit processing metrics tracking (total, processed, bad commits, activities)
services/apps/git_integration/src/crowdgit/services/maintainer/maintainer_service.py Adds AI cost and maintainer count tracking to maintainer service

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

"errorCode": self.error_code,
"errorMessage": self.error_message,
"executionTimeSec": self.execution_time_sec,
"metrics": orjson.dumps(self.metrics).decode(),
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

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

The orjson.dumps() call will return bytes, but PostgreSQL JSONB columns expect JSON text or can accept the dict directly. Since the metrics parameter in the INSERT query ($7) is passed as a string after .decode(), PostgreSQL will need to parse it. Consider passing self.metrics directly as a dict instead of serializing it, which allows the database driver to handle JSON serialization natively and is more efficient.

Suggested change
"metrics": orjson.dumps(self.metrics).decode(),
"metrics": self.metrics,

Copilot uses AI. Check for mistakes.
Comment on lines +476 to +477
# Capture AI cost even on error if it's a CrowdGitError with ai_cost
if isinstance(e, CrowdGitError) and hasattr(e, "ai_cost"):
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

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

[nitpick] The comment references capturing AI cost from CrowdGitError with ai_cost attribute, but this pattern assumes a specific error structure that may not be consistently available. Consider documenting which specific CrowdGitError subclasses provide the ai_cost attribute, or implement a more explicit protocol (e.g., a mixin or base class method) to make this contract clearer and more maintainable.

Suggested change
# Capture AI cost even on error if it's a CrowdGitError with ai_cost
if isinstance(e, CrowdGitError) and hasattr(e, "ai_cost"):
# Capture AI cost even on error if it's a CrowdGitError that implements the AICostCarrier protocol.
# See: crowdgit.errors.AICostCarrier
if isinstance(e, CrowdGitError) and isinstance(e, getattr(__import__("crowdgit.errors", fromlist=["AICostCarrier"]), "AICostCarrier", ())):

Copilot uses AI. Check for mistakes.
@mbani01 mbani01 merged commit ab48f22 into main Oct 15, 2025
13 checks passed
@mbani01 mbani01 deleted the feat/save_metrics_for_serviceExecutions branch October 15, 2025 12:52
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.

2 participants