Skip to content

ControllerLinkBuilder.linkTo is not working for actuator @Endpoint #674

Closed
@Aloren

Description

@Aloren

We are currently in the process of migrating from Spring Boot 1.5 to 2.0. We were previously using actuator's class MvcEndpoint with @RequestMapping. Now new annotation for actuator endpoints was introduced: @Endpoint. The following code was producing valid hateoas links in Spring Boot 1.5:

@RequestMapping("/dashboards")
public class MetricsDashboardsEndpoint implements MvcEndpoint {
    @RequestMapping(method = GET)
    @ResponseBody
    public List<Link> dashboards() throws IOException {
        return resources.keySet().stream()
                .map(name -> linkTo(DashboardsEndpoint.class).slash(name).withRel("dashboard"))
                .collect(Collectors.toList());
    }

The same code migrated to Spring Boot 2.0:

@Endpoint(id = "dashboards")
public class MetricsDashboardsEndpoint {
    @ReadOperation
    public List<Link> dashboards() throws IOException {
        return resources.keySet().stream()
                .map(name -> linkTo(MetricsDashboardsEndpoint.class).slash(name).withRel("dashboard"))
                .collect(Collectors.toList());
    }

Actual result in Spring Boot 1.5: "href":"http://localhost:9999/dashboards/dashboard2.json"
Actual result in in Spring Boot 2.0: "href":"http://localhost:9999/dashboard2.json"
Expected result in Spring Boot 2.0: "href":"http://localhost:9999/application/dashboards/dashboard2.json"

As I understand the issue is within ControllerLinkBuilder:

	private static final CachingAnnotationMappingDiscoverer DISCOVERER = new CachingAnnotationMappingDiscoverer(
			new AnnotationMappingDiscoverer(RequestMapping.class));

It only knows about @RequestMapping and knows nothing about new @Endpoint.

Could you please advise what is the correct way in Spring Boot Actuator 2.0 to produce links with valid base path?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions