-
Notifications
You must be signed in to change notification settings - Fork 34
[ENHANCEMENT] Record metrics for Scribe #2090
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
Conversation
WalkthroughThe pull request integrates metrics instrumentation into the AIChatCompletionRoutes class by injecting a MetricFactory dependency. The implementation wraps the OpenRag HTTP client call to proxyChatCompletions with a timer metric decorator labeled "JMAP-ai-chat-completion" to measure execution time. The constructor signature is updated to accept the additional MetricFactory parameter, while all existing request handling and response logic remains unchanged. Possibly related PRs
Suggested reviewers
Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tmail-backend/tmail-third-party/ai-bot/src/main/scala/com/linagora/tmail/jmap/aibot/AIChatCompletionRoutes.scala (1)
84-85: Extract the metric name to a constant to align with project conventions.The codebase follows an established pattern of extracting metric names to constants (e.g.,
LOCAL_DELIVERED_MAILS_METRIC_NAMEin TmailLocalDelivery.scala). Extract"JMAP-ai-chat-completion"to a constant for consistency and maintainability:Proposed refactor
At the object level (after line 46), add:
object AIChatCompletionRoutes { val LOGGER: Logger = LoggerFactory.getLogger(classOf[AIChatCompletionRoutes]) + private val JMAP_AI_CHAT_COMPLETION_METRIC: String = "JMAP-ai-chat-completion" }Then update the usage at line 84:
- .flatMap(input => SMono.fromPublisher(metricFactory.decoratePublisherWithTimerMetric("JMAP-ai-chat-completion", + .flatMap(input => SMono.fromPublisher(metricFactory.decoratePublisherWithTimerMetric(JMAP_AI_CHAT_COMPLETION_METRIC, openRagHttpClient.proxyChatCompletions(input))))
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tmail-backend/tmail-third-party/ai-bot/src/main/scala/com/linagora/tmail/jmap/aibot/AIChatCompletionRoutes.scala
🔇 Additional comments (2)
tmail-backend/tmail-third-party/ai-bot/src/main/scala/com/linagora/tmail/jmap/aibot/AIChatCompletionRoutes.scala (2)
38-38: No action required for the import and metric instrumentation.The
MetricFactoryimport from Apache James metrics API is correct and widely used throughout the codebase. The constructor parameter addition is not a breaking change because the class uses Guice dependency injection (@Inject()annotation), which automatically resolves and injects theMetricFactory. No manual updates to instantiation sites are needed. The metric name "JMAP-ai-chat-completion" follows the codebase naming conventions.
49-51: The constructor change is properly handled by the dependency injection framework and does not require additional verification.Since the class uses
@Inject()annotation, Guice automatically resolves all constructor parameters includingMetricFactory, which is a standard Apache James library component. The DI binding inAiBotCapability.scalacorrectly registers the class using.to(classOf[AIChatCompletionRoutes]), and no manual instantiations exist. The test infrastructure inherits from James's standard test modules, which provideMetricFactoryautomatically. This is a safe pattern consistent with other JMAPRoutes implementations in the codebase.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.