From 1a2e334ca8a15dbf37f3f6944811d4c0ec7eb052 Mon Sep 17 00:00:00 2001 From: Bryan Keller Date: Mon, 21 Aug 2023 01:37:53 -0700 Subject: [PATCH] AWS, Dell, GCP: Skip stack trace log for missing Hadoop dependency (#8359) --- .../org/apache/iceberg/aws/s3/S3FileIO.java | 12 ++++--- .../apache/iceberg/dell/ecs/EcsFileIO.java | 8 +++-- .../org/apache/iceberg/gcp/gcs/GCSFileIO.java | 35 ++++++++++--------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java b/aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java index 9ba2f545b2eb..fa7590608880 100644 --- a/aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java +++ b/aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java @@ -379,21 +379,23 @@ public void initialize(Map props) { } } + initMetrics(properties); + } + + @SuppressWarnings("CatchBlockLogException") + private void initMetrics(Map props) { // Report Hadoop metrics if Hadoop is available try { DynConstructors.Ctor ctor = DynConstructors.builder(MetricsContext.class) - .loader(S3FileIO.class.getClassLoader()) .hiddenImpl(DEFAULT_METRICS_IMPL, String.class) .buildChecked(); MetricsContext context = ctor.newInstance("s3"); - context.initialize(properties); + context.initialize(props); this.metrics = context; } catch (NoClassDefFoundError | NoSuchMethodException | ClassCastException e) { LOG.warn( - "Unable to load metrics class: '{}', falling back to null metrics", - DEFAULT_METRICS_IMPL, - e); + "Unable to load metrics class: '{}', falling back to null metrics", DEFAULT_METRICS_IMPL); } } diff --git a/dell/src/main/java/org/apache/iceberg/dell/ecs/EcsFileIO.java b/dell/src/main/java/org/apache/iceberg/dell/ecs/EcsFileIO.java index 54b11e8b3790..687d848ce06a 100644 --- a/dell/src/main/java/org/apache/iceberg/dell/ecs/EcsFileIO.java +++ b/dell/src/main/java/org/apache/iceberg/dell/ecs/EcsFileIO.java @@ -86,7 +86,11 @@ public void initialize(Map properties) { this.dellProperties = new DellProperties(properties); this.dellClientFactory = DellClientFactories.from(properties); this.s3 = dellClientFactory::ecsS3; + initMetrics(properties); + } + @SuppressWarnings("CatchBlockLogException") + private void initMetrics(Map properties) { // Report Hadoop metrics if Hadoop is available try { DynConstructors.Ctor ctor = @@ -98,9 +102,7 @@ public void initialize(Map properties) { this.metrics = context; } catch (NoClassDefFoundError | NoSuchMethodException | ClassCastException e) { LOG.warn( - "Unable to load metrics class: '{}', falling back to null metrics", - DEFAULT_METRICS_IMPL, - e); + "Unable to load metrics class: '{}', falling back to null metrics", DEFAULT_METRICS_IMPL); } } diff --git a/gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSFileIO.java b/gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSFileIO.java index 1c99bd78f20d..1e164f059dad 100644 --- a/gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSFileIO.java +++ b/gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSFileIO.java @@ -152,24 +152,27 @@ public void initialize(Map props) { builder.setCredentials(OAuth2Credentials.create(accessToken)); }); - // Report Hadoop metrics if Hadoop is available - try { - DynConstructors.Ctor ctor = - DynConstructors.builder(MetricsContext.class) - .hiddenImpl(DEFAULT_METRICS_IMPL, String.class) - .buildChecked(); - MetricsContext context = ctor.newInstance("gcs"); - context.initialize(properties); - this.metrics = context; - } catch (NoClassDefFoundError | NoSuchMethodException | ClassCastException e) { - LOG.warn( - "Unable to load metrics class: '{}', falling back to null metrics", - DEFAULT_METRICS_IMPL, - e); - } - return builder.build().getService(); }; + + initMetrics(properties); + } + + @SuppressWarnings("CatchBlockLogException") + private void initMetrics(Map props) { + // Report Hadoop metrics if Hadoop is available + try { + DynConstructors.Ctor ctor = + DynConstructors.builder(MetricsContext.class) + .hiddenImpl(DEFAULT_METRICS_IMPL, String.class) + .buildChecked(); + MetricsContext context = ctor.newInstance("gcs"); + context.initialize(props); + this.metrics = context; + } catch (NoClassDefFoundError | NoSuchMethodException | ClassCastException e) { + LOG.warn( + "Unable to load metrics class: '{}', falling back to null metrics", DEFAULT_METRICS_IMPL); + } } @Override