Skip to content

Commit

Permalink
fix opentracing-contrib#147 by using the base path attribute instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
psychobaatezu committed Dec 16, 2021
1 parent e394c57 commit d7ec67e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016-2019 The OpenTracing Authors
* Copyright 2016-2021 The OpenTracing Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -65,13 +65,17 @@ protected static class ManagementSkipPatternProviderConfig {

static Optional<Pattern> getPatternForManagementServerProperties(
ManagementServerProperties managementServerProperties) {
String contextPath = managementServerProperties.getServlet().getContextPath();
String contextPath = managementServerProperties.getBasePath();
if (StringUtils.hasText(contextPath)) {
return Optional.of(Pattern.compile(contextPath + ".*"));
return Optional.of(Pattern.compile(cleanup(contextPath) + ".*"));
}
return Optional.empty();
}

private static String cleanup(String contextPath) {
return contextPath.startsWith("/") ? contextPath.substring(1) : contextPath;
}

@Bean
@ConditionalOnBean(ManagementServerProperties.class)
public SkipPattern skipPatternForManagementServerProperties(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016-2019 The OpenTracing Authors
* Copyright 2016-2021 The OpenTracing Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -62,10 +62,21 @@ public void testShouldReturnEmptyWhenManagementContextHasNoContextPath() {
then(pattern).isEmpty();
}

@Test
public void testShouldReturnEmptyWhenManagementContextHasOnlyARootSlashHasContextPath() {
ManagementServerProperties properties = new ManagementServerProperties();
properties.setBasePath("/");

Optional<Pattern> pattern = new SkipPatternAutoConfiguration.ManagementSkipPatternProviderConfig()
.skipPatternForManagementServerProperties(properties).pattern();

then(pattern).isEmpty();
}

@Test
public void testShouldReturnManagementContextWithContextPath() {
ManagementServerProperties properties = new ManagementServerProperties();
properties.getServlet().setContextPath("foo");
properties.setBasePath("foo");

Optional<Pattern> pattern = new SkipPatternAutoConfiguration.ManagementSkipPatternProviderConfig()
.skipPatternForManagementServerProperties(properties).pattern();
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2016-2020 The OpenTracing Authors
Copyright 2016-2021 The OpenTracing Authors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -64,9 +64,9 @@
<version.io.opentracing.contrib-opentracing-spring-tracer-configuration-starter>0.4.0</version.io.opentracing.contrib-opentracing-spring-tracer-configuration-starter>
<version.junit>4.13.1</version.junit>
<version.org.mockito-mockito-core>2.23.4</version.org.mockito-mockito-core>
<version.org.springframework.boot>2.3.4.RELEASE</version.org.springframework.boot>
<version.org.springframework.boot>2.4.0</version.org.springframework.boot>
<!-- Should match version from https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-dependencies/pom.xml -->
<version.org.springframework>5.2.9.RELEASE</version.org.springframework>
<version.org.springframework>5.3.1</version.org.springframework>
<version.com.github.tomakehurst-wiremock-jre8>2.21.0</version.com.github.tomakehurst-wiremock-jre8>
<version.io.projectreactor.netty-reactor-netty>0.9.12.RELEASE</version.io.projectreactor.netty-reactor-netty>

Expand Down

0 comments on commit d7ec67e

Please sign in to comment.