Skip to content

Commit

Permalink
OAP-206 bump s3mock to 3.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nofateg authored Sep 11, 2024
1 parent 3369c25 commit 3e88b08
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 29 deletions.
15 changes: 10 additions & 5 deletions oap-http/oap-http-prometheus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@
<artifactId>oap-http</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>oap</groupId>
<artifactId>oap-stdlib-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

<dependency>
<groupId>oap</groupId>
<artifactId>oap-stdlib-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,28 @@

package oap.http.prometheus;

import io.micrometer.core.instrument.Measurement;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.prometheus.client.exporter.common.TextFormat;
import io.micrometer.prometheusmetrics.PrometheusConfig;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
import lombok.extern.slf4j.Slf4j;
import oap.http.server.nio.HttpHandler;
import oap.http.server.nio.HttpServerExchange;
import oap.http.server.nio.NioHttpServer;

import java.util.List;

@Slf4j
public class PrometheusExporter implements HttpHandler {
public static final PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry( PrometheusConfig.DEFAULT );
public static final String CONTENT_TYPE_TEXT_004 = "text/plain; version=0.0.4; charset=utf-8";
private static long metricCount = 0L;

static {
Metrics.addRegistry( prometheusRegistry );

Metrics.gauge( "system_metrics_total", prometheusRegistry, pmr -> metricCount );
Metrics.gauge( "system_metrics", prometheusRegistry, _ -> metricCount );
}

public PrometheusExporter( NioHttpServer server ) {
Expand All @@ -52,21 +56,24 @@ public PrometheusExporter( NioHttpServer server, String port ) {
server.bind( "/metrics", this, port );
}

private static long getMetricCount() {
long count = 0;

List<Meter> meters = prometheusRegistry.getMeters();
for( Meter meter : meters ) {
for( Measurement measurement : meter.measure() ) {
count++;
}
}

return count;
}

@Override
public void handleRequest( HttpServerExchange exchange ) throws Exception {
metricCount = getMetricCount();

var response = prometheusRegistry.scrape();
exchange.responseOk( response, TextFormat.CONTENT_TYPE_004 );
}

private static long getMetricCount() {
long count = 0;
var en = prometheusRegistry.getPrometheusRegistry().metricFamilySamples();
while( en.hasMoreElements() ) {
var s = en.nextElement();
count += s.samples.size();
}
return count;
exchange.responseOk( response, CONTENT_TYPE_TEXT_004 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

package oap.http.prometheus;

import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.search.Search;
import oap.http.Client;
import oap.http.server.nio.NioHttpServer;
import oap.testng.Fixtures;
Expand All @@ -38,6 +40,12 @@
import static org.assertj.core.api.Assertions.assertThat;

public class PrometheusExporterTest extends Fixtures {
private static void clear() {
for( Meter meter : Search.in( PrometheusExporter.prometheusRegistry ).meters() ) {
PrometheusExporter.prometheusRegistry.remove( meter );
}
}

@Test
public void server() throws IOException {
var port = Ports.getFreePort( getClass() );
Expand All @@ -58,19 +66,19 @@ public void server() throws IOException {
# TYPE test1_total counter
test1_total 2.0
""" );
assertThat( response ).contains( "test2_seconds_count 1.0" );
assertThat( response ).contains( "test2_seconds_count 1" );
assertThat( response ).contains( "test2_seconds_max 2.0" );
assertThat( response ).contains( "system_metrics_total 5.0" );
assertThat( response ).contains( "system_metrics 5" );
}
}

@AfterMethod
public void beforeMethod() {
PrometheusExporter.prometheusRegistry.getPrometheusRegistry().clear();
clear();
}

@AfterMethod
public void afterMethod() {
PrometheusExporter.prometheusRegistry.getPrometheusRegistry().clear();
clear();
}
}
4 changes: 2 additions & 2 deletions oap-storage/oap-storage-cloud-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<dependency>
<groupId>com.adobe.testing</groupId>
<artifactId>s3mock</artifactId>
<version>3.8.0</version>
<version>3.10.0</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
Expand All @@ -39,7 +39,7 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.12.671</version>
<version>1.12.772</version>
</dependency>

<dependency>
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>oap</groupId>
<artifactId>oap.maven</artifactId>
<version>22.0.0</version>
<version>22.0.5</version>
</parent>

<packaging>pom</packaging>
Expand All @@ -18,7 +18,7 @@
<dependency>
<groupId>oap</groupId>
<artifactId>oap-dependencies</artifactId>
<version>22.0.0</version>
<version>22.0.5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -70,7 +70,7 @@
</distributionManagement>

<properties>
<oap.project.version>22.4.18</oap.project.version>
<oap.project.version>22.4.19</oap.project.version>

<oap.deps.config.version>21.0.0</oap.deps.config.version>
<oap.deps.oap-teamcity.version>21.0.1</oap.deps.oap-teamcity.version>
Expand Down

0 comments on commit 3e88b08

Please sign in to comment.