BugFix - 41225 - Invalid API Type In Feature Tracking#3937
Conversation
WalkthroughThe 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 Changes
Possibly related PRs
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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 parsingThe 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 parsingThe 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:
- Make the error message more specific:
- Reporter.ToUser(eUserMsgKey.InvalidJSON); + Reporter.ToUser(eUserMsgKey.InvalidJSON, $"Error parsing JSON file: {FileName}");
- 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 handlingThe restructuring of the
ParseDocumentmethod 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
ParseDocumentmethod: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
📒 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 correctlyThe addition of
using Amdocs.Ginger.Common.Telemetry;is necessary for telemetry tracking functionality.
286-296: Potential redundant telemetry trackingThe
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 callingParse()method.Please confirm that the feature tracking in
Parse()has been removed or is necessary. If it's redundant, removing it fromParse()would prevent duplicate telemetry entries.
332-334: Ensure consistency in feature trackingFeature 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 TemplatesThe addition of feature tracking in
ShowJsonTemplatesOperations()enhances telemetry for JSON Template parsing.
| 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(); | ||
| } |
There was a problem hiding this comment.
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.
| using IFeatureTracker featureTracker = Reporter.StartFeatureTracking(FeatureId.AAMLearning); | ||
| featureTracker.Metadata.Add("APIType", "WSDL"); | ||
|
|
||
| bool parseSuccess = true; |
There was a problem hiding this comment.
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.
| 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 | |
| } |
Thank you for your contribution.
Before submitting this PR, please make sure:
Summary by CodeRabbit
New Features
Bug Fixes
Chores