Repository navigation
Analytics Config CRUD Methods - #215
Merged
Merged
Conversation
Duckierstone42
marked this pull request as ready for review
October 20, 2025 20:58
Contributor
There was a problem hiding this comment.
Disclaimer: This comment was AI-generated and is not necessarily completely accurate. Please take code comments with a grain of salt.
Greptile Overview
Summary
This PR implements Analytics Config CRUD operations to enable per-project analytics configuration storage and retrieval. The implementation follows the existing patterns from email and file service configs.
Key Changes:
- Created
AnalyticsServiceConfigproto definitions and Prisma schema with composite primary key(id, environment) - Implemented full CRUD operations across db-service, analytics-service, and api-gateway layers
- Integrated analytics config lookup into analytics event logging, replacing hardcoded API keys with dynamic config retrieval
- Updated analytics proto to use
projectIdandenvironmentinstead of hardcodedapiKeyfields - Added comprehensive e2e tests covering all requirements from issue #213
Architecture:
- API Gateway exposes REST endpoints (
/analytics/config) that extract projectId from API key - DB Service handles Prisma operations with proper error handling (P2002 for duplicates, P2025 for not found)
- Analytics Service retrieves configs via gRPC to authenticate with bog-analytics
- Composite key
(id, environment)allows multiple configs per project across environments
Test Coverage:
All required test cases are implemented and passing:
- Creating analytics configs (including duplicate handling)
- Reading configs (including non-existent)
- Updating configs (including non-existent)
- Deleting configs (including non-existent and already deleted)
- Full integration testing across all service layers
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The implementation is well-structured, follows existing patterns from email/file service configs, includes comprehensive test coverage (all tests passing), and properly handles edge cases with appropriate error handling
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| packages/proto/definitions/analytics_config.proto | 5/5 | Added new proto definitions for Analytics Config CRUD operations with proper message types and service definition |
| packages/db-service/prisma/schema.prisma | 5/5 | Added AnalyticsServiceConfig model with composite primary key (id, environment) matching email/file service patterns |
| packages/db-service/src/modules/analytics_config/analytics_config.controller.ts | 5/5 | gRPC controller with proper error handling for Prisma errors (P2002 for duplicates, P2025 for not found) |
| packages/analytics-service/src/modules/analytics/analytics.service.ts | 5/5 | Integrated analytics config lookup for authentication, replacing hardcoded API keys with dynamic config retrieval |
| packages/api-gateway/src/modules/analytics_config/analytics_config.controller.ts | 5/5 | REST API endpoints for analytics config CRUD with proper validation, Swagger docs, and auth integration |
| packages/proto/definitions/analytics.proto | 5/5 | Replaced hardcoded API keys with projectId and environment fields for dynamic analytics config lookup |
Sequence Diagram
sequenceDiagram
participant Client
participant APIGateway
participant AnalyticsService
participant AnalyticsConfigService
participant DBService
participant Database
Note over Client,Database: Create Analytics Config Flow
Client->>APIGateway: POST /analytics/config<br/>{analyticsKey}
APIGateway->>APIGateway: Extract projectId & environment from API key
APIGateway->>DBService: createAnalyticsConfig(projectId, environment, analyticsKey)
DBService->>Database: INSERT INTO AnalyticsServiceConfig
Database-->>DBService: Return config
DBService-->>APIGateway: AnalyticsServiceConfig
APIGateway-->>Client: 201 Created
Note over Client,Database: Log Event with Analytics Config Flow
Client->>AnalyticsService: logClickEvent(projectId, environment, ...)
AnalyticsService->>AnalyticsConfigService: getAnalyticsKey(projectId, environment)
AnalyticsConfigService->>DBService: readAnalyticsConfig(id, environment)
DBService->>Database: SELECT FROM AnalyticsServiceConfig<br/>WHERE id=projectId AND environment
Database-->>DBService: config.analyticsKey
DBService-->>AnalyticsConfigService: analyticsKey
AnalyticsConfigService-->>AnalyticsService: analyticsKey
AnalyticsService->>AnalyticsService: authenticate(analyticsKey)
AnalyticsService->>AnalyticsService: logClickEvent to bog-analytics
AnalyticsService-->>Client: Event logged
Note over Client,Database: Update Analytics Config Flow
Client->>APIGateway: PUT /analytics/config/:projectId<br/>{analyticsKey}
APIGateway->>DBService: updateAnalyticsConfig(id, environment, analyticsKey)
DBService->>Database: UPDATE AnalyticsServiceConfig<br/>WHERE id AND environment
Database-->>DBService: Updated config
DBService-->>APIGateway: AnalyticsServiceConfig
APIGateway-->>Client: 200 OK
Note over Client,Database: Delete Analytics Config Flow
Client->>APIGateway: DELETE /analytics/config/:projectId
APIGateway->>DBService: deleteAnalyticsConfig(id, environment)
DBService->>Database: DELETE FROM AnalyticsServiceConfig<br/>WHERE id AND environment
Database-->>DBService: Deleted config
DBService-->>APIGateway: AnalyticsServiceConfig
APIGateway-->>Client: 200 OK
29 files reviewed, no comments
Contributor
|
LGTM, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#213
Tests passing, also added integration into analytics routes.