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

Expose immutable Metadata from RouteConfig #476

Closed
wants to merge 2 commits into from

Conversation

ittennull
Copy link

Since extensibility of the yarp is work in progress yet I use Metadata to add some additional information that I can later use to run my own middelware. Without Metadata being accessible through Endpoint->Metadata->RouteConfig->Metadata I need to build my own store for metadata which is unfortunate because I already have everything.

@@ -49,6 +51,8 @@ internal sealed class RouteConfig

public Transforms Transforms { get; }

public IReadOnlyDictionary<string, string> Metadata { get; }
Copy link
Member

Choose a reason for hiding this comment

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

How does this help you when RouteConfig itself is still internal? You'd probably need to flow the data somewhere accessible like IReverseProxyFeature:

context.Features.Set<IReverseProxyFeature>(new ReverseProxyFeature

Copy link
Author

Choose a reason for hiding this comment

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

Ah, right. I saw RouteConfig pop up in the debugger and when I opened it it didn't expose metadata so I decided to add it but I didn't notice that the whole class was internal. Ok, thanks for clarifying it, I'll try to find another way. Although in general it would be very helpful to have runtime access to the original configuration that was used to create a route

@Tratcher
Copy link
Member

For reference, can you get an example of the kind of information you are adding to the route metadata?

@ittennull
Copy link
Author

ittennull commented Oct 19, 2020

For reference, can you get an example of the kind of information you are adding to the route metadata?

Sure. I'm still in a process of estimating yarp and I'm working on a POC that has the functionality that is currently used in production. I'm thinking on separating configuration from the RP itself so that I don't need to update RP every time I add new route. It should look like this

RP ---watch_and_load---> combined JSON config <---update--- ConfigUpdaterApp
                                                                ↑       ↑
                                                  route_collection1    route_collection2

I want combined json config to be a standard config for RP, no additional stuff. That means currently that I need to rely on metadata if I want something custom (transform extensibility isn't there yet). Something custom is for example a transformation that is not available in RP now or another middleware that I want to activate on the route. For example I want to short circuit certain paths and don't let them go through. I add metadata item { "ShortCircuit", ""}. Now in my RP I add a ShortCircuitMiddleware that needs to somehow understand which routes should be short circuited. Since all the meatadata is available on the endpoint (only hidden because of internal classes) I could use

if (context.GetEndpoint()?.Metadata.GetMetadata<RouteConfig>()?.Metadata?.TryGetValue("ShortCircuit", out var _) ?? false)
    // short circuit the request

So I want to reuse existing ProxyRoute structure to add functionality and I need an access to this additional data

@ittennull ittennull closed this Oct 19, 2020
@Kahbazi
Copy link
Collaborator

Kahbazi commented Oct 19, 2020

After #328 got merged, you could add your custom metadata to YARP endpoints.

@Tratcher
Copy link
Member

@Kahbazi I think they're asking about different metadata in this case. Endpoint.Metadata is a routing concept, but RouteConfig.Metadata is just extra config input.

@Kahbazi
Copy link
Collaborator

Kahbazi commented Oct 19, 2020

@Tratcher I was thinking about adding ProxyRoute.Metadata directly to Endpoint.Metadata or creates an object from ProxyRoute.Metadata and add it to Endpoint.Metadata in ReverseProxyConventionBuilder.ConfigureRoutes(Action<IEndpointConventionBuilder, ProxyRoute> convention).

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.

3 participants