Skip to content

define RouteValuesAddress .ToString () #39753

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

Merged
merged 24 commits into from
Feb 7, 2022
Merged

Conversation

yecril71pl
Copy link
Contributor

define RouteValuesAddress .ToString ()

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Summary of the changes (Less than 80 chars)

Description

Override RouteValuesAddress .ToString () as Name(ExplicitValues) for tracing/debugging.

Fixes #39708

@yecril71pl yecril71pl requested a review from javiercn as a code owner January 25, 2022 18:23
@ghost ghost added area-runtime community-contribution Indicates that the PR has been added by a community member labels Jan 25, 2022
@yecril71pl yecril71pl marked this pull request as draft January 25, 2022 18:23
/// <summary>
/// Formats the address as string "Name(ExplicitValues)" for tracing/debugging.
/// </summary>
public override string ToString () => $"{RouteName}(" + string.Join(',', from kv in ExplicitValues select $"{kv.Key}=[{kv.Value}]") + ")";
Copy link
Member

Choose a reason for hiding this comment

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

Can you use the method call syntax instead of LINQ? we don't use linq anywhere in the repo

@javiercn
Copy link
Member

Looks good to me

/cc: @JamesNK in case he has thoughts

@JamesNK
Copy link
Member

JamesNK commented Jan 25, 2022

Was there a PR some time ago about adding ToString to many types of route metadata? I have some memory of one. Was that merged or not?

@javiercn
Copy link
Member

@JamesNK I don't remember TBH

@JamesNK
Copy link
Member

JamesNK commented Jan 25, 2022

#35231

@javiercn
Copy link
Member

@JamesNK I think they are different scenarios? In this case is about logging (and I checked it only happens in Debug or Trace) so I think is much more limited in scope.

For things like Endpoints I think I also agree that it should be DebuggerDisplay()

@yecril71pl yecril71pl marked this pull request as ready for review January 25, 2022 23:39
@yecril71pl yecril71pl requested a review from a team as a code owner January 25, 2022 23:39
@halter73
Copy link
Member

I think we should discuss this in API review.

@halter73 halter73 added the api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews label Jan 26, 2022
@ghost
Copy link

ghost commented Jan 26, 2022

Thank you for your API proposal. I'm removing the api-ready-for-review label. API Proposals should be submitted for review through Issues based on this template.

@ghost ghost removed the api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews label Jan 26, 2022
@@ -3,6 +3,7 @@

#nullable enable

using System.Collections.Immutable;
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
using System.Collections.Immutable;

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 tried, it will not build.

@davidfowl
Copy link
Member

Why not just fix the log?

@halter73
Copy link
Member

Why not just fix the log?

How much do we care about changing the type of objects in the LogValues state? I don't think it's likely to break anyone, but I feel the same way about changing the default ToString() behavior which might be helpful in more scenarios.

@JamesNK
Copy link
Member

JamesNK commented Jan 26, 2022

Consider all of #35231 along with this change in API review. Making endpoint metadata more debuggable is good.

@pranavkm pranavkm enabled auto-merge (squash) January 28, 2022 23:54
@@ -24,4 +25,7 @@ public class RouteValuesAddress
/// Gets or sets ambient route values from the current HTTP request.
/// </summary>
public RouteValueDictionary? AmbientValues { get; set; }

/// <inheritdoc />
public override string? ToString() => $"{RouteName}({string.Join(',', ExplicitValues.Select(kv => $"{kv.Key}=[{kv.Value}]"))})";
Copy link
Member

Choose a reason for hiding this comment

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

If we end up doing this, we should cache it.

Copy link
Member

Choose a reason for hiding this comment

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

Why do you think we should cache it?

auto-merge was automatically disabled January 29, 2022 09:31

Head branch was pushed to by a user without write access

@pranavkm pranavkm assigned halter73 and unassigned pranavkm Jan 29, 2022
Comment on lines 32 to 40
readonly Lazy<string> asString;

/// <summary>
/// The constructor prepares the internal state of the object.
/// </summary>
public RouteValuesAddress()
{
asString = new Lazy<string>(() => $"{RouteName}({string.Join(',', ExplicitValues.Select(kv => $"{kv.Key}=[{kv.Value}]"))})");
}
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't need a public constructor. Caching this on the constructor is wrong since values can change after the first ToString call has been issued.

We also don't need to use Lazy as this code is not used in a multi-threaded context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you want to track changes to the values so that we could invalidate the cache? This gets more and more Byzantine 😱

@halter73
Copy link
Member

Thanks for the PR @yecril71pl. We still need to decide whether we want to approve the API along with the other ToString() overrides suggested in #39792.

We plan to discuss this next Monday. We may end up deciding not to approve the API or decide not to do caching. I recommend leaving the PR as-is until then. That way the whole team can get on the same page in terms of feedback and you don't have to do so many iterations.

@yecril71pl
Copy link
Contributor Author

We may end up deciding not to approve the API or decide not to do caching.

The converter is linear, this is a debug API, caching is for mission-critical features.

Copy link
Member

@adityamandaleeka adityamandaleeka left a comment

Choose a reason for hiding this comment

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

This went through API review today. Merging.

@adityamandaleeka adityamandaleeka merged commit c2cf4e9 into dotnet:main Feb 7, 2022
@ghost ghost added this to the 7.0-preview2 milestone Feb 7, 2022
@yecril71pl yecril71pl deleted the patch-2 branch February 7, 2022 22:16
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 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.

Add RouteValuesAddress .ToString ()
8 participants