Skip to content

Improve endpoint metadata debugging #47163

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

Closed
wants to merge 16 commits into from
Closed

Improve endpoint metadata debugging #47163

wants to merge 16 commits into from

Conversation

SeanFarrow
Copy link
Contributor

{PR title}

This PR improves endpoint metadata debugging.

Description

This PR overrides ToString where necessary to improve endpoint metadata debugging.

Fixes #39792

@ghost ghost added area-runtime community-contribution Indicates that the PR has been added by a community member labels Mar 12, 2023
@ghost
Copy link

ghost commented Mar 12, 2023

Thanks for your PR, @SeanFarrow. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@SeanFarrow
Copy link
Contributor Author

This is not ready yet, as there is a build error due to the fact that the CodeFix that adds methods to the public API has added the ToString method of the EndpointMetadataCollection class to the wrong place.

I still need to finish implement ToString for both the Endpoint base class and RouteEndpoint class.

@adityamandaleeka
Copy link
Member

Thanks @SeanFarrow! I've marked this as a draft since it's not ready yet. Feel free to mark it ready when appropriate.

@JamesNK Assigning this one to you for review.

Comment on lines 36 to 42
var metadataTokensBuilder = new StringBuilder();
foreach(var DataToken in DataTokens)
{
metadataTokensBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0} ={1}", DataToken.Key, DataToken.Value);
metadataTokensBuilder.AppendLine();
}
return metadataTokensBuilder.ToString();
Copy link
Member

@JamesNK JamesNK Mar 14, 2023

Choose a reason for hiding this comment

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

I prefer comma delimited rather than separate lines. Separate lines can mess up tooling.
Also, include text to label what the data is.

Something like:

var dataTokensDisplay = string.Join(",", DataTokens.Select(t => $"{t.Key}={t.Value}"));

return $"DataTokens: {dataTokensDisplay}";

/// <inheritdoc/>
public override string ToString()
{
return EndpointName;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return EndpointName;
return $"EndpointName: {EndpointName}";

/// <inheritdoc/>
public override string ToString()
{
return SuppressLinkGeneration.ToString();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return SuppressLinkGeneration.ToString();
return $"SuppressLinkGeneration = {SuppressLinkGeneration}";

/// <inheritdoc/>
public override string ToString()
{
return SuppressMatching.ToString();
Copy link
Member

@JamesNK JamesNK Mar 14, 2023

Choose a reason for hiding this comment

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

Suggested change
return SuppressMatching.ToString();
return $"SuppressMatching = {SuppressMatching}";

@@ -156,6 +157,24 @@ public EndpointMetadataCollection(params object[] items)
/// <returns>An <see cref="IEnumerator"/> of all metadata items.</returns>
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

/// <inheritdoc/>
public override string ToString()
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should override this collection ToString. If someone wants to view the contents then they can do it with a debugger.

Instead, put a debugger display on the collection:

[DebuggerDisplay("Count = {Count}")]

If you want, you could also add a debugger proxy. List<T> does this for example: https://github.com/dotnet/runtime/blob/73818601becad0d1c6cfc58b5d947db010da2d6b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs#L17-L18. A debugger proxy changes what properties are visible in IDEs when debugging.

You'll need to copy and paste this internal type: https://github.com/dotnet/runtime/blob/73818601becad0d1c6cfc58b5d947db010da2d6b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ICollectionDebugView.cs
Put it under src/Http/Http.Abstractions/src/Internal and update the namespace to match other files in that directory.

@JamesNK
Copy link
Member

JamesNK commented Mar 14, 2023

Looking good so far. I think these changes will make debugging endpoint metadata much easier.

Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

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

I'm ok if we want to do this change, but I would avoid overriding ToString and instead use [DebuggerDisplay] and a private method on the types.

@halter73
Copy link
Member

I'm ok if we want to do this change, but I would avoid overriding ToString and instead use [DebuggerDisplay] and a private method on the types.

This was discussed in API review, and we went with ToString(). It was considered in the initial proposal under alternative designs.

DebuggerDisplayAttribute is not appropriate because there are situations where it is useful to get the debug value at runtime. e.g. logging.

@JamesNK
Copy link
Member

JamesNK commented May 3, 2023

@SeanFarrow What are your plans for this PR? If you don't have time right now to complete it then I can take it over.

@SeanFarrow
Copy link
Contributor Author

@JamesNK I'm going to pick this up again next week--I am in the process of changing jobs, so have 2 weeks off before the next one starts! Hopefully this is ample time to get this finished.

@SeanFarrow
Copy link
Contributor Author

@JamesNK Are you able to pick this up please.

I thought I'd have more time than I have, but this won't be the case--at least not before 8.0, given my mum is not well and I'm changing jobs!

Thanks,
Sean.

@JamesNK
Copy link
Member

JamesNK commented May 11, 2023

Sure, I can finish this off. Thanks for starting.

@JamesNK
Copy link
Member

JamesNK commented May 12, 2023

Replaced by #48207

@JamesNK JamesNK closed this May 12, 2023
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve endpoint metadata debugging by overriding ToString
6 participants