-
Notifications
You must be signed in to change notification settings - Fork 1k
Implement Library Instrumentation for Apache Iceberg #15114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ghareeb-falazi
wants to merge
49
commits into
open-telemetry:main
Choose a base branch
from
ghareeb-falazi:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 23 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
66dfb39
create project skeleton
ghareeb-falazi cfa5695
import correct iceberg library
ghareeb-falazi caca4af
initial ScanMetrics builders implementation
ghareeb-falazi e56fb2e
apply spotless
ghareeb-falazi b200b65
Merge branch 'open-telemetry:main' into main
ghareeb-falazi d900bd4
update iceberg version
ghareeb-falazi 1359cf5
Merge branch 'open-telemetry:main' into main
ghareeb-falazi ad6c673
fix some build issues
ghareeb-falazi c5ca17e
Merge branch 'main' of github.com:ghareeb-falazi/opentelemetry-java-i…
ghareeb-falazi 5d94635
Convert DoubleGauge to LongGauge
ghareeb-falazi b8acfe8
Convert LongGauge to LongCounter
ghareeb-falazi 77dd606
add attributes to scan metrics
ghareeb-falazi b7a4b5d
create commit metrics builder
ghareeb-falazi 98ee412
Finalize IcebergMetricsReporter implementation
ghareeb-falazi b912f8f
initial testing implementation
ghareeb-falazi 9498d36
finish implementing unit test
ghareeb-falazi a35cf9e
remove commit metrics
ghareeb-falazi 716ae50
Merge branch 'open-telemetry:main' into main
ghareeb-falazi 6a74905
Merge branch 'main' of github.com:ghareeb-falazi/opentelemetry-java-i…
ghareeb-falazi 920dd26
Fix style issue
ghareeb-falazi 6a758b7
reorder imports
ghareeb-falazi a42c03e
make only class in testing project public to pass javadoc task
ghareeb-falazi 061f58f
set minJavaVersionSupported to 11 since this is required by the Icebe…
ghareeb-falazi e672e3b
Apply suggestions from code review
ghareeb-falazi af1dd70
apply suggestions from code review
ghareeb-falazi 570aa7c
Merge branch 'main' of github.com:ghareeb-falazi/opentelemetry-java-i…
ghareeb-falazi 8d975b9
reorder imports
ghareeb-falazi 93d9380
Merge branch 'main' into main
ghareeb-falazi e64d52d
Merge branch 'main' into main
ghareeb-falazi 1dd3179
Merge branch 'main' into main
ghareeb-falazi 62b4f02
Merge branch 'main' into main
ghareeb-falazi e9aeabe
apply review comments
ghareeb-falazi 2bcd4bc
Merge branch 'main' into main
ghareeb-falazi daba240
Merge branch 'main' into main
ghareeb-falazi 65aaf61
Merge branch 'main' into main
ghareeb-falazi ef2ae85
Merge branch 'main' into main
ghareeb-falazi 6f8e403
merge metrics
ghareeb-falazi 088e2dd
adapt unit tests to new metrics
ghareeb-falazi 2cb4f4f
Merge branch 'main' into main
ghareeb-falazi ea200d3
limit java version for tests to 17 to allow hadoop to run
ghareeb-falazi 978aa55
Merge branch 'main' of github.com:ghareeb-falazi/opentelemetry-java-i…
ghareeb-falazi d7f72ef
add javadocs to the public class
ghareeb-falazi f5d96e3
apply advice to exclude snapshot_id attribute
ghareeb-falazi 90f5047
try unit tests with java 21
ghareeb-falazi 752cf4b
Merge branch 'main' into main
ghareeb-falazi 0b0a161
revert to using iceberg's TestTables in unit tests to ensure we can t…
ghareeb-falazi 308f819
Merge branch 'main' into main
ghareeb-falazi b6ee75e
Merge branch 'main' into main
ghareeb-falazi aee6f7b
Update comment in instrumentation/iceberg-1.8/testing/build.gradle.kts
ghareeb-falazi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Library Instrumentation for Apache Iceberg Version 1.8 and Higher | ||
|
|
||
| Provides OpenTelemetry instrumentation for [Apache Iceberg](https://iceberg.apache.org/). | ||
|
|
||
| ## Quickstart | ||
|
|
||
| ### Add These Dependencies to Your Project | ||
|
|
||
| Replace `OPENTELEMETRY_VERSION` with the [latest release](https://central.sonatype.com/artifact/io.opentelemetry.instrumentation/opentelemetry-iceberg-1.8). | ||
|
|
||
| For Maven, add to your `pom.xml` dependencies: | ||
|
|
||
| ```xml | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>io.opentelemetry.instrumentation</groupId> | ||
| <artifactId>opentelemetry-iceberg-1.8</artifactId> | ||
| <version>OPENTELEMETRY_VERSION</version> | ||
| </dependency> | ||
| </dependencies> | ||
| ``` | ||
|
|
||
| For Gradle, add to your dependencies: | ||
|
|
||
| ```groovy | ||
| implementation("io.opentelemetry.instrumentation:opentelemetry-iceberg-1.8:OPENTELEMETRY_VERSION") | ||
| ``` | ||
|
|
||
| ### Usage | ||
|
|
||
| The instrumentation library allows creating instrumented `Scan` (e.g., `TableScan`) instances for collecting and reporting OpenTelemetry-based sacn metrics. For example: | ||
|
|
||
| ```java | ||
| OpenTelemetry openTelemetry = // ... | ||
| IcebergTelemetry icebergTelemetry = IcebergTelemetry.create(openTelemetry); | ||
| TableScan tableScan = icebergTelemetry.wrapScan(table.newScan()); | ||
|
|
||
| try (CloseableIterable<FileScanTask> fileScanTasks = tableScan.planFiles()) { | ||
| // Process the scan tasks | ||
| } | ||
|
|
||
| // The metrics will be reported after the scan tasks iterable is closed | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| plugins { | ||
| id("otel.library-instrumentation") | ||
| id("otel.nullaway-conventions") | ||
| } | ||
|
|
||
| dependencies { | ||
| library("org.apache.iceberg:iceberg-core:1.8.1") | ||
| testImplementation(project(":instrumentation:iceberg-1.8:testing")) | ||
| } | ||
|
|
||
| otelJava { | ||
| minJavaVersionSupported.set(JavaVersion.VERSION_11) | ||
| } |
194 changes: 194 additions & 0 deletions
194
...y/src/main/java/io/opentelemetry/instrumentation/iceberg/v1_8/IcebergMetricsReporter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.iceberg.v1_8; | ||
|
|
||
| import io.opentelemetry.api.OpenTelemetry; | ||
| import io.opentelemetry.api.common.AttributeKey; | ||
| import io.opentelemetry.api.common.Attributes; | ||
| import io.opentelemetry.api.metrics.LongCounter; | ||
| import io.opentelemetry.api.metrics.LongGauge; | ||
| import java.util.Locale; | ||
| import org.apache.iceberg.metrics.CounterResult; | ||
| import org.apache.iceberg.metrics.MetricsReport; | ||
| import org.apache.iceberg.metrics.MetricsReporter; | ||
| import org.apache.iceberg.metrics.ScanMetricsResult; | ||
| import org.apache.iceberg.metrics.ScanReport; | ||
| import org.apache.iceberg.metrics.TimerResult; | ||
|
|
||
| public class IcebergMetricsReporter implements MetricsReporter { | ||
ghareeb-falazi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private static final String INSTRUMENTATION_NAME = "io.opentelemetry.iceberg_1.8"; | ||
ghareeb-falazi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private static final AttributeKey<Long> SCHEMA_ID = AttributeKey.longKey("iceberg.schema.id"); | ||
| private static final AttributeKey<String> TABLE_NAME = | ||
| AttributeKey.stringKey("iceberg.table.name"); | ||
| private static final AttributeKey<Long> SNAPHSOT_ID = AttributeKey.longKey("iceberg.snapshot.id"); | ||
ghareeb-falazi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ghareeb-falazi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private final OpenTelemetry openTelemetry; | ||
|
|
||
| IcebergMetricsReporter(OpenTelemetry openTelemetry) { | ||
| this.openTelemetry = openTelemetry; | ||
| } | ||
|
|
||
| @Override | ||
| public void report(MetricsReport report) { | ||
| if (report instanceof ScanReport) { | ||
| reportScanMetrics((ScanReport) report); | ||
| } | ||
| } | ||
|
|
||
| void reportScanMetrics(ScanReport scanReport) { | ||
| Attributes scanAttributes = | ||
| Attributes.of( | ||
| SCHEMA_ID, | ||
| Long.valueOf(scanReport.schemaId()), | ||
| TABLE_NAME, | ||
| scanReport.tableName(), | ||
| SNAPHSOT_ID, | ||
| scanReport.snapshotId()); | ||
| ScanMetricsResult metrics = scanReport.scanMetrics(); | ||
| TimerResult duration = metrics.totalPlanningDuration(); | ||
|
|
||
| if (duration != null) { | ||
| LongGauge metric = | ||
| ScanMetricsBuilder.totalPlanningDuration( | ||
| openTelemetry.getMeter(INSTRUMENTATION_NAME), | ||
| duration.timeUnit().name().toLowerCase(Locale.getDefault())); | ||
ghareeb-falazi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| metric.set(duration.totalDuration().toMillis(), scanAttributes); | ||
| } | ||
|
|
||
| CounterResult current = metrics.resultDataFiles(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.scannedDataFilesCount(openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
|
|
||
| current = metrics.resultDeleteFiles(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.scannedDeleteFilesCount(openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
|
|
||
| current = metrics.scannedDataManifests(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.scannedDataManifestsCount( | ||
| openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
|
|
||
| current = metrics.scannedDeleteManifests(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.scannedDeleteManifestsCount( | ||
| openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
|
|
||
| current = metrics.totalDataManifests(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.totalDataManifestsCount(openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
|
|
||
| current = metrics.totalDeleteManifests(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.totalDeleteManifestsCount( | ||
| openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
|
|
||
| current = metrics.totalFileSizeInBytes(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.scannedDataFilesSize(openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
|
|
||
| current = metrics.totalDeleteFileSizeInBytes(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.scannedDeleteFilesSize(openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
|
|
||
| current = metrics.skippedDataManifests(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.skippedDataManifestsCount( | ||
| openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
|
|
||
| current = metrics.skippedDeleteManifests(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.skippedDeleteManifestsCount( | ||
| openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
|
|
||
| current = metrics.skippedDataFiles(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.skippedDataFilesCount(openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
|
|
||
| current = metrics.skippedDeleteFiles(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.skippedDeleteFilesCount(openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
|
|
||
| current = metrics.indexedDeleteFiles(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.indexedDeleteFilesCount(openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
|
|
||
| current = metrics.equalityDeleteFiles(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.equalityDeleteFilesCount(openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
|
|
||
| current = metrics.positionalDeleteFiles(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.positionDeleteFilesCount(openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
|
|
||
| current = metrics.dvs(); | ||
|
|
||
| if (current != null) { | ||
| LongCounter metric = | ||
| ScanMetricsBuilder.deletionVectorFilesCount(openTelemetry.getMeter(INSTRUMENTATION_NAME)); | ||
| metric.add(current.value(), scanAttributes); | ||
| } | ||
| } | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
...library/src/main/java/io/opentelemetry/instrumentation/iceberg/v1_8/IcebergTelemetry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.iceberg.v1_8; | ||
|
|
||
| import io.opentelemetry.api.OpenTelemetry; | ||
| import org.apache.iceberg.Scan; | ||
| import org.apache.iceberg.ScanTask; | ||
| import org.apache.iceberg.ScanTaskGroup; | ||
|
|
||
| public class IcebergTelemetry { | ||
ghareeb-falazi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private final OpenTelemetry openTelemetry; | ||
|
|
||
| public static IcebergTelemetry create(OpenTelemetry openTelemetry) { | ||
| return new IcebergTelemetry(openTelemetry); | ||
| } | ||
|
|
||
| IcebergTelemetry(OpenTelemetry openTelemetry) { | ||
| this.openTelemetry = openTelemetry; | ||
| } | ||
|
|
||
| public <T1, T2 extends ScanTask, T3 extends ScanTaskGroup<T2>> T1 wrapScan( | ||
| Scan<T1, T2, T3> scan) { | ||
| return scan.metricsReporter(new IcebergMetricsReporter(openTelemetry)); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.