These are chat archives for spring-cloud/spring-cloud

20th
Sep 2018
Andrew Fitzgerald
@fitzoh
Sep 20 2018 12:22

@spencergibb related-ish follow-up question…
I’ve got my janky sticky service discovery mechanism, and I’m setting the request URL to one of my given servers via GATEWAY_REQUEST_URL_ATTR

The thing that kind of sucks about that is that the metrics filter just uses the initial metrics filter uses the placeholder URI that I’m throwing away instead of the server we’re actually routing to which would be much more useful.

From looking through the code, it looks like the same thing happens with the built in routing filter?

I found a workaround that makes things a little easier by updating the Route URI in GATEWAY_ROUTE_ATTR instead of the GATEWAY_REQUEST_URL_ATTR.

        Route originalRoute = exchange.getAttribute(GATEWAY_ROUTE_ATTR);
        Route updatedRoute = Route.async()
                .id(originalRoute.getId())
                .uri(serverList.getServerURI(serverIdentifier))
                .asyncPredicate(originalRoute.getPredicate())
                .filters(originalRoute.getFilters())
                .build();

        exchange.getAttributes().put(GATEWAY_ROUTE_ATTR, updatedRoute);

Modifying the route is a little awkward w/ the current api (had to do some digging through the builders to find the right incantation), but the result is nice.

It gives a potentially much more useful set of metrics, and the logic to build the final URL is a lot simpler.

Any thoughts?

Spencer Gibb
@spencergibb
Sep 20 2018 20:54
@Fitzoh maybe the metrics filter needs to be updated