Skip to content

Commit

Permalink
AWS, Dell, GCP: Skip stack trace log for missing Hadoop dependency (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanck authored Aug 21, 2023
1 parent 8367434 commit 1a2e334
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
12 changes: 7 additions & 5 deletions aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,21 +379,23 @@ public void initialize(Map<String, String> props) {
}
}

initMetrics(properties);
}

@SuppressWarnings("CatchBlockLogException")
private void initMetrics(Map<String, String> props) {
// Report Hadoop metrics if Hadoop is available
try {
DynConstructors.Ctor<MetricsContext> 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);
}
}

Expand Down
8 changes: 5 additions & 3 deletions dell/src/main/java/org/apache/iceberg/dell/ecs/EcsFileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ public void initialize(Map<String, String> properties) {
this.dellProperties = new DellProperties(properties);
this.dellClientFactory = DellClientFactories.from(properties);
this.s3 = dellClientFactory::ecsS3;
initMetrics(properties);
}

@SuppressWarnings("CatchBlockLogException")
private void initMetrics(Map<String, String> properties) {
// Report Hadoop metrics if Hadoop is available
try {
DynConstructors.Ctor<MetricsContext> ctor =
Expand All @@ -98,9 +102,7 @@ public void initialize(Map<String, String> 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);
}
}

Expand Down
35 changes: 19 additions & 16 deletions gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSFileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,27 @@ public void initialize(Map<String, String> props) {
builder.setCredentials(OAuth2Credentials.create(accessToken));
});

// Report Hadoop metrics if Hadoop is available
try {
DynConstructors.Ctor<MetricsContext> 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<String, String> props) {
// Report Hadoop metrics if Hadoop is available
try {
DynConstructors.Ctor<MetricsContext> 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
Expand Down

0 comments on commit 1a2e334

Please sign in to comment.