Skip to content

Conversation

@chibenwa
Copy link
Member

@chibenwa chibenwa commented Jan 6, 2026

Summary by CodeRabbit

  • Chores
    • Added performance monitoring to AI chat completion requests to track response times and system metrics.

✏️ Tip: You can customize this high-level summary in your review settings.

@chibenwa chibenwa self-assigned this Jan 6, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 6, 2026

Walkthrough

The 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

  • quantranhong1999

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title references 'Scribe' but the changeset adds metrics for 'JMAP-ai-chat-completion', which is part of the AI bot functionality, not Scribe. Update the title to reflect the actual change, such as '[ENHANCEMENT] Record metrics for AI chat completion' or '[ENHANCEMENT] Add timing metrics to AIChatCompletionRoutes'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

Copy link

@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: 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_NAME in 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

📥 Commits

Reviewing files that changed from the base of the PR and between fc7e3df and 188ecf7.

📒 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 MetricFactory import 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 the MetricFactory. 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 including MetricFactory, which is a standard Apache James library component. The DI binding in AiBotCapability.scala correctly registers the class using .to(classOf[AIChatCompletionRoutes]), and no manual instantiations exist. The test infrastructure inherits from James's standard test modules, which provide MetricFactory automatically. This is a safe pattern consistent with other JMAPRoutes implementations in the codebase.

@quantranhong1999 quantranhong1999 merged commit 7e3ccc2 into linagora:master Jan 7, 2026
6 checks passed
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.

3 participants