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
e323e05e
Commit
e323e05e
authored
Jan 29, 2020
by
babjo
Committed by
Stephane Nicoll
Feb 04, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop time web metrics when autotime is disabled
See gh-19981
parent
fa239a06
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
5 deletions
+37
-5
TestController.java
...oot/actuate/autoconfigure/metrics/web/TestController.java
+9
-0
WebMvcMetricsAutoConfigurationTests.java
...rics/web/servlet/WebMvcMetricsAutoConfigurationTests.java
+23
-3
WebMvcMetricsFilter.java
...boot/actuate/metrics/web/servlet/WebMvcMetricsFilter.java
+5
-2
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/TestController.java
View file @
e323e05e
...
@@ -16,6 +16,8 @@
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
metrics
.
web
;
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
metrics
.
web
;
import
io.micrometer.core.annotation.Timed
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
...
@@ -24,6 +26,7 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -24,6 +26,7 @@ import org.springframework.web.bind.annotation.RestController;
*
*
* @author Dmytro Nosan
* @author Dmytro Nosan
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Chanhyeong LEE
*/
*/
@RestController
@RestController
public
class
TestController
{
public
class
TestController
{
...
@@ -43,4 +46,10 @@ public class TestController {
...
@@ -43,4 +46,10 @@ public class TestController {
return
"test2"
;
return
"test2"
;
}
}
@Timed
@GetMapping
(
"test3"
)
public
String
test3
()
{
return
"test2"
;
}
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfigurationTests.java
View file @
e323e05e
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
metrics
.
web
.
servlet
;
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
metrics
.
web
.
servlet
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.EnumSet
;
import
java.util.EnumSet
;
...
@@ -24,6 +25,7 @@ import javax.servlet.Filter;
...
@@ -24,6 +25,7 @@ import javax.servlet.Filter;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
io.micrometer.core.instrument.Meter
;
import
io.micrometer.core.instrument.MeterRegistry
;
import
io.micrometer.core.instrument.MeterRegistry
;
import
io.micrometer.core.instrument.Tag
;
import
io.micrometer.core.instrument.Tag
;
import
io.micrometer.core.instrument.Timer
;
import
io.micrometer.core.instrument.Timer
;
...
@@ -64,6 +66,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
...
@@ -64,6 +66,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
* @author Dmytro Nosan
* @author Dmytro Nosan
* @author Tadaya Tsuyukubo
* @author Tadaya Tsuyukubo
* @author Madhura Bhave
* @author Madhura Bhave
* @author Chanhyeong LEE
*/
*/
@ExtendWith
(
OutputCaptureExtension
.
class
)
@ExtendWith
(
OutputCaptureExtension
.
class
)
class
WebMvcMetricsAutoConfigurationTests
{
class
WebMvcMetricsAutoConfigurationTests
{
...
@@ -157,6 +160,19 @@ class WebMvcMetricsAutoConfigurationTests {
...
@@ -157,6 +160,19 @@ class WebMvcMetricsAutoConfigurationTests {
});
});
}
}
@Test
void
timerWorksWithTimedAnnotationsWhenAutoTimeRequestsIsFalse
()
{
this
.
contextRunner
.
withUserConfiguration
(
TestController
.
class
)
.
withConfiguration
(
AutoConfigurations
.
of
(
MetricsAutoConfiguration
.
class
,
WebMvcAutoConfiguration
.
class
))
.
withPropertyValues
(
"management.metrics.web.server.request.autotime.enabled=false"
).
run
((
context
)
->
{
MeterRegistry
registry
=
getInitializedMeterRegistry
(
context
,
"/test3"
);
Collection
<
Meter
>
meters
=
registry
.
get
(
"http.server.requests"
).
meters
();
assertThat
(
meters
).
hasSize
(
1
);
Meter
meter
=
meters
.
iterator
().
next
();
assertThat
(
meter
.
getId
().
getTag
(
"uri"
)).
isEqualTo
(
"/test3"
);
});
}
@Test
@Test
@SuppressWarnings
(
"rawtypes"
)
@SuppressWarnings
(
"rawtypes"
)
void
longTaskTimingInterceptorIsRegistered
()
{
void
longTaskTimingInterceptorIsRegistered
()
{
...
@@ -167,13 +183,17 @@ class WebMvcMetricsAutoConfigurationTests {
...
@@ -167,13 +183,17 @@ class WebMvcMetricsAutoConfigurationTests {
.
contains
(
LongTaskTimingHandlerInterceptor
.
class
));
.
contains
(
LongTaskTimingHandlerInterceptor
.
class
));
}
}
private
MeterRegistry
getInitializedMeterRegistry
(
AssertableWebApplicationContext
context
)
throws
Exception
{
private
MeterRegistry
getInitializedMeterRegistry
(
AssertableWebApplicationContext
context
,
String
...
urls
)
throws
Exception
{
if
(
urls
.
length
==
0
)
{
urls
=
new
String
[]
{
"/test0"
,
"/test1"
,
"/test2"
};
}
assertThat
(
context
).
hasSingleBean
(
FilterRegistrationBean
.
class
);
assertThat
(
context
).
hasSingleBean
(
FilterRegistrationBean
.
class
);
Filter
filter
=
context
.
getBean
(
FilterRegistrationBean
.
class
).
getFilter
();
Filter
filter
=
context
.
getBean
(
FilterRegistrationBean
.
class
).
getFilter
();
assertThat
(
filter
).
isInstanceOf
(
WebMvcMetricsFilter
.
class
);
assertThat
(
filter
).
isInstanceOf
(
WebMvcMetricsFilter
.
class
);
MockMvc
mockMvc
=
MockMvcBuilders
.
webAppContextSetup
(
context
).
addFilters
(
filter
).
build
();
MockMvc
mockMvc
=
MockMvcBuilders
.
webAppContextSetup
(
context
).
addFilters
(
filter
).
build
();
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
String
url
:
urls
)
{
mockMvc
.
perform
(
MockMvcRequestBuilders
.
get
(
"/test"
+
i
)).
andExpect
(
status
().
isOk
());
mockMvc
.
perform
(
MockMvcRequestBuilders
.
get
(
url
)).
andExpect
(
status
().
isOk
());
}
}
return
context
.
getBean
(
MeterRegistry
.
class
);
return
context
.
getBean
(
MeterRegistry
.
class
);
}
}
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilter.java
View file @
e323e05e
...
@@ -48,6 +48,7 @@ import org.springframework.web.util.NestedServletException;
...
@@ -48,6 +48,7 @@ import org.springframework.web.util.NestedServletException;
*
*
* @author Jon Schneider
* @author Jon Schneider
* @author Phillip Webb
* @author Phillip Webb
* @author Chanhyeong LEE
* @since 2.0.0
* @since 2.0.0
*/
*/
public
class
WebMvcMetricsFilter
extends
OncePerRequestFilter
{
public
class
WebMvcMetricsFilter
extends
OncePerRequestFilter
{
...
@@ -139,8 +140,10 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter {
...
@@ -139,8 +140,10 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter {
Set
<
Timed
>
annotations
=
getTimedAnnotations
(
handler
);
Set
<
Timed
>
annotations
=
getTimedAnnotations
(
handler
);
Timer
.
Sample
timerSample
=
timingContext
.
getTimerSample
();
Timer
.
Sample
timerSample
=
timingContext
.
getTimerSample
();
if
(
annotations
.
isEmpty
())
{
if
(
annotations
.
isEmpty
())
{
Builder
builder
=
this
.
autoTimer
.
builder
(
this
.
metricName
);
if
(
this
.
autoTimer
.
isEnabled
())
{
timerSample
.
stop
(
getTimer
(
builder
,
handler
,
request
,
response
,
exception
));
Builder
builder
=
this
.
autoTimer
.
builder
(
this
.
metricName
);
timerSample
.
stop
(
getTimer
(
builder
,
handler
,
request
,
response
,
exception
));
}
return
;
return
;
}
}
for
(
Timed
annotation
:
annotations
)
{
for
(
Timed
annotation
:
annotations
)
{
...
...
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