From bef9a8b4f2a791bec6e0cf4ebda3e713796e4997 Mon Sep 17 00:00:00 2001 From: fanng Date: Mon, 25 Sep 2023 19:30:23 +0800 Subject: [PATCH] add metrics --- .../web/rest/IcebergTableOperations.java | 11 ++++++++ .../iceberg/web/rest/IcebergRestTestUtil.java | 1 + .../iceberg/web/rest/IcebergTestBase.java | 8 ++++++ .../web/rest/TestIcebergTableOperations.java | 27 +++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/catalogs/catalog-lakehouse/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/IcebergTableOperations.java b/catalogs/catalog-lakehouse/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/IcebergTableOperations.java index a27685ba536..c6d47b9c3b9 100644 --- a/catalogs/catalog-lakehouse/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/IcebergTableOperations.java +++ b/catalogs/catalog-lakehouse/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/IcebergTableOperations.java @@ -24,6 +24,7 @@ import org.apache.iceberg.catalog.TableIdentifier; import org.apache.iceberg.rest.RESTUtil; import org.apache.iceberg.rest.requests.CreateTableRequest; +import org.apache.iceberg.rest.requests.ReportMetricsRequest; import org.apache.iceberg.rest.requests.UpdateTableRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -127,4 +128,14 @@ public Response tableExists( return IcebergRestUtils.notExists(); } } + + @POST + @Path("{table}/metrics") + @Produces(MediaType.APPLICATION_JSON) + public Response reportTableMetrics( + @PathParam("namespace") String namespace, + @PathParam("table") String table, + ReportMetricsRequest request) { + return IcebergRestUtils.noContent(); + } } diff --git a/catalogs/catalog-lakehouse/src/test/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/IcebergRestTestUtil.java b/catalogs/catalog-lakehouse/src/test/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/IcebergRestTestUtil.java index 9ddc4f9a149..d9955b88184 100644 --- a/catalogs/catalog-lakehouse/src/test/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/IcebergRestTestUtil.java +++ b/catalogs/catalog-lakehouse/src/test/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/IcebergRestTestUtil.java @@ -26,6 +26,7 @@ public class IcebergRestTestUtil { public static final String TEST_NAMESPACE_NAME = "graviton-test"; public static final String TABLE_PATH = NAMESPACE_PATH + "/" + TEST_NAMESPACE_NAME + "/tables"; public static final String RENAME_TABLE_PATH = V_1 + "/tables/rename"; + public static final String REPORT_METRICS_POSTFIX = "metrics"; public static final boolean DEBUG_SERVER_LOG_ENABLED = true; diff --git a/catalogs/catalog-lakehouse/src/test/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/IcebergTestBase.java b/catalogs/catalog-lakehouse/src/test/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/IcebergTestBase.java index d7e82ca247a..f560c940973 100644 --- a/catalogs/catalog-lakehouse/src/test/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/IcebergTestBase.java +++ b/catalogs/catalog-lakehouse/src/test/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/IcebergTestBase.java @@ -51,6 +51,14 @@ public Builder getTableClientBuilder(Optional name) { return getIcebergClientBuilder(path, Optional.empty()); } + public Builder getReportMetricsClientBuilder(String name) { + String path = + Joiner.on("/") + .skipNulls() + .join(IcebergRestTestUtil.TABLE_PATH, name, IcebergRestTestUtil.REPORT_METRICS_POSTFIX); + return getIcebergClientBuilder(path, Optional.empty()); + } + public Builder getNamespaceClientBuilder() { return getNamespaceClientBuilder(Optional.empty(), Optional.empty()); } diff --git a/catalogs/catalog-lakehouse/src/test/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/TestIcebergTableOperations.java b/catalogs/catalog-lakehouse/src/test/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/TestIcebergTableOperations.java index dafab8ad89d..bd68e7d2c33 100644 --- a/catalogs/catalog-lakehouse/src/test/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/TestIcebergTableOperations.java +++ b/catalogs/catalog-lakehouse/src/test/java/com/datastrato/graviton/catalog/lakehouse/iceberg/web/rest/TestIcebergTableOperations.java @@ -21,8 +21,12 @@ import org.apache.iceberg.TableMetadata; import org.apache.iceberg.catalog.Namespace; import org.apache.iceberg.catalog.TableIdentifier; +import org.apache.iceberg.metrics.CommitReport; +import org.apache.iceberg.metrics.ImmutableCommitMetricsResult; +import org.apache.iceberg.metrics.ImmutableCommitReport; import org.apache.iceberg.rest.requests.CreateTableRequest; import org.apache.iceberg.rest.requests.RenameTableRequest; +import org.apache.iceberg.rest.requests.ReportMetricsRequest; import org.apache.iceberg.rest.requests.UpdateTableRequest; import org.apache.iceberg.rest.responses.ListTablesResponse; import org.apache.iceberg.rest.responses.LoadTableResponse; @@ -284,4 +288,27 @@ void testRenameTable(boolean withPrefix) { verifyCreateTableSucc("rename_foo3"); verifyRenameTableFail("rename_foo2", "rename_foo3", 409); } + + @Test + void testReportTableMetrics() { + + verifyCreateNamespaceSucc(IcebergRestTestUtil.TEST_NAMESPACE_NAME); + verifyCreateTableSucc("metrics_foo1"); + + ImmutableCommitMetricsResult commitMetrics = ImmutableCommitMetricsResult.builder().build(); + CommitReport commitReport = + ImmutableCommitReport.builder() + .tableName("metrics_foo1") + .snapshotId(-1) + .sequenceNumber(-1) + .operation("append") + .commitMetrics(commitMetrics) + .build(); + ReportMetricsRequest request = ReportMetricsRequest.of(commitReport); + Response response = + getReportMetricsClientBuilder("metrics_foo1") + .post(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE)); + + Assertions.assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus()); + } }