feat(git-integration): add metrics to service executions#3517
Conversation
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
There was a problem hiding this comment.
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
metricsJSONB column toserviceExecutionstable 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(), |
There was a problem hiding this comment.
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.
| "metrics": orjson.dumps(self.metrics).decode(), | |
| "metrics": self.metrics, |
| # Capture AI cost even on error if it's a CrowdGitError with ai_cost | ||
| if isinstance(e, CrowdGitError) and hasattr(e, "ai_cost"): |
There was a problem hiding this comment.
[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.
| # 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", ())): |
This pull request introduces a new
metricsfield to theserviceExecutionstable 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:
metricscolumn of typeJSONBto theserviceExecutionstable, with a GIN index for efficient querying, and provided a corresponding down migration for rollback. [1] [2]Model and persistence updates:
ServiceExecutionmodel to include ametricsdictionary, and modified theto_db_dictmethod and CRUD logic to serialize and persist this field. [1] [2] [3] [4] [5]Commit service metrics tracking:
total_commits,processed_commits,bad_commits, andtotal_activities, and to save these in themetricsfield of each execution. [1] [2] [3] [4] [5]Maintainer service metrics tracking:
ai_costandmaintainers_foundin themetricsfield, including capturingai_coston errors. [1] [2] [3] [4]