Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
carts
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cld
S
systems
sock-shop
carts
Commits
620e51b5
Commit
620e51b5
authored
Mar 15, 2017
by
Phil Winder
Committed by
GitHub
Mar 15, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #29 from microservices-demo/monitoring/match-request
Match request to prevent metric for each ID.
parents
1ef22f59
abd7e71f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
1 deletion
+26
-1
src/main/java/works/weave/socks/cart/middleware/HTTPMonitoringInterceptor.java
...eave/socks/cart/middleware/HTTPMonitoringInterceptor.java
+26
-1
No files found.
src/main/java/works/weave/socks/cart/middleware/HTTPMonitoringInterceptor.java
View file @
620e51b5
package
works.weave.socks.cart.middleware
;
import
io.prometheus.client.Histogram
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.mvc.method.RequestMappingInfo
;
import
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.Map
;
public
class
HTTPMonitoringInterceptor
implements
HandlerInterceptor
{
static
final
Histogram
requestLatency
=
Histogram
.
build
()
...
...
@@ -20,6 +25,9 @@ public class HTTPMonitoringInterceptor implements HandlerInterceptor {
@Value
(
"${spring.application.name:carts}"
)
private
String
serviceName
;
@Autowired
private
RequestMappingHandlerMapping
requestMappingHandlerMapping
;
@Override
public
boolean
preHandle
(
HttpServletRequest
httpServletRequest
,
HttpServletResponse
httpServletResponse
,
Object
o
)
throws
Exception
{
...
...
@@ -36,7 +44,7 @@ public class HTTPMonitoringInterceptor implements HandlerInterceptor {
requestLatency
.
labels
(
serviceName
,
httpServletRequest
.
getMethod
(),
httpServletRequest
.
getServletPath
(
),
getMatchingURLPattern
(
httpServletRequest
),
Integer
.
toString
(
httpServletResponse
.
getStatus
())
).
observe
(
seconds
);
}
...
...
@@ -45,4 +53,21 @@ public class HTTPMonitoringInterceptor implements HandlerInterceptor {
public
void
afterCompletion
(
HttpServletRequest
httpServletRequest
,
HttpServletResponse
httpServletResponse
,
Object
o
,
Exception
e
)
throws
Exception
{
}
private
String
getMatchingURLPattern
(
HttpServletRequest
httpServletRequest
)
{
String
res
=
httpServletRequest
.
getServletPath
();
for
(
Map
.
Entry
<
RequestMappingInfo
,
HandlerMethod
>
item
:
requestMappingHandlerMapping
.
getHandlerMethods
().
entrySet
())
{
RequestMappingInfo
mapping
=
item
.
getKey
();
if
(
mapping
.
getPatternsCondition
().
getMatchingCondition
(
httpServletRequest
)
!=
null
&&
mapping
.
getMethodsCondition
().
getMatchingCondition
(
httpServletRequest
)
!=
null
)
{
res
=
mapping
.
getPatternsCondition
().
getMatchingCondition
(
httpServletRequest
)
.
getPatterns
().
iterator
().
next
();
break
;
}
}
return
res
;
}
}
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