File tree 2 files changed +17
-8
lines changed
spring-boot-project/spring-boot-actuator/src
main/java/org/springframework/boot/actuate/endpoint
test/java/org/springframework/boot/actuate/metrics/export/prometheus
2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ private Enum<? extends Producible<?>> resolveProducible(Class<Enum<? extends Pro
65
65
Enum <? extends Producible <?>> result = null ;
66
66
for (String accept : accepts ) {
67
67
for (String mimeType : MimeTypeUtils .tokenize (accept )) {
68
- result = mostRecent (result , forMimeType (values , mimeType ));
68
+ result = mostRecent (result , forMimeType (values , MimeTypeUtils . parseMimeType ( mimeType ) ));
69
69
}
70
70
}
71
71
return result ;
@@ -78,14 +78,10 @@ private Enum<? extends Producible<?>> mostRecent(Enum<? extends Producible<?>> e
78
78
return (candidateOrdinal > existingOrdinal ) ? candidate : existing ;
79
79
}
80
80
81
- private Enum <? extends Producible <?>> forMimeType (List <Enum <? extends Producible <?>>> values , String mimeType ) {
82
- if ("*/*" . equals ( mimeType )) {
81
+ private Enum <? extends Producible <?>> forMimeType (List <Enum <? extends Producible <?>>> values , MimeType mimeType ) {
82
+ if (mimeType . isWildcardType () && mimeType . isWildcardSubtype ( )) {
83
83
return getDefaultValue (values );
84
84
}
85
- return forMimeType (values , MimeTypeUtils .parseMimeType (mimeType ));
86
- }
87
-
88
- private Enum <? extends Producible <?>> forMimeType (List <Enum <? extends Producible <?>>> values , MimeType mimeType ) {
89
85
for (Enum <? extends Producible <?>> candidate : values ) {
90
86
if (mimeType .isCompatibleWith (((Producible <?>) candidate ).getProducedMimeType ())) {
91
87
return candidate ;
Original file line number Diff line number Diff line change @@ -41,12 +41,25 @@ class PrometheusScrapeEndpointIntegrationTests {
41
41
42
42
@ WebEndpointTest
43
43
void scrapeHasContentTypeText004ByDefault (WebTestClient client ) {
44
+ String expectedContentType = TextFormat .CONTENT_TYPE_004 ;
45
+ assertThat (TextFormat .chooseContentType (null )).isEqualTo (expectedContentType );
44
46
client .get ().uri ("/actuator/prometheus" ).exchange ().expectStatus ().isOk ().expectHeader ()
45
- .contentType (MediaType .parseMediaType (TextFormat . CONTENT_TYPE_004 )).expectBody (String .class )
47
+ .contentType (MediaType .parseMediaType (expectedContentType )).expectBody (String .class )
46
48
.value ((body ) -> assertThat (body ).contains ("counter1_total" ).contains ("counter2_total" )
47
49
.contains ("counter3_total" ));
48
50
}
49
51
52
+ @ WebEndpointTest
53
+ void scrapeHasContentTypeText004ByDefaultWhenClientAcceptsWildcardWithParameter (WebTestClient client ) {
54
+ String expectedContentType = TextFormat .CONTENT_TYPE_004 ;
55
+ String accept = "*/*;q=0.8" ;
56
+ assertThat (TextFormat .chooseContentType (accept )).isEqualTo (expectedContentType );
57
+ client .get ().uri ("/actuator/prometheus" ).accept (MediaType .parseMediaType (accept )).exchange ().expectStatus ()
58
+ .isOk ().expectHeader ().contentType (MediaType .parseMediaType (expectedContentType ))
59
+ .expectBody (String .class ).value ((body ) -> assertThat (body ).contains ("counter1_total" )
60
+ .contains ("counter2_total" ).contains ("counter3_total" ));
61
+ }
62
+
50
63
@ WebEndpointTest
51
64
void scrapeCanProduceOpenMetrics100 (WebTestClient client ) {
52
65
MediaType openMetrics = MediaType .parseMediaType (TextFormat .CONTENT_TYPE_OPENMETRICS_100 );
You can’t perform that action at this time.
0 commit comments