forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#27599 from brunobat/fix-client-request-test
Fix flaky ClientRequestTest
- Loading branch information
Showing
4 changed files
with
184 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
integration-tests/micrometer-prometheus/src/main/java/io/quarkus/ExporterResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.quarkus; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.search.Search; | ||
|
||
@Path("/server-requests") | ||
@ApplicationScoped | ||
public class ExporterResource { | ||
@Inject | ||
MeterRegistry registry; | ||
|
||
@Path("/count") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@GET | ||
public Integer countServerRequests(@QueryParam("method") String method, | ||
@QueryParam("outcome") String outcome, | ||
@QueryParam("status") String status, | ||
@QueryParam("uri") String uri) { | ||
final Search search = registry | ||
.find("http.server.requests"); | ||
if (method != null) { | ||
search.tag("method", method); | ||
} | ||
if (outcome != null) { | ||
search.tag("outcome", outcome); | ||
} | ||
if (status != null) { | ||
search.tag("status", status); | ||
} | ||
if (uri != null) { | ||
search.tag("uri", uri); | ||
} | ||
return search.timers().size(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
integration-tests/micrometer-prometheus/src/main/java/io/quarkus/Util.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.quarkus; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
|
||
public class Util { | ||
private Util() { | ||
} | ||
|
||
static String stackToString(Throwable t) { | ||
StringBuilder sb = new StringBuilder().append("\n"); | ||
while (t.getCause() != null) { | ||
t = t.getCause(); | ||
} | ||
sb.append(t.getClass()).append(": ").append(t.getMessage()).append("\n"); | ||
Arrays.asList(t.getStackTrace()).forEach(x -> sb.append("\t").append(x.toString()).append("\n")); | ||
return sb.toString(); | ||
} | ||
|
||
public static String foundServerRequests(MeterRegistry registry, String message) { | ||
return message + "\nFound:\n" + Util.listMeters(registry, "http.server.requests"); | ||
} | ||
|
||
public static String foundClientRequests(MeterRegistry registry, String message) { | ||
return message + "\nFound:\n" + Util.listMeters(registry, "http.client.requests"); | ||
} | ||
|
||
public static String listMeters(MeterRegistry registry, String meterName) { | ||
return registry.find(meterName).meters().stream() | ||
.map(x -> { | ||
return x.getId().toString(); | ||
}) | ||
.collect(Collectors.joining("\n")); | ||
} | ||
|
||
public static String listMeters(MeterRegistry registry, String meterName, final String tag) { | ||
return registry.find(meterName).meters().stream() | ||
.map(x -> { | ||
return x.getId().getTag(tag); | ||
}) | ||
.collect(Collectors.joining(",")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters