use of java.net.http.HttpRequest in project jena by apache.
the class TestMetrics method can_retrieve_metrics.
@Test
public void can_retrieve_metrics() {
String r = urlRoot() + "$/metrics";
HttpRequest request = HttpRequest.newBuilder().uri(HttpLib.toRequestURI(r)).build();
HttpResponse<InputStream> response = HttpLib.executeJDK(HttpEnv.getDftHttpClient(), request, BodyHandlers.ofInputStream());
String body = handleResponseRtnString(response);
String ct = response.headers().firstValue(HttpNames.hContentType).orElse(null);
assertTrue(ct.contains(WebContent.contentTypeTextPlain));
assertTrue(ct.contains(WebContent.charsetUTF8));
assertTrue(body.contains("fuseki_requests_good"));
}
use of java.net.http.HttpRequest in project pravega by pravega.
the class ControllerPrometheusTest method testPrometheusMetrics.
@Test
public void testPrometheusMetrics() throws Exception {
MetricsProvider.initialize(MetricsConfig.builder().with(MetricsConfig.ENABLE_STATISTICS, true).with(MetricsConfig.ENABLE_PROMETHEUS, true).with(MetricsConfig.METRICS_PREFIX, "promtestcontroller").build());
@Cleanup StatsProvider statsProvider = MetricsProvider.getMetricsProvider();
statsProvider.start();
@Cleanup ControllerServiceStarter starter = new ControllerServiceStarter(createControllerServiceConfig(), storeClient, null);
starter.startAsync();
starter.awaitRunning();
Counter c = statsProvider.createStatsLogger("promtest").createCounter("promtestcounter");
c.add(1);
HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build();
HttpRequest request = HttpRequest.newBuilder().uri(URI.create("http://localhost:" + this.restPort + "/prometheus")).build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
assertTrue(response.body().lines().anyMatch(x -> Pattern.matches("promtestcounter.*1\\.0", x)));
starter.stopAsync();
starter.awaitTerminated();
}
use of java.net.http.HttpRequest in project pravega by pravega.
the class PrometheusTest method testPrometheusMetrics.
@Test
public void testPrometheusMetrics() throws Exception {
@Cleanup StatsProvider statsProvider = MetricsProvider.getMetricsProvider();
statsProvider.start();
Counter c = statsProvider.createStatsLogger("promtest").createCounter("promtestcounter");
c.add(1);
HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build();
HttpRequest request = HttpRequest.newBuilder().uri(URI.create("http://localhost:" + this.restPort + "/prometheus")).build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
assertTrue(response.body().lines().anyMatch(x -> Pattern.matches("promtestcounter.*1\\.0", x)));
}
use of java.net.http.HttpRequest in project pravega by pravega.
the class PrometheusResourceTest method testScrape.
@Test
public void testScrape() throws Exception {
MetricsConfig appConfig = MetricsConfig.builder().with(MetricsConfig.ENABLE_STATISTICS, true).with(MetricsConfig.ENABLE_PROMETHEUS, true).build();
@Cleanup CompositeMeterRegistry localRegistry = new CompositeMeterRegistry();
@Cleanup StatsProvider statsProvider = new StatsProviderImpl(appConfig, localRegistry);
statsProvider.start();
for (MeterRegistry registry : localRegistry.getRegistries()) {
assertTrue(registry instanceof PrometheusMeterRegistry);
}
assertTrue(statsProvider.prometheusResource().isPresent());
ResourceConfig rc = ResourceConfig.forApplication(new PrometheusApplication(statsProvider));
URI baseUri = UriBuilder.fromUri("http://localhost/").port(TestUtils.getAvailableListenPort()).build();
@Cleanup("shutdown") HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, rc);
Counter c = statsProvider.createStatsLogger("promtest").createCounter("promtestcounter");
c.add(1);
HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build();
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(baseUri + "prometheus")).build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
assertTrue(response.body().lines().anyMatch(x -> Pattern.matches("promtestcounter.*1\\.0", x)));
server.shutdown();
}
use of java.net.http.HttpRequest in project alf.io by alfio-event.
the class FileDownloadManager method downloadFile.
public DownloadedFile downloadFile(String url) {
HttpRequest httpRequest = HttpRequest.newBuilder(URI.create(url)).GET().build();
HttpResponse<byte[]> response = null;
try {
response = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofByteArray());
} catch (IOException exception) {
logWarning(exception);
return null;
} catch (InterruptedException exception) {
Thread.currentThread().interrupt();
logWarning(exception);
return null;
}
if (callSuccessful(response)) {
String[] parts = Pattern.compile("/").split(url);
String name = parts[parts.length - 1];
if (Objects.nonNull(response.body()) && response.body().length <= FileUploadManager.MAXIMUM_ALLOWED_SIZE) {
return new DownloadedFile(response.body(), name, response.headers().firstValue("Content-Type").orElse("application/octet-stream"));
} else {
return null;
}
} else {
log.warn("downloading file not successful:" + response);
return null;
}
}
Aggregations