Skip to content

BugFix - 41225 - Invalid API Type In Feature Tracking#3937

Merged
Maheshkale447 merged 1 commit into
Releases/Official-Releasefrom
BugFix/41225-InvalidAPITypeInFeatureTracking
Sep 30, 2024
Merged

BugFix - 41225 - Invalid API Type In Feature Tracking#3937
Maheshkale447 merged 1 commit into
Releases/Official-Releasefrom
BugFix/41225-InvalidAPITypeInFeatureTracking

Conversation

@IamHarsimranjeet

@IamHarsimranjeet IamHarsimranjeet commented Sep 30, 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

  • New Features

    • Enhanced telemetry tracking for API parsing operations, providing better insights into the types of APIs being processed.
  • Bug Fixes

    • Improved error handling and control flow in the Swagger parser, enhancing readability and maintainability.
  • Chores

    • Removed feature tracking code from various parsers (WSDL, JSON, XML, Swagger), streamlining methods without affecting core functionality.

@coderabbitai

coderabbitai Bot commented Sep 30, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The changes in this pull request focus on enhancing telemetry tracking across various API parsing operations in the API model wizard. Specifically, telemetry tracking has been added to the ScanAPIModelWizardPage.xaml.cs file for Swagger, XML Template, and JSON Template parsing methods. In contrast, feature tracking has been removed from the WSDLParser, JSONTemplateParser, SwaggerParser, and XMLTemplateParser, simplifying their respective parsing methods while maintaining core functionalities.

Changes

File Path Change Summary
Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelWizard/ScanAPIModelWizardPage.xaml.cs Added telemetry tracking for parsing operations in Parse, ShowSwaggerOperations, ShowXMLTemplatesOperations, ShowJsonTemplatesOperations, and ShowWSDLOperations.
Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelWizard/WSDLParser.cs Removed feature tracking code from ParseDocument method, simplifying the parsing process while retaining functionality.
Ginger/GingerAutoPilot/APIModelLib/JSONTemplateParser.cs Removed feature tracking code from ParseDocument method, maintaining the original parsing logic.
Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerParser.cs Restructured error handling in ParseDocument method, removing nested try-catch blocks and feature tracking.
Ginger/GingerAutoPilot/APIModelLib/XMLTemplateParser.cs Removed feature tracking code from ParseDocument method, ensuring core parsing functionality remains unchanged.

Possibly related PRs

Suggested reviewers

  • Maheshkale447

Poem

🐇 In the land of code where rabbits play,
Telemetry hops in to brighten the day.
Parsing APIs, swift and neat,
With every change, our work's a treat!
No more tracking slowing the race,
Just clean code in our happy space! 🌟


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

🧹 Outside diff range and nitpick comments (3)
Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerParser.cs (3)

36-47: Improved error handling for YAML parsing

The restructured code for YAML parsing is cleaner and easier to follow. The error handling is comprehensive, addressing both logging and user notification, which aligns well with the PR objectives.

Consider making the error message more specific:

- Reporter.ToUser(eUserMsgKey.InvalidYAML);
+ Reporter.ToUser(eUserMsgKey.InvalidYAML, $"Error parsing YAML file: {FileName}");

This change would provide more context to the user about which file caused the error.


51-60: Improved error handling for JSON parsing

The restructured code for JSON parsing is consistent with the YAML parsing section, improving overall code clarity and maintainability. The error handling is comprehensive, addressing both logging and user notification.

Consider the following improvements:

  1. Make the error message more specific:
- Reporter.ToUser(eUserMsgKey.InvalidJSON);
+ Reporter.ToUser(eUserMsgKey.InvalidJSON, $"Error parsing JSON file: {FileName}");
  1. Avoid reading the file content twice:
- string fileContent = FileContentProvider(FileName);
- JToken.Parse(fileContent);  // doing the Jtoken to validate the json file
- Swaggerdoc = SwaggerDocument.FromJsonAsync(FileContentProvider(FileName)).Result;
+ string fileContent = FileContentProvider(FileName);
+ JToken.Parse(fileContent);  // doing the Jtoken to validate the json file
+ Swaggerdoc = SwaggerDocument.FromJsonAsync(fileContent).Result;

These changes would provide more context to the user about which file caused the error and improve performance by avoiding redundant file reads.


36-60: Overall improvement in code structure and error handling

The restructuring of the ParseDocument method has significantly improved its readability and maintainability. The separate error handling for YAML and JSON files is clear and consistent. These changes align well with the PR objectives of improving code quality and clarity.

For future improvement, consider extracting the common logic for YAML and JSON parsing into a separate method. This could further reduce code duplication and improve maintainability. Here's a potential refactoring:

private void ParseSwaggerDocument(string fileContent, bool isYaml)
{
    try
    {
        string jsonContent = isYaml ? ConvertYamlToJson(fileContent) : fileContent;
        JToken.Parse(jsonContent); // Validate JSON
        Swaggerdoc = SwaggerDocument.FromJsonAsync(jsonContent).Result;
    }
    catch (Exception ex)
    {
        string fileType = isYaml ? "YAML" : "JSON";
        Reporter.ToLog(eLogLevel.ERROR, $"Error occurred while trying to read provided {fileType} document ", ex);
        Reporter.ToUser(isYaml ? eUserMsgKey.InvalidYAML : eUserMsgKey.InvalidJSON, $"Error parsing {fileType} file: {FileName}");
    }
}

Then, in the ParseDocument method:

string fileContent = FileContentProvider(FileName);
ParseSwaggerDocument(fileContent, IsValidYaml(FileName));

This refactoring would further improve code maintainability and reduce duplication.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0062169 and 4bb7b01.

📒 Files selected for processing (5)
  • Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelWizard/ScanAPIModelWizardPage.xaml.cs (7 hunks)
  • Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelWizard/WSDLParser.cs (0 hunks)
  • Ginger/GingerAutoPilot/APIModelLib/JSONTemplateParser.cs (0 hunks)
  • Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerParser.cs (1 hunks)
  • Ginger/GingerAutoPilot/APIModelLib/XMLTemplateParser.cs (0 hunks)
💤 Files with no reviewable changes (3)
  • Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelWizard/WSDLParser.cs
  • Ginger/GingerAutoPilot/APIModelLib/JSONTemplateParser.cs
  • Ginger/GingerAutoPilot/APIModelLib/XMLTemplateParser.cs
🔇 Additional comments (4)
Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelWizard/ScanAPIModelWizardPage.xaml.cs (4)

26-26: Import statement added correctly

The addition of using Amdocs.Ginger.Common.Telemetry; is necessary for telemetry tracking functionality.


286-296: Potential redundant telemetry tracking

The ShowSwaggerOperations() method starts a feature tracking session, which is appropriate. However, ensure that feature tracking is not duplicated due to the feature tracking also being initiated in the calling Parse() method.

Please confirm that the feature tracking in Parse() has been removed or is necessary. If it's redundant, removing it from Parse() would prevent duplicate telemetry entries.


332-334: Ensure consistency in feature tracking

Feature tracking is initiated in ShowXMLTemplatesOperations(). Verify that similar telemetry tracking is consistently implemented across all parsing methods for accurate data collection.


390-392: Feature tracking added for JSON Templates

The addition of feature tracking in ShowJsonTemplatesOperations() enhances telemetry for JSON Template parsing.

Comment on lines +264 to +276
using (IFeatureTracker featureTracker = Reporter.StartFeatureTracking(FeatureId.AAMLearning))
{
featureTracker.Metadata.Add("APIType", "Swagger");
if (SwaggerParser.IsValidYaml((AddAPIModelWizard.URL)))
{
featureTracker.Metadata.Add("FileType", "YAML");
}
else
{
featureTracker.Metadata.Add("FileType", "JSON");
}
parseSuccess = await ShowSwaggerOperations();
}

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.

⚠️ Potential issue

Remove duplicate feature tracking in Parse() method

The Parse() method initiates a feature tracking session for Swagger API type, but ShowSwaggerOperations() also starts its own feature tracking for the same feature. Starting feature tracking twice for the same operation may lead to redundant telemetry data.

Consider removing the feature tracking block from the Parse() method to prevent duplication, as each parsing method already handles its own feature tracking.

Comment on lines +446 to +449
using IFeatureTracker featureTracker = Reporter.StartFeatureTracking(FeatureId.AAMLearning);
featureTracker.Metadata.Add("APIType", "WSDL");

bool parseSuccess = true;

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.

⚠️ Potential issue

Incomplete feature tracking scope in ShowWSDLOperations()

The using declaration for featureTracker is followed by a variable declaration bool parseSuccess = true; without encompassing the main parsing code. This may result in featureTracker not capturing all relevant telemetry data.

Ensure that the feature tracking encompasses all relevant operations by adjusting the scope:

-using IFeatureTracker featureTracker = Reporter.StartFeatureTracking(FeatureId.AAMLearning);
-featureTracker.Metadata.Add("APIType", "WSDL");
-
 bool parseSuccess = true;
 
+using (IFeatureTracker featureTracker = Reporter.StartFeatureTracking(FeatureId.AAMLearning))
+{
+    featureTracker.Metadata.Add("APIType", "WSDL");
+
    // Existing parsing code should be inside this block
+}
📝 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
using IFeatureTracker featureTracker = Reporter.StartFeatureTracking(FeatureId.AAMLearning);
featureTracker.Metadata.Add("APIType", "WSDL");
bool parseSuccess = true;
bool parseSuccess = true;
using (IFeatureTracker featureTracker = Reporter.StartFeatureTracking(FeatureId.AAMLearning))
{
featureTracker.Metadata.Add("APIType", "WSDL");
// Existing parsing code should be inside this block
}

@Maheshkale447
Maheshkale447 merged commit 1e427d8 into Releases/Official-Release Sep 30, 2024
@Maheshkale447
Maheshkale447 deleted the BugFix/41225-InvalidAPITypeInFeatureTracking branch September 30, 2024 15:22
@coderabbitai coderabbitai Bot mentioned this pull request Mar 18, 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