spring-projects / spring-projects/spring-boot

Add bean id to Actuator (mappings) JSON data for functional routes

Open
#15,230 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: pending-design-work type: enhancement
Dominant language
Java
Stars
81.5k
Forks
42.7k
Avg merge
2d 4h
Merged PRs (30d)
65

Description

STS team attempts to find a spot in the source code that declares routes using functional style using the JSON data from the Actuator.

Source code example:

public class VetsRouter {

	@Bean
	public RouterFunction<ServerResponse> route(VetsHandler vetsHandler) {
		return RouterFunctions
			.route(RequestPredicates.GET("/vets").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), vetsHandler::vets)
			.andRoute(RequestPredicates.GET("/vets.html"), vetsHandler::vetsHtml);
	}
	
	@Bean
	public RouterFunction<ServerResponse> moreRoute(VetsHandler vetsHandler) {
		return RouterFunctions
			.route(RequestPredicates.GET("/new-vets").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), vetsHandler::vets)
			.andRoute(RequestPredicates.GET("/new-vets.html"), vetsHandler::vetsHtml);
	}
}

The JSON data from the Actuator for /vets route:

          {
            "predicate": "((GET && /vets) && Accept: [text/plain])",
            "handler": "org.springframework.samples.petclinic.deviations.VetsRouter$$Lambda$868/443912630@369564bd",
            "details": {
              "handlerFunction": {
                "className": "org.springframework.samples.petclinic.deviations.VetsRouter$$Lambda$868/443912630"
              }
            }
          },

There are two pieces of data to help matching are predicate and handler
The handler data should be most helpful in matching the proper place in the source. The matching place in the source code we think should be the route method declaration. Based on the handler's data we cannot match the route method unfortunately. The lambda with magic numbers is useless in this case.

It'd be great if the details object had something helpful to find the route method. Either method signature or perhaps the id of the corresponding RouterFunction bean. Seemed like getting the bean id into the JSON is doable (ApplicationContext.getBeansOfType(RouterFunction.class, true, true) gives an id -> bean object map, given a RouterFunction object should be easy to get the corresponding id ). Therefore the JSON would look like:

          {
            "predicate": "((GET && /vets) && Accept: [text/plain])",
            "handler": "org.springframework.samples.petclinic.deviations.VetsRouter$$Lambda$868/443912630@369564bd",
            "details": {
              "handlerFunction": {
                "className": "org.springframework.samples.petclinic.deviations.VetsRouter$$Lambda$868/443912630"
              },
              "bean": "route"
            }
          },

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Actuator /mappings JSON generation for functional RouterFunction routes and inspect how the handlerFunction details are assembled. Investigate the proposed ApplicationContext.getBeansOfType(RouterFunction.class, true, true) lookup and determine how a matching bean id could be represented in the details object; done means the JSON identifies the corresponding RouterFunction bean for the shown routes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.