Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-boot-admin
Project
Overview
Details
Activity
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
openSource
spring-boot-admin
Commits
35074676
Commit
35074676
authored
Jul 16, 2018
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Be more resilient when endpoints with the same id are discovered.
fixes #828
parent
c4264c7d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
6 deletions
+35
-6
ProbeEndpointsStrategy.java
...min/server/services/endpoints/ProbeEndpointsStrategy.java
+33
-5
ProbeEndpointsStrategyTest.java
...server/services/endpoints/ProbeEndpointsStrategyTest.java
+2
-1
No files found.
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/services/endpoints/ProbeEndpointsStrategy.java
View file @
35074676
...
...
@@ -27,13 +27,20 @@ import reactor.core.publisher.Mono;
import
java.net.URI
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.util.Assert
;
import
org.springframework.web.reactive.function.client.ClientResponse
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
static
java
.
util
.
stream
.
Collectors
.
groupingBy
;
public
class
ProbeEndpointsStrategy
implements
EndpointDetectionStrategy
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ProbeEndpointsStrategy
.
class
);
private
final
Collection
<
EndpointDefinition
>
endpoints
;
private
final
InstanceWebClient
instanceWebClient
;
...
...
@@ -49,7 +56,7 @@ public class ProbeEndpointsStrategy implements EndpointDetectionStrategy {
return
Flux
.
fromIterable
(
endpoints
)
.
flatMap
(
endpoint
->
detectEndpoint
(
instance
,
endpoint
))
.
collectList
()
.
flatMap
(
list
->
list
.
isEmpty
()
?
Mono
.
empty
()
:
Mono
.
just
(
Endpoints
.
of
(
list
))
);
.
flatMap
(
this
::
convert
);
}
private
Mono
<
Endpoint
>
detectEndpoint
(
Instance
instance
,
EndpointDefinition
endpoint
)
{
...
...
@@ -63,9 +70,29 @@ public class ProbeEndpointsStrategy implements EndpointDetectionStrategy {
private
Function
<
ClientResponse
,
Mono
<
Endpoint
>>
convert
(
EndpointDefinition
endpoint
,
URI
uri
)
{
return
response
->
response
.
bodyToMono
(
Void
.
class
)
.
then
(
response
.
statusCode
().
is2xxSuccessful
()
?
Mono
.
just
(
Endpoint
.
of
(
endpoint
.
getId
(),
uri
.
toString
()))
:
Mono
.
empty
());
.
then
(
response
.
statusCode
()
.
is2xxSuccessful
()
?
Mono
.
just
(
Endpoint
.
of
(
endpoint
.
getId
(),
uri
.
toString
()
))
:
Mono
.
empty
());
}
private
Mono
<
Endpoints
>
convert
(
List
<
Endpoint
>
endpoints
)
{
if
(
endpoints
.
isEmpty
())
{
return
Mono
.
empty
();
}
Map
<
String
,
List
<
Endpoint
>>
endpointsById
=
endpoints
.
stream
().
collect
(
groupingBy
(
Endpoint:
:
getId
));
List
<
Endpoint
>
result
=
endpointsById
.
values
().
stream
().
map
(
endpointList
->
{
if
(
endpointList
.
size
()
>
1
)
{
log
.
warn
(
"Duplicate endpoints for id '{}' detected. Omitting: {}"
,
endpointList
.
get
(
0
).
getId
(),
endpointList
.
subList
(
1
,
endpointList
.
size
())
);
}
return
endpointList
.
get
(
0
);
}).
collect
(
Collectors
.
toList
());
return
Mono
.
just
(
Endpoints
.
of
(
result
));
}
@Data
...
...
@@ -79,7 +106,8 @@ public class ProbeEndpointsStrategy implements EndpointDetectionStrategy {
return
new
EndpointDefinition
(
idWithPath
,
idWithPath
);
}
else
{
return
new
EndpointDefinition
(
idWithPath
.
substring
(
0
,
idxDelimiter
),
idWithPath
.
substring
(
idxDelimiter
+
1
));
idWithPath
.
substring
(
idxDelimiter
+
1
)
);
}
}
}
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/server/services/endpoints/ProbeEndpointsStrategyTest.java
View file @
35074676
...
...
@@ -63,12 +63,13 @@ public class ProbeEndpointsStrategyTest {
.
managementUrl
(
wireMock
.
url
(
"/mgmt"
))
.
build
());
wireMock
.
stubFor
(
options
(
urlEqualTo
(
"/mgmt/metrics"
)).
willReturn
(
ok
()));
wireMock
.
stubFor
(
options
(
urlEqualTo
(
"/mgmt/stats"
)).
willReturn
(
ok
()));
wireMock
.
stubFor
(
options
(
urlEqualTo
(
"/mgmt/info"
)).
willReturn
(
ok
()));
wireMock
.
stubFor
(
options
(
urlEqualTo
(
"/mgmt/non-exist"
)).
willReturn
(
notFound
()));
ProbeEndpointsStrategy
strategy
=
new
ProbeEndpointsStrategy
(
instanceWebClient
,
new
String
[]{
"metrics:stats"
,
"info"
,
"non-exist"
});
new
String
[]{
"metrics:stats"
,
"
metrics"
,
"
info"
,
"non-exist"
});
//when
StepVerifier
.
create
(
strategy
.
detectEndpoints
(
instance
))
...
...
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