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

Tweak MetaData Report format for better readability #5929

Open
wants to merge 43 commits into
base: main
Choose a base branch
from

Conversation

IbrahimMNada
Copy link
Contributor

@IbrahimMNada IbrahimMNada commented Feb 19, 2025

This pull request only tackle the generated metadata format putting different proprieties on new Lines

Tests were failing due to the differences between escapes in Windows and Linux ,
at the GeneratorTests class in the namespace Microsoft.Gen.MetadataExtractor.Unit.Tests; .
I introduced new method called NormalizeEscapes, which will only escape "\r\n" to neglect the gap between
Windows & Linux, I hope this addition is acceptable.

Before :
image

After :
image

the test report has been changed to be aligned with the new formatting.
here are the unit tests :

image
Microsoft Reviewers: Open in CodeFlow

@IbrahimMNada
Copy link
Contributor Author

the checks failed because of something related to hybrid caching

@IbrahimMNada IbrahimMNada requested a review from a team as a code owner February 19, 2025 09:22
@dotnet-comment-bot
Copy link
Collaborator

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Gen.MetadataExtractor 57 70
Microsoft.Extensions.Caching.Hybrid 82 87

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=956346&view=codecoverage-tab

@dotnet-comment-bot
Copy link
Collaborator

‼️ Found issues ‼️

Project Coverage Type Expected Actual
Microsoft.Extensions.AI Line 89 88.54 🔻

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Gen.MetadataExtractor 57 70
Microsoft.Extensions.AI.Abstractions 82 83

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=957466&view=codecoverage-tab

@RussKie
Copy link
Member

RussKie commented Feb 20, 2025

Project Expected Actual
Microsoft.Gen.MetadataExtractor 57 70

Could you please also bump this threshold?

@RussKie RussKie added waiting-author-feedback 📭 The author of this issue needs to respond in order for us to continue investigating this issue. area-telemetry labels Feb 20, 2025
@IbrahimMNada
Copy link
Contributor Author

@RussKie Thank you for your valuable feedback, I will fix them ASAP ,

regarding the changing the order of parameters and naming ,I tried to make them consistent with compliance.
same goes for tmp and var.

now all of the are consistent , I could change the three of them if you'd like.

I'll work on the other notes in the meantime

@dotnet-policy-service dotnet-policy-service bot removed the waiting-author-feedback 📭 The author of this issue needs to respond in order for us to continue investigating this issue. label Feb 20, 2025
@IbrahimMNada IbrahimMNada requested a review from a team as a code owner February 20, 2025 09:09
@dotnet-comment-bot
Copy link
Collaborator

‼️ Found issues ‼️

Project Coverage Type Expected Actual
Microsoft.Extensions.AI Line 89 88.76 🔻

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Extensions.AI.Abstractions 82 83
Microsoft.Gen.MetadataExtractor 57 70

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=957592&view=codecoverage-tab

"File": "src-0.cs",
"Line": "18",
"Classifications": [
"Types": [
Copy link
Member

Choose a reason for hiding this comment

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

This indentation doesn't look correct

Copy link
Contributor Author

@IbrahimMNada IbrahimMNada Feb 25, 2025

Choose a reason for hiding this comment

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

its has been indented , it looks like this currently
level2 props is indented a bit to make it standout , if you have any thoughts ill reflect it

{
"Name":"test.dll",
"ComplianceReport": 
                {
                    "Types": [
                        {
                            "Name": "Test.Basic",
                            "Members": [
                                {
                                    "Name": "F0",
                                    "Type": "int",
                                    "File": "src-0.cs",
                                    "Line": "18",
                                    "Classifications": [
                                        {
                                            "Name": "C1"
                                        },
                                        {
                                            "Name": "C2",
                                            "Notes": "Note 1"
                                        }
                                    ]
                                },
                                {
                                    "Name": "F1",
                                    "Type": "int",
                                    "File": "src-0.cs",
                                    "Line": "21",
                                    "Classifications": [
                                        {
                                            "Name": "C1"
                                        },
                                        {
                                            "Name": "C2"
                                        }
                                    ]
                                },
                                {
                                    "Name": "P0",
                                    "Type": "int",
                                    "File": "src-0.cs",
                                    "Line": "11",
                                    "Classifications": [
                                        {
                                            "Name": "C1"
                                        },
                                        {
                                            "Name": "C3",
                                            "Notes": "Note 2"
                                        },
                                        {
                                            "Name": "C4"
                                        }
                                    ]
                                },
                                {
                                    "Name": "P1",
                                    "Type": "int",
                                    "File": "src-0.cs",
                                    "Line": "27",
                                    "Classifications": [
                                        {
                                            "Name": "C1"
                                        },
                                        {
                                            "Name": "C3"
                                        }
                                    ]
                                }
                            ],
                            "Logging Methods": [
                                {
                                    "Name": "LogHello",
                                    "Parameters": [
                                        {
                                            "Name": "user",
                                            "Type": "string",
                                            "File": "src-0.cs",
                                            "Line": "30",
                                            "Classifications": [
                                                {
                                                    "Name": "C2",
                                                    "Notes": "Note 3"
                                                }
                                            ]
                                        },
                                        {
                                            "Name": "port",
                                            "Type": "int",
                                            "File": "src-0.cs",
                                            "Line": "30"
                                        }
                                    ]
                                },
                                {
                                    "Name": "LogWorld",
                                    "Parameters": [
                                        {
                                            "Name": "user",
                                            "Type": "string",
                                            "File": "src-0.cs",
                                            "Line": "33",
                                            "Classifications": [
                                                {
                                                    "Name": "C2"
                                                }
                                            ]
                                        },
                                        {
                                            "Name": "port",
                                            "Type": "int",
                                            "File": "src-0.cs",
                                            "Line": "33"
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                },
"MetricReport": []
}

Copy link
Member

Choose a reason for hiding this comment

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

The first level properties aren't indented. The 3rd level onwards "{" are indented by 4 spaces, and the 2nd level is indented by 16 (?) spaces. This is what caught my eye.

I would kind of expect something like

{
    "Name":"test.dll",
    "ComplianceReport": 
        {
            "Types": [
                {
                    "Name": "Test.Basic",

(Although my personal preference would be 2 spaces :))

Copy link
Contributor Author

@IbrahimMNada IbrahimMNada Feb 25, 2025

Choose a reason for hiding this comment

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

I have fixed it , it's actually a lot better now , thank you

please for you verification - this is taken from Basic.json

{
    "Name":"test.dll",
    "ComplianceReport": 
        {
            "Types": [
                {
                    "Name": "Test.Basic",

@dariusclay
Copy link
Contributor

Looks better 👍

Copy link
Member

@RussKie RussKie left a comment

Choose a reason for hiding this comment

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

It's getting better but the resulting jsons need further work

{
"TestClasses":
[
Copy link
Member

Choose a reason for hiding this comment

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

Indentations in this file look doubled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry , I cant follow on this one , can u explain more ?
all other notes are fixed

Copy link
Member

Choose a reason for hiding this comment

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

image

Also, could you please help me understand why we're changing from 2 spaces to 4 spaces?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

at the EmitterBase its set to 4
this is the reason of indenting 4 instead of two
image

however , I made sure its consistence what ever its set in the EmitterBase

Copy link
Contributor

Choose a reason for hiding this comment

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

Emitter base also affects Logging generation, which is C# code, and thus 4 spaces is ideal. I wouldn't change this value.

Copy link
Contributor Author

@IbrahimMNada IbrahimMNada Mar 1, 2025

Choose a reason for hiding this comment

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

a suggestion would be to make it virtual, and override it whenever its needed.
However , this would require us to revisit all three reports to tune the unit testing files etc....

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion I made below was to create a EmitterJsonBase which inherits EmitterBase. Then it can adjust this if we want to have the 2 spaces per indent level. It also can include helpers related to JSON output (OutArray, OutObject, OutNameValue)

}
]

Copy link
Member

Choose a reason for hiding this comment

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

What's causing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will revisit the metric report emitter and see what is going on exactly inside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the indent char is 4 from the EmitterBase
it goes like this :

(root) 4 -> (MetricReport ) -> 8 ([) -> 12 -> ({metricClass.RootNamespace}) ->16

OutLn(" {");

OutLn($" \"MetricName\": \"{metricMethod.MetricName.Replace("\\", "\\\\").Replace("\"", "\\\"")}\",");
OutLn($" \"MetricName\": \"{metricMethod.MetricName.Replace("\\", "\\\\").Replace("\"", "\\\"")}\",");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
OutLn($" \"MetricName\": \"{metricMethod.MetricName.Replace("\\", "\\\\").Replace("\"", "\\\"")}\",");
OutIndent();
OutLn($"\"MetricName\": \"{metricMethod.MetricName.Replace("\\", "\\\\").Replace("\"", "\\\"")}\",");

ditto to remove spaces in OutLn following this indentation.

Comment on lines +67 to +68
Indent();
OutLn("{");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Indent();
OutLn("{");
OutOpenBrace();

ditto for any other Indent / Outln("{"} calls

}

Out(" }");
OutLn("}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
OutLn("}");
OutCloseBrace();

Comment on lines +132 to +133
OutLn("{");
Indent();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
OutLn("{");
Indent();
OutOpenBrace();

Comment on lines +69 to +99
Indent();
OutLn($"\"{metricClass.RootNamespace}\":");

if (metricClass.Methods.Length > 0)
{
OutLn(" [");
Indent();
OutLn("[");

for (int j = 0; j < metricClass.Methods.Length; j++)
{
var metricMethod = metricClass.Methods[j];
Indent();
ReportedMetricMethod metricMethod = metricClass.Methods[j];
bool isLastReportedMetricMethod = (j == metricClass.Methods.Length - 1);

GenMetricMethodDefinition(metricMethod, cancellationToken);
GenMetricMethodDefinition(metricMethod, isLastReportedMetricMethod, cancellationToken);

if (j < metricClass.Methods.Length - 1)
if (!isLastReportedMetricMethod)
{
Out(",");
OutLn();
}

OutLn();
Unindent();
}

OutLn(" ]");
Unindent();
OutLn("]");
Unindent();
}

Out(" }");
OutLn("}");
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency, consider how ComplianceReportEmitter uses OutArray. Although it's not in EmitterBase, so we could introduce a new EmiterJsonBase that inherits EmitterBase, and includes these additional JSON related helpers from ComplianceReportEmitter.

@@ -13,70 +13,94 @@ namespace Microsoft.Gen.MetricsReports;

internal sealed class MetricDefinitionEmitter : EmitterBase
{
private const int DimensionsIndentLevel = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels unnecessary if indentation levels are handled correctly.

@dariusclay dariusclay self-requested a review March 1, 2025 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants