Skip to content
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

fix: replaced the stopwatch implementation with micrometer #37200

Conversation

Sai6347
Copy link

@Sai6347 Sai6347 commented Nov 4, 2024

Bug Issue

Description:
The stopwatch metrics are only being sent to logs, and we haven't been able to fully utilize them.
With Micrometer now handling our metrics collection, we can eliminate the stopwatch metrics in CommonGitFileUtils, as they no longer add value and are limited to log outputs.

Summary by CodeRabbit

  • New Features

    • Introduced new constants related to Git operations for improved clarity in messaging.
    • Enhanced observability with the integration of a more robust performance measurement framework.
  • Bug Fixes

    • Improved error handling during Git operations, ensuring accurate tracking of failures.
  • Refactor

    • Replaced the existing timing mechanism with a structured approach using Micrometer's Timer and ObservationHelper for better performance monitoring.

@Sai6347 Sai6347 requested a review from a team as a code owner November 4, 2024 09:50
Copy link
Contributor

coderabbitai bot commented Nov 4, 2024

Walkthrough

The changes in this pull request involve the addition of new constants to the CommonConstants class for Git operations and a significant update to the CommonGitFileUtilsCE class. The latter includes the removal of the Stopwatch class in favor of the Timer class from the Micrometer library for improved performance measurement and observability. This update introduces new fields for MeterRegistry and ObservationHelper, enhancing the application's ability to track and analyze performance metrics during Git operations.

Changes

File Path Change Summary
app/server/appsmith-git/src/main/java/com/appsmith/git/constants/CommonConstants.java Added constants: GIT_SAVE_ARTIFACT, TIME_TAKEN_TO_SAVE_ARTIFACT, GIT_DESERIALIZE_ARTIFACT, TIME_TAKEN_TO_DESERIALIZE_ARTIFACT.
app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/CommonGitFileUtilsCE.java Removed Stopwatch, replaced with Timer from Micrometer. Added fields for MeterRegistry and ObservationHelper. Updated methods for performance tracking and error handling.
app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/CommonGitFileUtils.java Updated constructor to include MeterRegistry and ObservationHelper as parameters.

Possibly related PRs

Suggested labels

skip-changelog, ok-to-test

Suggested reviewers

  • nidhi-nair
  • sondermanish

Poem

In the realm of code where constants gleam,
New strings arise, like a developer's dream.
With timers now ticking, observability in sight,
Git operations shine, oh what a delight!
Metrics and spans, tracking each flow,
In the world of Appsmith, watch our progress grow! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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: 6

🧹 Outside diff range and nitpick comments (2)
app/server/appsmith-git/src/main/java/com/appsmith/git/constants/CommonConstants.java (2)

39-42: LGTM! Consider grouping related constants.

The new constants follow good naming conventions and align with the migration to Micrometer. Consider grouping these Git metrics-related constants together at the top of the file with other Git-related constants for better organization.

public class CommonConstants {
+    // Git Metrics Constants
+    public static final String GIT_SAVE_ARTIFACT = "git.saveArtifact";
+    public static final String TIME_TAKEN_TO_SAVE_ARTIFACT = "Time taken to save Artifact";
+    public static final String GIT_DESERIALIZE_ARTIFACT = "git.deserializeArtifact";
+    public static final String TIME_TAKEN_TO_DESERIALIZE_ARTIFACT = "Time taken to deserialize Artifact from Git repo";
+
     // This field will be useful when we migrate fields within JSON files...
     public static Integer fileFormatVersion = 5;
     // ... rest of the constants

39-42: Add documentation for metrics usage.

Consider adding Javadoc comments to explain the purpose and usage context of these metrics constants, especially since they're part of a monitoring implementation change.

+    /**
+     * Constants for Micrometer metrics tracking Git operations.
+     * These are used to measure performance of artifact operations in the Git integration.
+     */
     public static final String GIT_SAVE_ARTIFACT = "git.saveArtifact";
     public static final String TIME_TAKEN_TO_SAVE_ARTIFACT = "Time taken to save Artifact";
     public static final String GIT_DESERIALIZE_ARTIFACT = "git.deserializeArtifact";
     public static final String TIME_TAKEN_TO_DESERIALIZE_ARTIFACT = "Time taken to deserialize Artifact from Git repo";
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f2c3125 and 7c3b9fb.

📒 Files selected for processing (2)
  • app/server/appsmith-git/src/main/java/com/appsmith/git/constants/CommonConstants.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/CommonGitFileUtilsCE.java (6 hunks)
🔇 Additional comments (2)
app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/CommonGitFileUtilsCE.java (2)

130-133: ⚠️ Potential issue

Capture and use the execution time from sample.stop(...)

Instead of calling sample.toString(), capture the execution time when stopping the timer sample.

Apply this diff to fix the issue:

 sample.stop(Timer.builder(CommonConstants.GIT_SAVE_ARTIFACT)
     .description(CommonConstants.TIME_TAKEN_TO_SAVE_ARTIFACT)
     .register(meterRegistry));
-observationHelper.endSpan(span, true);
+"executionTime", sample.stop(...));
+observationHelper.endSpan(span, true);

Likely invalid or redundant comment.


223-226: ⚠️ Potential issue

Capture and use execution time from timer sample

Ensure you capture the execution time when stopping the timer and use it accordingly.

Apply this diff:

 sample.stop(Timer.builder(CommonConstants.GIT_DESERIALIZE_ARTIFACT)
     .description(CommonConstants.TIME_TAKEN_TO_DESERIALIZE_ARTIFACT)
     .register(meterRegistry));
-observationHelper.endSpan(span, true);
+"executionTime", sample.stop(...));
+observationHelper.endSpan(span, true);

Likely invalid or redundant comment.

stopwatch.getFlow(),
"executionTime",
stopwatch.getExecutionTime());
"executionTime", sample.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Replace sample.toString() with actual execution time

Use the execution time captured from the timer sample instead of calling sample.toString().

Apply this diff:

-"executionTime", sample.toString());
+"executionTime", /* captured execution time variable */);

Committable suggestion skipped: line range outside the PR's diff.

@@ -141,6 +148,7 @@ public Mono<Path> saveArtifactToLocalRepoWithAnalytics(
});
} catch (IOException | GitAPIException e) {
log.error("Error occurred while saving files to local git repo: ", e);
observationHelper.endSpan(span, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure span is ended even if an exception occurs

The span should be ended in a finally block to guarantee it's closed regardless of exceptions.

Apply this diff:

 try {
     // Existing code
 } catch (IOException | GitAPIException e) {
     log.error("Error occurred while saving files to local git repo: ", e);
-    observationHelper.endSpan(span, false);
     throw Exceptions.propagate(e);
+} finally {
+    observationHelper.endSpan(span, false);
 }

Committable suggestion skipped: line range outside the PR's diff.

stopwatch.getFlow(),
"executionTime",
stopwatch.getExecutionTime());
"executionTime", sample.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use captured execution time instead of sample.toString()

Replace sample.toString() with the actual execution time captured from the timer.

Apply this diff:

-"executionTime", sample.toString());
+"executionTime", /* captured execution time variable */);

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +239 to +242
})
.doOnError(e -> {
observationHelper.endSpan(span, false);
log.error("Error deserializing artifact : {}", e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

End the span in a doFinally block

Ensure the span is ended even if an error occurs by using doFinally instead of doOnError.

Apply this diff:

-.doOnError(e -> {
-    observationHelper.endSpan(span, false);
-    log.error("Error deserializing artifact : {}", e.getMessage());
-});
+.doFinally(signalType -> {
+    boolean success = !signalType.equals(SignalType.ON_ERROR);
+    observationHelper.endSpan(span, success);
+});
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
})
.doOnError(e -> {
observationHelper.endSpan(span, false);
log.error("Error deserializing artifact : {}", e.getMessage());
})
.doFinally(signalType -> {
boolean success = !signalType.equals(SignalType.ON_ERROR);
observationHelper.endSpan(span, success);
});

Comment on lines +213 to +215
Timer.Sample sample = Timer.start(meterRegistry);
Span span = observationHelper.createSpan(AnalyticsEvents.GIT_DESERIALIZE_APP_RESOURCES_FROM_FILE.getEventName());
observationHelper.startSpan(span, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Activate span in the current context

Use try-with-resources to manage span scope correctly during deserialization.

Apply this diff:

 Timer.Sample sample = Timer.start(meterRegistry);
 Span span = observationHelper.createSpan(AnalyticsEvents.GIT_DESERIALIZE_APP_RESOURCES_FROM_FILE.getEventName());
-observationHelper.startSpan(span, true);
+try (Tracer.SpanInScope scope = tracer.withSpan(span)) {
     // Existing code inside the try block
+}

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +120 to +122
Timer.Sample sample = Timer.start(meterRegistry);
Span span = observationHelper.createSpan(AnalyticsEvents.GIT_SERIALIZE_APP_RESOURCES_TO_LOCAL_FILE.getEventName());
observationHelper.startSpan(span, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Properly manage span activation and deactivation

Ensure that the span is activated in the current context to correctly capture trace information. Use try-with-resources for automatic scope management.

Apply this diff to improve span management:

 Timer.Sample sample = Timer.start(meterRegistry);
 Span span = observationHelper.createSpan(AnalyticsEvents.GIT_SERIALIZE_APP_RESOURCES_TO_LOCAL_FILE.getEventName());
-observationHelper.startSpan(span, true);
+try (Tracer.SpanInScope scope = tracer.withSpan(span)) {
     // Existing code inside the try block
+}

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Contributor

@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

🧹 Outside diff range and nitpick comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/CommonGitFileUtils.java (1)

5-5: Well-structured integration of Micrometer metrics.

The addition of MeterRegistry and ObservationHelper aligns with enterprise observability patterns. This change effectively transitions from basic stopwatch logging to a more sophisticated metrics collection system.

Consider documenting the key metrics being collected in the class-level JavaDoc to help other developers understand the observability touchpoints.

Also applies to: 13-13, 31-32, 40-41

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7c3b9fb and 6d1e72d.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/CommonGitFileUtils.java (2 hunks)
🔇 Additional comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/CommonGitFileUtils.java (1)

24-32: LGTM! Clean constructor parameter organization.

The constructor parameters are well-organized, following the pattern of core dependencies first (git utils, file operations) followed by supporting services (analytics, session) and finally the new observability components.

@sondermanish sondermanish self-requested a review November 7, 2024 14:41
Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Nov 14, 2024
Copy link

This PR has been closed because of inactivity.

@github-actions github-actions bot closed this Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants