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

Feature - Ginger Telemetry #3897

Merged
merged 54 commits into from
Sep 16, 2024
Merged

Feature - Ginger Telemetry #3897

merged 54 commits into from
Sep 16, 2024

Conversation

IamRanjeetSingh
Copy link
Contributor

@IamRanjeetSingh IamRanjeetSingh commented Sep 9, 2024

Thank you for your contribution.
Before submitting this PR, please make sure:

  • PR description and commit message should describe the changes done in this PR
  • Verify the PR is pointing to correct branch i.e. Release or Beta branch if the code fix is for specific release , else point it to master
  • Latest Code from master or specific release branch is merged to your branch
  • No unwanted\commented\junk code is included
  • No new warning upon build solution
  • Code Summary\Comments are added to my code which explains what my code is doing
  • Existing unit test cases are passed
  • New Unit tests are added for your development
  • Sanity Tests are successfully executed for New and Existing Functionality
  • Verify that changes are compatible with all relevant browsers and platforms.
  • After creating pull request there should not be any conflicts
  • Resolve all Codacy comments
  • Builds and checks are passed before PR is sent for review
  • Resolve code review comments
  • Update the Help Library document to match any feature changes

Summary by CodeRabbit

  • New Features

    • Enhanced telemetry tracking for export processes, providing detailed insights into executed business flows, activities, and actions.
    • Introduced a structured TelemetryMetadata class for improved management and serialization of telemetry data.
    • Improved telemetry integration for API parsing operations, logging metadata for better monitoring.
  • Bug Fixes

    • Enhanced error handling during API parsing to ensure accurate telemetry reporting.
  • Documentation

    • Updated documentation to reflect the new telemetry features and enhancements.
  • Chores

    • Upgraded dependencies to support the latest telemetry functionalities.

Copy link
Contributor

coderabbitai bot commented Sep 9, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request enhances telemetry tracking across several methods related to exporting BPMN data and API parsing. It introduces the IFeatureTracker interface to gather detailed metadata about executed business flows, activity groups, activities, and actions. Additionally, a new TelemetryMetadata class is added to manage telemetry data in a structured manner. These updates improve the observability of export functionalities and API parsing processes without altering the core logic of the methods.

Changes

Files Change Summary
Ginger/Ginger/Run/RunSetsExecutionsHistoryPage.xaml.cs, Ginger/Ginger/SolutionWindows/TreeViewItems/BusinessFlowTreeItem.cs, Ginger/Ginger/SolutionWindows/TreeViewItems/SharedActivitiesGroupTreeItem.cs Enhanced export methods with telemetry tracking to monitor counts of executed business flows, activities, and actions.
Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerParser.cs Improved telemetry tracking in the ParseDocument method for monitoring API parsing operations for both YAML and JSON.
Ginger/GingerCoreCommon/Telemetry/TelemetryMetadata.cs Introduced TelemetryMetadata class for structured telemetry data management, including key-value pairs and JSON serialization.

Possibly related PRs

Poem

🐰 In the realm of code, where rabbits play,
Telemetry blooms, brightening the way.
With counts and logs, we track every flow,
Exporting with joy, watch our data grow!
Hops of progress, in every line,
Celebrate changes, oh how they shine! 🎉


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 generate interesting stats about this repository and render them as a table.
    -- @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 or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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: 0

Outside diff range and nitpick comments (3)
Ginger/GingerCoreNET/Telemetry/Protos/V1/log.proto (1)

15-18: Consider removing the LogCount field.

The AddLogsRequest message definition is well-structured for a request to add multiple log records.

However, the LogCount field seems redundant as the count can be derived from the size of the Logs list. Consider removing this field to simplify the message definition.

Apply this diff to remove the LogCount field:

 message AddLogsRequest {
 	repeated LogRecord Logs = 1;
-	int32 LogCount = 2;
 }
Ginger/GingerCoreNET/Telemetry/Protos/V1/feature.proto (2)

5-13: Consider using a map or a separate message type for the Metadata field.

The Metadata field is currently defined as a string, which might not be the most efficient or type-safe way to store arbitrary metadata. Consider using a map or a separate message type for structured metadata.

For example, you could define a separate FeatureMetadata message and use it as the type for the Metadata field:

message FeatureMetadata {
  map<string, string> Fields = 1;
}

message FeatureRecord {
  // ...
  FeatureMetadata Metadata = 7;
}

This allows for more structured and type-safe metadata storage.


15-18: Consider removing the FeatureCount field.

The FeatureCount field seems redundant, as the number of feature records can be determined from the size of the Features list. Unless there is a specific reason to include this field, consider removing it to simplify the message definition.

 message AddFeaturesRequest {
   repeated FeatureRecord Features = 1;
-  int32 FeatureCount = 2;
 }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 34b7350 and 66d78d6.

Files selected for processing (4)
  • Ginger/GingerCoreNET/GingerCoreNET.csproj (2 hunks)
  • Ginger/GingerCoreNET/Telemetry/Protos/V1/feature.proto (1 hunks)
  • Ginger/GingerCoreNET/Telemetry/Protos/V1/log.proto (1 hunks)
  • Ginger/GingerCoreNET/Telemetry/TelemetryCollector.cs (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • Ginger/GingerCoreNET/GingerCoreNET.csproj
  • Ginger/GingerCoreNET/Telemetry/TelemetryCollector.cs
Additional comments not posted (5)
Ginger/GingerCoreNET/Telemetry/Protos/V1/log.proto (3)

5-13: LGTM!

The LogRecord message definition is well-structured and captures relevant information for a log record.


20-22: LGTM!

The AddLogsResponse message definition is well-structured for a response to the AddLogsRequest.


24-26: LGTM!

The LogCollector service definition is well-structured for collecting log records.

Ginger/GingerCoreNET/Telemetry/Protos/V1/feature.proto (2)

20-22: LGTM!

The AddFeaturesResponse message definition looks good. The FeatureCount field provides useful information about the number of feature records processed in the corresponding AddFeaturesRequest.


24-26: LGTM!

The FeatureCollector service definition and its Collect method look good. The method provides a simple and clear interface for collecting feature records, using the appropriate request and response message types.

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: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1a3ec78 and dbcacdf.

Files selected for processing (3)
  • Ginger/GingerCoreNET/Telemetry/BlockingBufferQueue.cs (1 hunks)
  • Ginger/GingerCoreNET/Telemetry/TelemetryQueue.cs (1 hunks)
  • Ginger/GingerCoreNET/WorkSpaceLib/WorkSpace.cs (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • Ginger/GingerCoreNET/WorkSpaceLib/WorkSpace.cs
Additional context used
GitHub Check: Codacy Static Code Analysis
Ginger/GingerCoreNET/Telemetry/BlockingBufferQueue.cs

[failure] 108-108: Ginger/GingerCoreNET/Telemetry/BlockingBufferQueue.cs#L108
Either implement 'IDisposable.Dispose', or totally rename this method to prevent confusion.


[failure] 110-110: Ginger/GingerCoreNET/Telemetry/BlockingBufferQueue.cs#L110
Add curly braces around the nested statement(s) in this 'if' block.

Ginger/GingerCoreNET/Telemetry/TelemetryQueue.cs

[warning] 21-21: Ginger/GingerCoreNET/Telemetry/TelemetryQueue.cs#L21
A static field in a generic type is not shared among instances of different close constructed types.


[failure] 55-55: Ginger/GingerCoreNET/Telemetry/TelemetryQueue.cs#L55
Dispose '_cancellationTokenSource' when it is no longer needed.

Additional comments not posted (10)
Ginger/GingerCoreNET/Telemetry/BlockingBufferQueue.cs (4)

27-36: LGTM!

The constructor correctly initializes all the required fields.


38-58: LGTM!

The Enqueue method correctly implements the enqueue operation with proper synchronization and error handling.


60-101: LGTM!

The Dequeue method correctly implements the dequeue operation with proper synchronization and error handling. The use of a cancellation token to break out of the loop is a good practice.


103-106: LGTM!

The Flush method correctly implements the flush operation by canceling the cancellation token source.

Ginger/GingerCoreNET/Telemetry/TelemetryQueue.cs (6)

64-88: Handle exceptions thrown by the background tasks.

The CreateConsumerTask and CreateRetryTask methods create background tasks that are not monitored for exceptions. If a task throws an exception, it will terminate silently. Consider using Task.Run to create the tasks and try-catch to handle exceptions.

Also applies to: 90-121


96-105: Check for cancellation before polling for records.

The CreateRetryTask method does not handle cancellation requests gracefully. It should check for cancellation before polling for records to avoid unnecessary work.

Apply this diff to fix the issue:

-while (!_cancellationTokenSource.IsCancellationRequested)
+while (true)
 {
+    if (_cancellationTokenSource.IsCancellationRequested)
+    {
+        break;
+    }
+
     string corrId = NewCorrelationId();

173-180: Log a warning message when the collector returns a non-successful result.

The ProcessAsync and ReprocessAsync methods do not handle the case where the collector returns a non-successful result. They should log a warning message to alert the user.

Apply this diff to fix the issue:

 if (result != null && result.Successful)
 {
     await TryDeleteRecordsFromDBAsync(records, corrId);
 }
 else
 {
+    _logger?.LogWarning("{corrId} collector returned non-successful result in {queueName}", corrId, QueueName);
     await TryIncrementUploadAttemptCountAsync(records, corrId);
 }

Also applies to: 199-206


76-83: Catch and log exceptions thrown by the ProcessAsync method.

The CreateConsumerTask method does not handle exceptions thrown by the ProcessAsync method. It should catch and log exceptions to avoid terminating the task.

Apply this diff to fix the issue:

 try
 {
     await ProcessAsync(records, corrId);
 }
+catch (Exception ex)
+{
+    _logger?.LogError("{corrId} error while processing records in {queueName}\n{ex}", corrId, QueueName, ex);
+}

198-207: Catch and log exceptions thrown by the TrySendToCollectorAsync and TryDeleteRecordsFromDBAsync methods.

The ReprocessAsync method does not handle exceptions thrown by the TrySendToCollectorAsync and TryDeleteRecordsFromDBAsync methods. It should catch and log exceptions to avoid terminating the method.

Apply this diff to fix the issue:

+try
+{
     ITelemetryCollector<TRecord>.AddResult? result = await TrySendToCollectorAsync(records, corrId);
+}
+catch (Exception ex)
+{
+    _logger?.LogError("{corrId} error while sending records to collector in {queueName}\n{ex}", corrId, QueueName, ex);
+}
+
+try
+{
     if (result != null && result.Successful)
     {
         await TryDeleteRecordsFromDBAsync(records, corrId);
     }
 }
+catch (Exception ex)
+{
+    _logger?.LogError("{corrId} error while deleting records from db in {queueName}\n{ex}", corrId, QueueName, ex);
+}

165-180: Catch and log exceptions thrown by the TryAddToDBAsync, TrySendToCollectorAsync, and TryDeleteRecordsFromDBAsync methods.

The ProcessAsync method does not handle exceptions thrown by the TryAddToDBAsync, TrySendToCollectorAsync, and TryDeleteRecordsFromDBAsync methods. It should catch and log exceptions to avoid terminating the method.

Apply this diff to fix the issue:

 try
 {
     await TryAddToDBAsync(records, corrId);
 }
+catch (Exception ex)
+{
+    _logger?.LogError("{corrId} error while adding records to db in {queueName}\n{ex}", corrId, QueueName, ex);
+}
+
+try
+{
     ITelemetryCollector<TRecord>.AddResult? result = await TrySendToCollectorAsync(records, corrId);
+}
+catch (Exception ex)
+{
+    _logger?.LogError("{corrId} error while sending records to collector in {queueName}\n{ex}", corrId, QueueName, ex);
+}
+
+try
+{
     if (result != null && result.Successful)
     {
         await TryDeleteRecordsFromDBAsync(records, corrId);
     }
 }
+catch (Exception ex)
+{
+    _logger?.LogError("{corrId} error while deleting records from db in {queueName}\n{ex}", corrId, QueueName, ex);
+}

Ginger/GingerCoreNET/Telemetry/BlockingBufferQueue.cs Outdated Show resolved Hide resolved
_collector = config.Collector;
_retryPollingSize = config.RetryPollingSize;
_retryPollingInterval = config.RetryPollingInterval;
_cancellationTokenSource = new();
Copy link
Contributor

Choose a reason for hiding this comment

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

Dispose _cancellationTokenSource when it is no longer needed.

The _cancellationTokenSource field is not disposed when it is no longer needed. This could lead to resource leaks. Consider disposing it in the Dispose method.

Apply this diff to fix the issue:

 public void Dispose()
 {
     if (_isDisposed)
     {
         return;
     }

     _logger?.LogDebug("disposing {queueName}", QueueName);

     _isDisposed = true;
     _cancellationTokenSource.Cancel();
+    _cancellationTokenSource.Dispose();
     _queue.Dispose();
    
     _consumerTask.Wait(QueueFlushWaitTime);
 }

Committable suggestion was skipped due to low confidence.

Tools
GitHub Check: Codacy Static Code Analysis

[failure] 55-55: Ginger/GingerCoreNET/Telemetry/TelemetryQueue.cs#L55
Dispose '_cancellationTokenSource' when it is no longer needed.

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dbcacdf and be7cdc5.

Files selected for processing (5)
  • Ginger/GingerCoreNET/Telemetry/Protos/V1/feature.proto (1 hunks)
  • Ginger/GingerCoreNET/Telemetry/Protos/V1/log.proto (1 hunks)
  • Ginger/GingerCoreNET/Telemetry/TelemetryBaseRecord.cs (1 hunks)
  • Ginger/GingerCoreNET/Telemetry/TelemetryCollector.cs (1 hunks)
  • Ginger/GingerCoreNET/Telemetry/TelemetryQueueManager.cs (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • Ginger/GingerCoreNET/Telemetry/Protos/V1/log.proto
  • Ginger/GingerCoreNET/Telemetry/TelemetryBaseRecord.cs
  • Ginger/GingerCoreNET/Telemetry/TelemetryCollector.cs
  • Ginger/GingerCoreNET/Telemetry/TelemetryQueueManager.cs
Additional comments not posted (3)
Ginger/GingerCoreNET/Telemetry/Protos/V1/feature.proto (3)

5-15: LGTM!

The FeatureRecord message is well-structured and captures relevant information for feature telemetry. The field names are descriptive, and the field types are appropriate.


22-24: LGTM!

The AddFeaturesResponse message is well-structured and provides confirmation of the number of feature records added.


26-28: LGTM!

The FeatureCollector service and its Collect method provide a clean and straightforward interface for collecting feature telemetry data.

@Maheshkale447 Maheshkale447 merged commit 976764c into master Sep 16, 2024
1 of 5 checks passed
@Maheshkale447 Maheshkale447 deleted the Features/Telemetry branch September 16, 2024 11:46
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.

2 participants