Skip to content

Commit

Permalink
FileIO: Handle null metrics fallback for MetricsContext (apache#4500)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajarshisarkar authored Apr 13, 2022
1 parent 014eb78 commit a6a4237
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ public void initialize(Map<String, String> properties) {
try {
DynConstructors.Ctor<MetricsContext> ctor =
DynConstructors.builder(MetricsContext.class).hiddenImpl(DEFAULT_METRICS_IMPL, String.class).buildChecked();
this.metrics = ctor.newInstance("oss");

metrics.initialize(properties);
} catch (NoSuchMethodException | ClassCastException e) {
MetricsContext context = ctor.newInstance("oss");
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);
}
}
Expand Down
8 changes: 4 additions & 4 deletions aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ public void initialize(Map<String, String> properties) {
try {
DynConstructors.Ctor<MetricsContext> ctor =
DynConstructors.builder(MetricsContext.class).hiddenImpl(DEFAULT_METRICS_IMPL, String.class).buildChecked();
this.metrics = ctor.newInstance("s3");

metrics.initialize(properties);
} catch (NoSuchMethodException | ClassCastException e) {
MetricsContext context = ctor.newInstance("s3");
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);
}
}
Expand Down
7 changes: 3 additions & 4 deletions dell/src/main/java/org/apache/iceberg/dell/ecs/EcsFileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ public void initialize(Map<String, String> properties) {
try {
DynConstructors.Ctor<MetricsContext> ctor =
DynConstructors.builder(MetricsContext.class).hiddenImpl(DEFAULT_METRICS_IMPL, String.class).buildChecked();
this.metrics = ctor.newInstance("ecs");

metrics.initialize(properties);
MetricsContext context = ctor.newInstance("ecs");
context.initialize(properties);
this.metrics = context;
} catch (NoClassDefFoundError | NoSuchMethodException | ClassCastException e) {
this.metrics = MetricsContext.nullMetrics();
LOG.warn("Unable to load metrics class: '{}', falling back to null metrics", DEFAULT_METRICS_IMPL, e);
}
}
Expand Down
8 changes: 4 additions & 4 deletions gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSFileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ public void initialize(Map<String, String> properties) {
try {
DynConstructors.Ctor<MetricsContext> ctor =
DynConstructors.builder(MetricsContext.class).hiddenImpl(DEFAULT_METRICS_IMPL, String.class).buildChecked();
this.metrics = ctor.newInstance("gcs");

metrics.initialize(properties);
} catch (NoSuchMethodException | ClassCastException e) {
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);
}

Expand Down

0 comments on commit a6a4237

Please sign in to comment.