Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoloboschi committed Aug 20, 2024
1 parent 542236c commit 265781d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,12 @@ CompletableFuture<ResponseEntity> service(
@NotBlank @PathVariable("application") String application,
@NotBlank @PathVariable("gateway") String gateway)
throws Exception {
io.micrometer.core.instrument.Timer.Sample sample = apiGatewayMetrics.startTimer();
return handleServiceCall(request, servletRequest, tenant, application, gateway)
.thenApply(
response -> {
apiGatewayMetrics.addHttpGatewayRequest(
apiGatewayMetrics.recordHttpGatewayRequest(
sample,
tenant,
application,
gateway,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
package ai.langstream.apigateway.metrics;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Timer;

public class ApiGatewayMetrics implements AutoCloseable {

private static final String TAG_TENANT = "tenant";
private static final String TAG_APPLICATION_ID = "application";
private static final String TAG_GATEWAY_ID = "gateway";

public void addHttpGatewayRequest(
public MeterRegistry getMeterRegistry() {
return Metrics.globalRegistry;
}

public Timer.Sample startTimer() {
return Timer.start(getMeterRegistry());
}

public void recordHttpGatewayRequest(
io.micrometer.core.instrument.Timer.Sample sample,
String tenant,
String applicationId,
String gatewayId,
String httpMethod,
int responseStatusCode) {
Counter.builder("langstream.gateways.http.requests")
.description("HTTP requests to gateways")
.tag(TAG_TENANT, tenant)
.tag(TAG_APPLICATION_ID, applicationId)
.tag(TAG_GATEWAY_ID, gatewayId)
.tag("http_method", httpMethod)
.tag("response_status_code", responseStatusCode + "")
.register(Metrics.globalRegistry)
.increment();
Timer timer =
Timer.builder("langstream.gateways.http.requests")
.description("HTTP requests to gateways")
.tag(TAG_TENANT, tenant)
.tag(TAG_APPLICATION_ID, applicationId)
.tag(TAG_GATEWAY_ID, gatewayId)
.tag("http_method", httpMethod)
.tag("response_status_code", responseStatusCode + "")
.publishPercentiles(0.5, 0.95, 0.99)
.register(getMeterRegistry());
sample.stop(timer);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,12 +798,13 @@ void testService() throws Exception {
produceJsonAndGetBody(valueUrl, "{\"key\": \"my-key\", \"value\": \"my-value\"}"));

String metrics = getPrometheusMetrics(port);
System.out.println(metrics);

List<ApiGatewayTestUtil.ParsedMetric> metricsList =
findMetric("langstream_gateways_http_requests_total", metrics);
findMetric("langstream_gateways_http_requests_seconds_count", metrics);
assertEquals(2, metricsList.size());
for (ApiGatewayTestUtil.ParsedMetric parsedMetric : metricsList) {
assertEquals("langstream_gateways_http_requests_total", parsedMetric.name());
assertEquals("langstream_gateways_http_requests_seconds_count", parsedMetric.name());
assertEquals("tenant1", parsedMetric.labels().get("tenant"));
assertEquals("application1", parsedMetric.labels().get("application"));
assertEquals("POST", parsedMetric.labels().get("http_method"));
Expand All @@ -815,6 +816,10 @@ void testService() throws Exception {
assertEquals("1.0", parsedMetric.value());
}
}
assertEquals(
2, findMetric("langstream_gateways_http_requests_seconds_sum", metrics).size());
assertEquals(
2, findMetric("langstream_gateways_http_requests_seconds_max", metrics).size());
}

@Test
Expand Down Expand Up @@ -868,10 +873,10 @@ void testServiceWithError() throws Exception {
String metrics = getPrometheusMetrics(port);

List<ApiGatewayTestUtil.ParsedMetric> metricsList =
findMetric("langstream_gateways_http_requests_total", metrics);
findMetric("langstream_gateways_http_requests_seconds_count", metrics);
assertEquals(1, metricsList.size());
ApiGatewayTestUtil.ParsedMetric parsedMetric = metricsList.get(0);
assertEquals("langstream_gateways_http_requests_total", parsedMetric.name());
assertEquals("langstream_gateways_http_requests_seconds_count", parsedMetric.name());
assertEquals("tenant1", parsedMetric.labels().get("tenant"));
assertEquals("application1", parsedMetric.labels().get("application"));
assertEquals("POST", parsedMetric.labels().get("http_method"));
Expand Down
2 changes: 1 addition & 1 deletion langstream-runtime/langstream-runtime-tester/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
</goals>
<configuration>
<url>https://downloads.apache.org</url>
<fromFile>kafka/3.5.2/kafka_2.13-3.5.2.tgz</fromFile>
<fromFile>kafka/3.6.2/kafka_2.13-3.6.2.tgz</fromFile>
<toDir>${project.build.directory}/kafka</toDir>
<skipIfExists>true</skipIfExists>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ USER 0

ADD maven/minio /minio/minio
ADD maven/herddb-services-0.28.0.zip /herddb/herddb-services-0.28.0.zip
COPY maven/kafka_2.13-3.5.2.tgz /kafka/kafka.tgz
COPY maven/kafka_2.13-3.6.2.tgz /kafka/kafka.tgz
COPY maven/apache-pulsar-3.2.3-bin.tar.gz /pulsar/pulsar.tar.gz


Expand Down

0 comments on commit 265781d

Please sign in to comment.