Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
c6f5961a
Commit
c6f5961a
authored
Aug 04, 2014
by
Taylor Wicksell
Committed by
Dave Syer
Aug 05, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix for gh-1331 MetricFilter now supports uri template variables when available
parent
0c6a0bde
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
8 deletions
+48
-8
MetricFilterAutoConfiguration.java
.../actuate/autoconfigure/MetricFilterAutoConfiguration.java
+5
-0
MetricFilterAutoConfigurationTests.java
...ate/autoconfigure/MetricFilterAutoConfigurationTests.java
+43
-8
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java
View file @
c6f5961a
...
@@ -39,6 +39,7 @@ import org.springframework.core.Ordered;
...
@@ -39,6 +39,7 @@ import org.springframework.core.Ordered;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.util.StopWatch
;
import
org.springframework.util.StopWatch
;
import
org.springframework.web.filter.OncePerRequestFilter
;
import
org.springframework.web.filter.OncePerRequestFilter
;
import
org.springframework.web.servlet.HandlerMapping
;
import
org.springframework.web.util.UrlPathHelper
;
import
org.springframework.web.util.UrlPathHelper
;
/**
/**
...
@@ -86,6 +87,10 @@ public class MetricFilterAutoConfiguration {
...
@@ -86,6 +87,10 @@ public class MetricFilterAutoConfiguration {
}
}
finally
{
finally
{
stopWatch
.
stop
();
stopWatch
.
stop
();
if
(
request
.
getAttribute
(
HandlerMapping
.
BEST_MATCHING_PATTERN_ATTRIBUTE
)
!=
null
)
{
suffix
=
request
.
getAttribute
(
HandlerMapping
.
BEST_MATCHING_PATTERN_ATTRIBUTE
).
toString
().
replaceAll
(
"[{}]"
,
"-"
);
}
String
gaugeKey
=
getKey
(
"response"
+
suffix
);
String
gaugeKey
=
getKey
(
"response"
+
suffix
);
MetricFilterAutoConfiguration
.
this
.
gaugeService
.
submit
(
gaugeKey
,
MetricFilterAutoConfiguration
.
this
.
gaugeService
.
submit
(
gaugeKey
,
stopWatch
.
getTotalTimeMillis
());
stopWatch
.
getTotalTimeMillis
());
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java
View file @
c6f5961a
...
@@ -16,6 +16,16 @@
...
@@ -16,6 +16,16 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
;
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
willAnswer
;
import
static
org
.
mockito
.
Matchers
.
anyDouble
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
javax.servlet.Filter
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.FilterChain
;
...
@@ -29,14 +39,10 @@ import org.springframework.context.annotation.Bean;
...
@@ -29,14 +39,10 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
org.springframework.test.web.servlet.MockMvc
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
static
org
.
mockito
.
BDDMockito
.
willAnswer
;
import
org.springframework.web.bind.annotation.RestController
;
import
static
org
.
mockito
.
Matchers
.
anyDouble
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
/**
* Tests for {@link MetricFilterAutoConfiguration}.
* Tests for {@link MetricFilterAutoConfiguration}.
...
@@ -44,6 +50,7 @@ import static org.mockito.Mockito.verify;
...
@@ -44,6 +50,7 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
* @author Phillip Webb
*/
*/
public
class
MetricFilterAutoConfigurationTests
{
public
class
MetricFilterAutoConfigurationTests
{
@Test
@Test
public
void
recordsHttpInteractions
()
throws
Exception
{
public
void
recordsHttpInteractions
()
throws
Exception
{
...
@@ -67,6 +74,21 @@ public class MetricFilterAutoConfigurationTests {
...
@@ -67,6 +74,21 @@ public class MetricFilterAutoConfigurationTests {
anyDouble
());
anyDouble
());
context
.
close
();
context
.
close
();
}
}
@Test
public
void
recordsHttpInteractionsWithTemplateVariable
()
throws
Exception
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
(
Config
.
class
,
MetricFilterAutoConfiguration
.
class
);
Filter
filter
=
context
.
getBean
(
Filter
.
class
);
MockMvc
mvc
=
MockMvcBuilders
.
standaloneSetup
(
new
MetricFilterTestController
()).
addFilter
(
filter
).
build
();
mvc
.
perform
(
get
(
"/templateVarTest/foo"
))
.
andExpect
(
status
().
isOk
());
verify
(
context
.
getBean
(
CounterService
.
class
)).
increment
(
"status.200.templateVarTest.-someVariable-"
);
verify
(
context
.
getBean
(
GaugeService
.
class
)).
submit
(
eq
(
"response.templateVarTest.-someVariable-"
),
anyDouble
());
context
.
close
();
}
@Test
@Test
public
void
skipsFilterIfMissingServices
()
throws
Exception
{
public
void
skipsFilterIfMissingServices
()
throws
Exception
{
...
@@ -88,6 +110,19 @@ public class MetricFilterAutoConfigurationTests {
...
@@ -88,6 +110,19 @@ public class MetricFilterAutoConfigurationTests {
public
GaugeService
gaugeService
()
{
public
GaugeService
gaugeService
()
{
return
mock
(
GaugeService
.
class
);
return
mock
(
GaugeService
.
class
);
}
}
}
}
}
}
@RestController
class
MetricFilterTestController
{
@RequestMapping
(
"templateVarTest/{someVariable}"
)
public
String
testTemplateVariableResolution
(
String
someVariable
)
{
return
someVariable
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment