danielcweeks commented on code in PR #16235:
URL: https://github.com/apache/iceberg/pull/16235#discussion_r3470591143
##########
aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIOProperties.java:
##########
@@ -1197,4 +1209,63 @@ private <T> T loadSdkPluginConfigurations(String impl,
Map<String, String> prope
public Map<String, String> properties() {
return allProperties;
}
+
+ public String metricsPublisherImpl() {
+ return metricsPublisherImpl;
+ }
+
+ /**
+ * Configure a custom {@link MetricPublisher} for an S3 client.
+ *
+ * <p>Sample usage:
+ *
+ * <pre>
+ *
S3Client.builder().applyMutation(s3FileIOProperties::applyMetricsPublisherConfiguration)
+ * </pre>
+ */
+ public <T extends S3BaseClientBuilder<T, ?>> void
applyMetricsPublisherConfiguration(T builder) {
+ if (metricsPublisherImpl != null) {
+ ClientOverrideConfiguration.Builder configBuilder =
+ null != builder.overrideConfiguration()
+ ? builder.overrideConfiguration().toBuilder()
+ : ClientOverrideConfiguration.builder();
+ builder.overrideConfiguration(
+ configBuilder.addMetricPublisher(loadMetricPublisher()).build());
+ }
+ }
+
+ private MetricPublisher loadMetricPublisher() {
+ // Phase 1: look up the factory. A NoSuchMethodException here means the
class does not
+ // declare `create(Map)` — fall back to the no-arg constructor path. Any
OTHER exception
+ // from a factory that DOES exist (e.g. the factory itself throws) should
surface via the
+ // wrapping IllegalArgumentException in phase 2 so users can distinguish
"wrong signature"
+ // from "misconfigured factory".
+ DynMethods.StaticMethod factory = null;
+ try {
+ factory =
+ DynMethods.builder("create")
+ .hiddenImpl(metricsPublisherImpl, Map.class)
+ .buildStaticChecked();
Review Comment:
Also, the one that doesn't only exposes a builder pattern, so it looks like
you wouldn't be able to instantiate it through this mechanism (i.e.
`EmfMetricLoggingPublisher`)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]