Search in sources :

Example 1 with InMemoryMetrics

use of com.artipie.metrics.memory.InMemoryMetrics in project artipie by artipie.

the class TrafficMetricSliceTest method updatesMetrics.

@Test
void updatesMetrics() throws Exception {
    final Metrics metrics = new InMemoryMetrics();
    final int req = 100;
    final int res = 50;
    new TrafficMetricSlice((line, head, body) -> new RsWithBody(Flowable.fromPublisher(body).ignoreElements().andThen(Flowable.just(ByteBuffer.wrap(new byte[res])))), metrics).response(new RequestLine(RqMethod.GET, "/foo").toString(), Collections.emptyList(), Flowable.just(ByteBuffer.wrap(new byte[req]))).send((status, headers, body) -> Flowable.fromPublisher(body).ignoreElements().to(CompletableInterop.await())).toCompletableFuture().get();
    final TestMetricsOutput out = new TestMetricsOutput();
    metrics.publish(out);
    MatcherAssert.assertThat("request body size wasn't updated", out.counters().get("request.body.size"), Matchers.equalTo((long) req));
    MatcherAssert.assertThat("response body size wasn't updated", out.counters().get("response.body.size"), Matchers.equalTo((long) res));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) Metrics(com.artipie.metrics.Metrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) TestMetricsOutput(com.artipie.metrics.memory.TestMetricsOutput) RsWithBody(com.artipie.http.rs.RsWithBody) Test(org.junit.jupiter.api.Test)

Example 2 with InMemoryMetrics

use of com.artipie.metrics.memory.InMemoryMetrics in project artipie by artipie.

the class PromuSliceTest method returnsMetricsThatMatchNames.

@Test
void returnsMetricsThatMatchNames() {
    final Metrics metrics = new InMemoryMetrics();
    metrics.counter("http.response.count").inc();
    metrics.gauge("http.response.content").set(5000L);
    metrics.gauge("app.workload").set(300L);
    MatcherAssert.assertThat(new PromuSlice(metrics), new SliceHasResponse(new RsHasBody(new AnyOf<>(new IsEqual<>(String.join("\n", "# HELP http_response_content Http response content", "# TYPE http_response_content gauge", "http_response_content 5000.0", "# HELP app_workload App workload", "# TYPE app_workload gauge", "app_workload 300.0", "")), new IsEqual<>(String.join("\n", "# HELP app_workload App workload", "# TYPE app_workload gauge", "app_workload 300.0", "# HELP http_response_content Http response content", "# TYPE http_response_content gauge", "http_response_content 5000.0", ""))), StandardCharsets.UTF_8), new RequestLine(RqMethod.GET, "/prometheus/metrics?name=http_response_content&name=app_workload"), new Headers.From(new Header(Accept.NAME, PromuSliceTest.PLAIN_TEXT)), Content.EMPTY));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) Metrics(com.artipie.metrics.Metrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) Header(com.artipie.http.headers.Header) RsHasBody(com.artipie.http.hm.RsHasBody) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with InMemoryMetrics

use of com.artipie.metrics.memory.InMemoryMetrics in project artipie by artipie.

the class PromuSliceTest method producesMetrics.

@ParameterizedTest
@CsvSource({ "http.response.length,500,counter,text/plain", "http.response.length,500,counter,application/openmetrics-text", "app.used.memory,200,gauge,text/plain", "app.used.memory,200,gauge,application/openmetrics-text" })
void producesMetrics(final String name, final long value, final String type, final String mimetype) {
    final Metrics metrics = new InMemoryMetrics();
    collect(metrics, name, value, type);
    MatcherAssert.assertThat(new PromuSlice(metrics), new SliceHasResponse(new AllOf<>(Arrays.asList(new RsHasStatus(RsStatus.OK), new RsHasHeaders(new IsEqual<>(new Header(ContentType.NAME, mimetype)), new IsAnything<>()), new RsHasBody(new MatchesPattern(Pattern.compile(metricFormatted(name, value, type, mimetype))), StandardCharsets.UTF_8))), new RequestLine(RqMethod.GET, "/prometheus/metrics"), new Headers.From(Accept.NAME, mimetype), Content.EMPTY));
}
Also used : SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) MatchesPattern(org.hamcrest.text.MatchesPattern) RsHasHeaders(com.artipie.http.hm.RsHasHeaders) RequestLine(com.artipie.http.rq.RequestLine) Metrics(com.artipie.metrics.Metrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) Header(com.artipie.http.headers.Header) RsHasBody(com.artipie.http.hm.RsHasBody) AllOf(org.hamcrest.core.AllOf) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

RequestLine (com.artipie.http.rq.RequestLine)3 Metrics (com.artipie.metrics.Metrics)3 InMemoryMetrics (com.artipie.metrics.memory.InMemoryMetrics)3 Header (com.artipie.http.headers.Header)2 RsHasBody (com.artipie.http.hm.RsHasBody)2 SliceHasResponse (com.artipie.http.hm.SliceHasResponse)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 RsHasHeaders (com.artipie.http.hm.RsHasHeaders)1 RsHasStatus (com.artipie.http.hm.RsHasStatus)1 RsWithBody (com.artipie.http.rs.RsWithBody)1 TestMetricsOutput (com.artipie.metrics.memory.TestMetricsOutput)1 AllOf (org.hamcrest.core.AllOf)1 IsEqual (org.hamcrest.core.IsEqual)1 MatchesPattern (org.hamcrest.text.MatchesPattern)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1