This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
The following commit(s) were added to refs/heads/master by this push:
new a4df042deb [S3 Metrics] Allow to customize S3 metrics prefix
a4df042deb is described below
commit a4df042deb8ece3fe8ca2fa8330f70b7083854a2
Author: Quan Tran <[email protected]>
AuthorDate: Tue Oct 15 10:45:13 2024 +0700
[S3 Metrics] Allow to customize S3 metrics prefix
---
.../blob/objectstorage/aws/JamesS3MetricPublisher.java | 15 +++++++++------
.../james/blob/objectstorage/aws/S3ClientFactory.java | 9 ++++++++-
.../james/blob/objectstorage/aws/S3BlobStoreDAOTest.java | 4 +++-
3 files changed, 20 insertions(+), 8 deletions(-)
diff --git
a/server/blob/blob-s3/src/main/java/org/apache/james/blob/objectstorage/aws/JamesS3MetricPublisher.java
b/server/blob/blob-s3/src/main/java/org/apache/james/blob/objectstorage/aws/JamesS3MetricPublisher.java
index 095acc2c7c..3e43845635 100644
---
a/server/blob/blob-s3/src/main/java/org/apache/james/blob/objectstorage/aws/JamesS3MetricPublisher.java
+++
b/server/blob/blob-s3/src/main/java/org/apache/james/blob/objectstorage/aws/JamesS3MetricPublisher.java
@@ -35,18 +35,21 @@ import software.amazon.awssdk.metrics.MetricCollection;
import software.amazon.awssdk.metrics.MetricPublisher;
public class JamesS3MetricPublisher implements MetricPublisher {
+ public static final String DEFAULT_S3_METRICS_PREFIX = "s3";
+
private final GaugeRegistry.SettableGauge<Integer> availableConcurrency;
// The number of remaining concurrent requests that can be supported by the
HTTP client without needing to establish another connection.
private final GaugeRegistry.SettableGauge<Integer> leasedConcurrency; //
The number of request currently being executed by the HTTP client.
private final GaugeRegistry.SettableGauge<Integer>
pendingConcurrencyAcquires; // The number of requests that are blocked, waiting
for another TCP connection or a new stream to be available from the connection
pool.
private final TimeMetric concurrencyAcquireDuration; // The time taken to
acquire a channel from the connection pool.
private final TimeMetric apiCallDuration; // The total time taken to
finish a request (inclusive of all retries).
- public JamesS3MetricPublisher(MetricFactory metricFactory, GaugeRegistry
gaugeRegistry) {
- this.availableConcurrency =
gaugeRegistry.settableGauge("s3_httpClient_availableConcurrency");
- this.leasedConcurrency =
gaugeRegistry.settableGauge("s3_httpClient_leasedConcurrency");
- this.pendingConcurrencyAcquires =
gaugeRegistry.settableGauge("s3_httpClient_pendingConcurrencyAcquires");
- this.concurrencyAcquireDuration =
metricFactory.timer("s3_httpClient_concurrencyAcquireDuration");
- this.apiCallDuration =
metricFactory.timer("s3_apiCall_apiCallDuration");
+ public JamesS3MetricPublisher(MetricFactory metricFactory, GaugeRegistry
gaugeRegistry,
+ String metricPrefix) {
+ this.availableConcurrency = gaugeRegistry.settableGauge(metricPrefix +
"_httpClient_availableConcurrency");
+ this.leasedConcurrency = gaugeRegistry.settableGauge(metricPrefix +
"_httpClient_leasedConcurrency");
+ this.pendingConcurrencyAcquires =
gaugeRegistry.settableGauge(metricPrefix +
"_httpClient_pendingConcurrencyAcquires");
+ this.concurrencyAcquireDuration = metricFactory.timer(metricPrefix +
"_httpClient_concurrencyAcquireDuration");
+ this.apiCallDuration = metricFactory.timer(metricPrefix +
"_apiCall_apiCallDuration");
}
@Override
diff --git
a/server/blob/blob-s3/src/main/java/org/apache/james/blob/objectstorage/aws/S3ClientFactory.java
b/server/blob/blob-s3/src/main/java/org/apache/james/blob/objectstorage/aws/S3ClientFactory.java
index f635fcd608..ef3f32f2fd 100644
---
a/server/blob/blob-s3/src/main/java/org/apache/james/blob/objectstorage/aws/S3ClientFactory.java
+++
b/server/blob/blob-s3/src/main/java/org/apache/james/blob/objectstorage/aws/S3ClientFactory.java
@@ -19,6 +19,8 @@
package org.apache.james.blob.objectstorage.aws;
+import static
org.apache.james.blob.objectstorage.aws.JamesS3MetricPublisher.DEFAULT_S3_METRICS_PREFIX;
+
import java.io.Closeable;
import java.io.FileInputStream;
import java.io.IOException;
@@ -32,6 +34,7 @@ import javax.net.ssl.X509TrustManager;
import jakarta.annotation.PreDestroy;
import jakarta.inject.Inject;
+import jakarta.inject.Provider;
import jakarta.inject.Singleton;
import org.apache.james.lifecycle.api.Startable;
@@ -67,13 +70,17 @@ public class S3ClientFactory implements Startable,
Closeable {
public static final String S3_METRICS_ENABLED_PROPERTY_KEY =
"james.s3.metrics.enabled";
public static final String S3_METRICS_ENABLED_DEFAULT_VALUE = "true";
+ public static final String S3_METRICS_PREFIX =
System.getProperty("james.s3.metrics.prefix", DEFAULT_S3_METRICS_PREFIX);
private final S3AsyncClient s3Client;
@Inject
@Singleton
public S3ClientFactory(S3BlobStoreConfiguration configuration,
MetricFactory metricFactory, GaugeRegistry gaugeRegistry) {
+ this(configuration, () -> new JamesS3MetricPublisher(metricFactory,
gaugeRegistry, S3_METRICS_PREFIX));
+ }
+ public S3ClientFactory(S3BlobStoreConfiguration configuration,
Provider<JamesS3MetricPublisher> jamesS3MetricPublisherProvider) {
AwsS3AuthConfiguration authConfiguration =
configuration.getSpecificAuthConfiguration();
S3Configuration pathStyleAccess = S3Configuration.builder()
.pathStyleAccessEnabled(true)
@@ -89,7 +96,7 @@ public class S3ClientFactory implements Startable, Closeable {
.overrideConfiguration(builder -> {
boolean s3MetricsEnabled =
Boolean.parseBoolean(System.getProperty(S3_METRICS_ENABLED_PROPERTY_KEY,
S3_METRICS_ENABLED_DEFAULT_VALUE));
if (s3MetricsEnabled) {
- builder.addMetricPublisher(new
JamesS3MetricPublisher(metricFactory, gaugeRegistry));
+
builder.addMetricPublisher(jamesS3MetricPublisherProvider.get());
}
})
.build();
diff --git
a/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3BlobStoreDAOTest.java
b/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3BlobStoreDAOTest.java
index b852ca25ac..bca00dd75e 100644
---
a/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3BlobStoreDAOTest.java
+++
b/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3BlobStoreDAOTest.java
@@ -20,6 +20,7 @@ package org.apache.james.blob.objectstorage.aws;
import static org.apache.james.blob.api.BlobStoreDAOFixture.ELEVEN_KILOBYTES;
import static org.apache.james.blob.api.BlobStoreDAOFixture.TEST_BUCKET_NAME;
+import static
org.apache.james.blob.objectstorage.aws.JamesS3MetricPublisher.DEFAULT_S3_METRICS_PREFIX;
import static
org.apache.james.blob.objectstorage.aws.S3BlobStoreConfiguration.UPLOAD_RETRY_EXCEPTION_PREDICATE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
@@ -66,7 +67,8 @@ public class S3BlobStoreDAOTest implements
BlobStoreDAOContract {
.filter(UPLOAD_RETRY_EXCEPTION_PREDICATE)))
.build();
- s3ClientFactory = new S3ClientFactory(s3Configuration, new
RecordingMetricFactory(), new NoopGaugeRegistry());
+ s3ClientFactory = new S3ClientFactory(s3Configuration, () -> new
JamesS3MetricPublisher(new RecordingMetricFactory(), new NoopGaugeRegistry(),
+ DEFAULT_S3_METRICS_PREFIX));
testee = new S3BlobStoreDAO(s3ClientFactory, s3Configuration, new
TestBlobId.Factory());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]