Skip to content

BugFix - 41125, 41278, 41279, 42336, 42337 - Telemetry BugFix#3952

Merged
Maheshkale447 merged 2 commits into
Releases/Official-Releasefrom
BugFix/TelemetryBugFix
Oct 3, 2024
Merged

BugFix - 41125, 41278, 41279, 42336, 42337 - Telemetry BugFix#3952
Maheshkale447 merged 2 commits into
Releases/Official-Releasefrom
BugFix/TelemetryBugFix

Conversation

@IamHarsimranjeet

@IamHarsimranjeet IamHarsimranjeet commented Oct 3, 2024

Copy link
Copy Markdown
Contributor

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

Release Notes

  • New Features

    • Enhanced telemetry reporting for GIT operations, including Pull, Commit, and Push.
  • Improvements

    • Improved logic for committing changes by ensuring valid paths are checked.
    • Refined conflict detection to accurately identify conflicted files.
    • Enhanced error handling and user messaging throughout the GIT operations.

These updates enhance user experience by improving tracking, error management, and overall functionality.

@coderabbitai

coderabbitai Bot commented Oct 3, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The pull request introduces enhancements to the GITSourceControl class within the GingerCore.SourceControl namespace. Key modifications include the addition of a telemetry reporting mechanism for operations such as Pull, Commit, and Push, along with a refined check for local changes in the CommitAndCheckinChanges method. The GetConflictPaths method has been improved to accurately identify conflicted files. Additionally, minor adjustments to error handling and logging have been made throughout the class.

Changes

File Path Change Summary
Ginger/GingerCoreNET/SourceControl/GITSourceControl.cs Added telemetry reporting for Pull, Commit, and Push methods; refined local changes check in CommitAndCheckinChanges; improved GetConflictPaths method; added ReportFeatureUsage method; adjusted exception handling.

Possibly related PRs

Suggested reviewers

  • Maheshkale447

Poem

🐰 In the code where bunnies play,
Telemetry hops in a bright array.
With each commit and pull we cheer,
Tracking our changes, spreading good cheer.
So here’s to the updates, both clever and bright,
Hopping through code, everything feels right! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 64fd3d5 and 44a2c42.

📒 Files selected for processing (1)
  • Ginger/GingerCoreNET/SourceControl/GITSourceControl.cs (6 hunks)
🔇 Additional comments (5)
Ginger/GingerCoreNET/SourceControl/GITSourceControl.cs (5)

22-22: LGTM: Telemetry namespace added

The addition of the telemetry namespace is appropriate for the new telemetry reporting functionality.


Line range hint 1333-1357: LGTM: Telemetry reporting added for Pull operation

The addition of telemetry reporting for the Pull operation is implemented correctly at the beginning of the method. This change aligns with the suggestions from previous reviews and improves the tracking of Git operations.


Line range hint 1358-1370: LGTM: Telemetry reporting added for Commit operation

The addition of telemetry reporting for the Commit operation is implemented correctly at the beginning of the method. This change aligns with the suggestions from previous reviews and improves the tracking of Git operations.


Line range hint 1451-1647: LGTM: Telemetry reporting added for Push operation and refactored

The changes in this segment are well-implemented:

  1. Telemetry reporting has been added for the Push operation.
  2. A new ReportFeatureUsage method has been created to encapsulate the telemetry reporting logic, following the DRY principle.

These changes address the suggestions from previous reviews and improve the overall code quality and maintainability.


22-22: Overall assessment: Telemetry reporting successfully implemented

The changes in this file consistently implement telemetry reporting for Git operations (Pull, Commit, and Push). The addition of the ReportFeatureUsage method improves code maintainability by centralizing the telemetry logic. These modifications enhance the ability to track and analyze the usage of Git operations within the application without introducing any new issues or concerns.

Great job on addressing the previous review comments and improving the overall code quality!

Also applies to: 1333-1357, 1358-1370, 1451-1647


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 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (9)
Ginger/Ginger/SolutionWindows/TreeViewItems/BusinessFlowsFolderTreeItem.cs (2)

221-225: LGTM! Consider adding error handling for telemetry reporting.

The addition of telemetry for ALM import is a good practice. It will help track feature usage and provide valuable insights.

Consider wrapping the telemetry reporting in a try-catch block to ensure that any potential exceptions in telemetry don't interfere with the main functionality:

+try {
   Reporter.AddFeatureUsage(FeatureId.ALM, new TelemetryMetadata()
   {
       { "Type", ALMIntegration.Instance.GetALMType().ToString() },
       { "Operation", "ImportBusinessFlow" },
   });
+} catch (Exception ex) {
+   // Log the exception without throwing
+   Reporter.ToLog(eLogLevel.ERROR, "Failed to report ALM import telemetry", ex);
+}

231-235: LGTM! Consider adding error handling for telemetry reporting.

The addition of telemetry for ALM import by ID is consistent with the previous method and a good practice.

For consistency with the previous method, consider wrapping the telemetry reporting in a try-catch block:

+try {
   Reporter.AddFeatureUsage(FeatureId.ALM, new TelemetryMetadata()
   {
       { "Type", ALMIntegration.Instance.GetALMType().ToString() },
       { "Operation", "ImportBusinessFlowById" },
   });
+} catch (Exception ex) {
+   // Log the exception without throwing
+   Reporter.ToLog(eLogLevel.ERROR, "Failed to report ALM import by ID telemetry", ex);
+}
Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelWizard/ScanAPIModelWizardPage.xaml.cs (1)

264-264: Consider the impact of removing feature tracking from the Parse method.

While the change simplifies the code, it's worth noting that we've removed the ability to track the file type (YAML or JSON) at the Parse method level. This information is still captured within the ShowSwaggerOperations method, but it might affect any analytics or logging that relied on this data being set at the Parse level.

If tracking the file type at the Parse level is important for your analytics or logging, consider adding this metadata to the feature tracker within the ShowSwaggerOperations method:

async Task<bool> ShowSwaggerOperations()
{
    using IFeatureTracker featureTracker = Reporter.StartFeatureTracking(FeatureId.AAMLearning);
    featureTracker.Metadata.Add("APIType", "Swagger");
+   string fileType = SwaggerParser.IsValidYaml((AddAPIModelWizard.URL)) ? "YAML" : "JSON";
+   featureTracker.Metadata.Add("FileType", fileType);
    // ... rest of the method
}
Ginger/GingerCoreNET/SourceControl/GITSourceControl.cs (3)

Line range hint 1215-1215: Fix syntax error: Incorrect list initialization

The list missingPaths is incorrectly initialized using []. In C#, you should initialize lists using new List<string>().

Apply this diff to fix the syntax error:

-List<string> missingPaths = [];
+List<string> missingPaths = new List<string>();

Line range hint 1452-1452: Fix syntax error: Incorrect list initialization

The list filesPathsToUndo is incorrectly initialized using []. In C#, you should initialize lists using new List<string>().

Apply this diff to fix the syntax error:

-List<string> filesPathsToUndo = [];
+List<string> filesPathsToUndo = new List<string>();

Line range hint 1333-1354: Refactor synchronous code to avoid unnecessary Task.Run().Wait()

The Pull() method uses Task.Run() followed by .Wait(), which can lead to potential deadlocks and adds unnecessary complexity. Since the code inside Task.Run() is synchronous, consider refactoring the method to be purely synchronous.

Apply this diff to refactor the method:

 private MergeResult Pull()
 {
     MergeResult mergeResult = null;

-    Reporter.AddFeatureUsage(FeatureId.SourceControl, new TelemetryMetadata()
-    {
-        { "VersionControlType", "GIT" },
-        { "Operation", "Pull" }
-    });
-    //Pull = Fetch + Merge
-    Task.Run(() =>
-    {
         using (var repo = new LibGit2Sharp.Repository(RepositoryRootFolder))
         {
+            Reporter.AddFeatureUsage(FeatureId.SourceControl, new TelemetryMetadata()
+            {
+                { "VersionControlType", "GIT" },
+                { "Operation", "Pull" }
+            });
             PullOptions PullOptions = new PullOptions();
             PullOptions.FetchOptions = new FetchOptions();
             PullOptions.FetchOptions.CredentialsProvider = GetSourceCredentialsHandler();
             if (!IsRepositoryPublic())
             {
                 mergeResult = Commands.Pull(repo, new Signature(SourceControlUser, SourceControlUser, new DateTimeOffset(DateTime.Now)), PullOptions);
             }
             else
             {
                 mergeResult = Commands.Pull(repo, new Signature("dummy", "dummy", new DateTimeOffset(DateTime.Now)), PullOptions);
             }
         }
-    }).Wait();
     return mergeResult;
 }
Ginger/GingerCoreNET/Run/GingerExecutionEngine.cs (3)

Line range hint 2218-2218: Handle the return value of ResetRunStatus method

The ResetRunStatus method now returns a bool, but the calling method ResetStatus does not handle this return value. To maintain consistency and ensure correct behavior, consider handling the returned value in ResetStatus, or change ResetRunStatus to return void if the return value is not necessary.


Line range hint 2251-2251: Add null check for activity parameter

The SetMappedValuesToActivityVariables method does not check if the activity parameter is null before using it. This could result in a NullReferenceException if activity is null. Consider adding a null check at the beginning of the method.

Apply this diff to add the null check:

+ if (activity == null)
+ {
+     throw new ArgumentNullException(nameof(activity));
+ }

Line range hint 2290-2290: Correct the grammatical error in the log message

In the error message on line 2290, "for mapping it's output value" should be "for mapping its output value" (without an apostrophe).

Apply this diff to correct the typo:

- Reporter.ToLog(eLogLevel.ERROR, $"No {GingerDicser.GetTermResValue(eTermResKey.Variable)}('{mappedSourceVarGuid}') found by id in {GingerDicser.GetTermResValue(eTermResKey.Activity)}('{mappedSourceActivity.Guid}-{mappedSourceActivity.ActivityName}') for mapping it's output value.");
+ Reporter.ToLog(eLogLevel.ERROR, $"No {GingerDicser.GetTermResValue(eTermResKey.Variable)}('{mappedSourceVarGuid}') found by id in {GingerDicser.GetTermResKey(eTermResKey.Activity)}('{mappedSourceActivity.Guid}-{mappedSourceActivity.ActivityName}') for mapping its output value.");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 10b2beb and 64fd3d5.

📒 Files selected for processing (7)
  • Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelWizard/ScanAPIModelWizardPage.xaml.cs (1 hunks)
  • Ginger/Ginger/SolutionWindows/TreeViewItems/BusinessFlowsFolderTreeItem.cs (1 hunks)
  • Ginger/GingerCoreCommon/Repository/BusinessFlowLib/BusinessFlow.cs (2 hunks)
  • Ginger/GingerCoreNET/Run/GingerExecutionEngine.cs (4 hunks)
  • Ginger/GingerCoreNET/Run/RunSetActions/RunSetActionBaseOperations.cs (1 hunks)
  • Ginger/GingerCoreNET/SourceControl/GITSourceControl.cs (5 hunks)
  • Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs (0 hunks)
💤 Files with no reviewable changes (1)
  • Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs
🧰 Additional context used
📓 Learnings (1)
Ginger/GingerCoreCommon/Repository/BusinessFlowLib/BusinessFlow.cs (2)
Learnt from: Maheshkale447
PR: Ginger-Automation/Ginger#3918
File: Ginger/GingerCoreCommon/Repository/BusinessFlowLib/BusinessFlow.cs:2023-2038
Timestamp: 2024-09-22T17:05:18.912Z
Learning: Caching is not necessary for the `VariablesSummary` property as it is accessed infrequently.
Learnt from: Maheshkale447
PR: Ginger-Automation/Ginger#3918
File: Ginger/GingerCoreCommon/Repository/BusinessFlowLib/Activity.cs:1271-1287
Timestamp: 2024-09-22T17:01:36.055Z
Learning: Prefers the original implementation of the `VariablesSummary` property using explicit list creation over LINQ for better readability.
🔇 Additional comments (9)
Ginger/GingerCoreNET/Run/RunSetActions/RunSetActionBaseOperations.cs (1)

60-60: Verify the impact of changing the metadata key case.

The metadata key for the feature tracker has been changed from "type" to "Type". While this change might be intentional to fix a bug or adhere to a naming convention, it's important to ensure that this modification doesn't introduce any issues elsewhere in the system.

Please confirm the following:

  1. This change is intentional and necessary.
  2. All consumers of this metadata are updated to expect "Type" instead of "type".
  3. There are no case-sensitive lookups for this metadata key that might be affected.

Additionally, consider adding a code comment explaining the reason for this change to prevent future confusion.

✅ Verification successful

Verified that the metadata key change to "Type" is consistent across the codebase.

All instances of metadata additions use "Type" as the key, ensuring consistency and preventing potential issues related to key casing.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usages of 'type' or 'Type' as metadata keys in feature tracking

# Test: Search for lowercase 'type' usage in feature tracking
echo "Searching for lowercase 'type' usage:"
rg --type csharp -i 'featureTracker.*Metadata.*"type"'

# Test: Search for capitalized 'Type' usage in feature tracking
echo "Searching for capitalized 'Type' usage:"
rg --type csharp -i 'featureTracker.*Metadata.*"Type"'

Length of output: 1765

Ginger/Ginger/SolutionWindows/TreeViewItems/BusinessFlowsFolderTreeItem.cs (1)

Line range hint 252-309: No changes detected. Consider adding telemetry and improving error handling.

While no changes are visible in this method, it's worth noting that the AI summary mentioned the removal of telemetry reporting. If this is accurate, consider re-adding telemetry for consistency with other import methods.

  1. Consider adding telemetry reporting similar to the ALM import methods:
try {
    Reporter.AddFeatureUsage(FeatureId.ExternalImport, new TelemetryMetadata()
    {
        { "Type", "BusinessFlow" },
        { "Operation", "ImportExternalBusinessFlow" },
    });
} catch (Exception ex) {
    Reporter.ToLog(eLogLevel.ERROR, "Failed to report external import telemetry", ex);
}
  1. Improve error handling by using a more specific exception type instead of the general Exception:
try
{
    // ... existing code ...
}
catch (IOException ex)
{
    Reporter.ToUser(eUserMsgKey.StaticErrorMessage, $"Failed to copy the selected {GingerDicser.GetTermResValue(eTermResKey.BusinessFlow)} file. Error: {ex.Message}");
}
catch (Exception ex)
{
    Reporter.ToUser(eUserMsgKey.StaticErrorMessage, $"Failed to load the selected {GingerDicser.GetTermResValue(eTermResKey.BusinessFlow)} file. Error: {ex.Message}");
}

To ensure that telemetry is not being reported elsewhere for this method, run the following script:

Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelWizard/ScanAPIModelWizardPage.xaml.cs (2)

264-264: Summary of changes and their impact.

The main change in this file is the simplification of the Swagger parsing logic in the Parse method. This modification streamlines the code by removing a redundant feature tracking block. The feature tracking functionality is still maintained within the ShowSwaggerOperations method, ensuring that important metadata is still captured.

Overall, this change reduces code complexity without compromising the core functionality. However, it's important to verify that any systems or processes that relied on the file type (YAML or JSON) being set at the Parse level are updated accordingly.

These changes appear to be a positive step towards code simplification. Just ensure that:

  1. The removal of the feature tracking block from the Parse method doesn't affect any existing analytics or logging processes.
  2. The ShowSwaggerOperations method correctly handles all necessary feature tracking, including file type information if needed.

264-264: Simplified Swagger parsing logic.

The code has been simplified by directly calling ShowSwaggerOperations() without wrapping it in a feature tracking block. This change streamlines the parsing process for Swagger APIs.

To ensure that this change doesn't affect the feature tracking functionality, let's verify if the feature tracking is still being performed within the ShowSwaggerOperations method:

Ginger/GingerCoreCommon/Repository/BusinessFlowLib/BusinessFlow.cs (3)

42-42: Telemetry functionality added

The addition of the Amdocs.Ginger.Common.Telemetry namespace indicates that telemetry capabilities are being introduced to the BusinessFlow class. This is a positive change that will likely improve monitoring and analysis of the application.


670-679: Telemetry added for global parameter usage

The GetHierarchyVariableByName method has been enhanced with telemetry reporting. This addition will provide valuable insights into the usage of global parameters (variables from SolutionVariables). The implementation is correct and doesn't affect the existing logic of the method.

Key points:

  1. Telemetry is only reported when a variable is found in SolutionVariables.
  2. The feature is identified as "GlobalParameter" with the operation "Use".

This change will help in understanding the usage patterns of global parameters across the application.


Line range hint 2023-2038: Improved initialization of VariablesSummary property

The VariablesSummary property has been refactored to use a more idiomatic C# approach for list initialization. This change improves code readability and maintainability without altering the existing functionality.

Key improvements:

  1. The property now uses List<General.VariableMinimalRecord> variableDetails = []; instead of assigning an empty array.
  2. This change allows for easier modification of the list if needed in the future.
  3. The modification aligns with the previous feedback that caching is not necessary for this infrequently accessed property.

The overall logic for populating the list remains unchanged, ensuring that existing functionality is preserved.

Ginger/GingerCoreNET/SourceControl/GITSourceControl.cs (2)

22-22: LGTM

The addition of the telemetry namespace is appropriate given the new telemetry reporting.


102-102: LGTM

The additional condition ensures that a commit is only attempted when there are local changes pending to commit.

Comment thread Ginger/GingerCoreNET/SourceControl/GITSourceControl.cs Outdated
Comment thread Ginger/GingerCoreNET/SourceControl/GITSourceControl.cs Outdated
Comment thread Ginger/GingerCoreNET/SourceControl/GITSourceControl.cs Outdated
@Maheshkale447
Maheshkale447 merged commit 4d24ccb into Releases/Official-Release Oct 3, 2024
@Maheshkale447
Maheshkale447 deleted the BugFix/TelemetryBugFix branch October 3, 2024 10:20
@coderabbitai coderabbitai Bot mentioned this pull request Oct 28, 2024
15 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Feb 24, 2025
15 tasks
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