jerqi commented on code in PR #9010:
URL: https://github.com/apache/gravitino/pull/9010#discussion_r2493538018


##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/metrics/JDBCMetricsStore.java:
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.iceberg.service.metrics;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.io.IOException;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.time.Instant;
+import java.util.Map;
+import java.util.function.Consumer;
+import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergPropertiesUtils;
+import org.apache.gravitino.json.JsonUtils;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.jdbc.JdbcClientPool;
+import org.apache.iceberg.jdbc.UncheckedInterruptedException;
+import org.apache.iceberg.jdbc.UncheckedSQLException;
+import org.apache.iceberg.metrics.CommitReport;
+import org.apache.iceberg.metrics.CounterResult;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.apache.iceberg.metrics.ScanReport;
+import org.apache.iceberg.metrics.TimerResult;
+
+public class JDBCMetricsStore implements IcebergMetricsStore {
+  public static final String ICEBERG_METRICS_STORE_JDBC_NAME = "jdbc";
+  private static final String URI = "uri";
+  private static final String INSERT_COMMIT_REPORT_METRICS_SQL =
+      "INSERT INTO commit_metrics_report ("
+          + "timestamp, namespace, table_name, snapshot_id, sequence_number, 
operation,"
+          + "added_data_files, removed_data_files, total_data_files,"
+          + "added_delete_files, added_equality_delete_files,  
added_positional_delete_files, "
+          + "removed_delete_files, removed_equality_delete_files, 
removed_positional_delete_files, total_delete_files,"
+          + "added_records, removed_records, total_records,"
+          + "added_file_size_bytes, removed_file_size_bytes, 
total_file_size_bytes,"
+          + "added_positional_deletes, removed_positional_deletes, 
total_positional_deletes,"
+          + "added_equality_deletes, removed_equality_deletes, 
total_equality_deletes,"
+          + "manifests_created, manifests_replaced, manifests_kept, 
manifest_entries_processed,"
+          + "added_dvs, removed_dvs,"
+          + "total_duration_ms, attempts, metadata"
+          + ") VALUES "
+          + "(?, ?, ?, ?, ?, ?,"
+          + " ?, ?, ?,"
+          + " ?, ?, ?,"
+          + " ?, ?, ?, ?,"
+          + " ?, ?, ?,"
+          + " ?, ?, ?,"
+          + " ?, ?, ?,"
+          + " ?, ?, ?,"
+          + " ?, ?, ?, ?,"
+          + " ?, ?,"
+          + " ?, ?, ?);";
+
+  private static final String INSERT_SCAN_REPORT_METRICS_SQL =
+      "INSERT INTO scan_metrics_report ("
+          + "timestamp, namespace, table_name, snapshot_id, schema_id, "
+          + "filter, metadata, projected_field_ids, projected_field_names, "
+          + "equality_delete_files, indexed_delete_files, 
positional_delete_files, "
+          + "result_data_files, result_delete_files, "
+          + "scanned_data_manifests, scanned_delete_manifests, "
+          + "skipped_data_files, skipped_data_manifests, "
+          + "skipped_delete_files, skipped_delete_manifests, "
+          + "total_data_manifests, total_delete_file_size_in_bytes, "
+          + "total_delete_manifests, total_file_size_in_bytes,"
+          + "total_planning_duration_ms) VALUES "
+          + "(?, ?, ?, ?, ?,"
+          + "?, ?, ?, ?,"
+          + "?, ? ,?,"
+          + "?, ?,"
+          + "?, ?,"
+          + "?, ?,"
+          + "?, ?,"
+          + "?, ?,"
+          + "?, ?,"
+          + "?);";
+
+  private static final String DELETE_EXPIRED_SCAN_METRICS_SQL =
+      "DELETE FROM scan_metrics_report WHERE timestamp < ?; ";
+
+  private static final String DELETE_EXPIRED_COMMIT_METRICS_SQL =
+      "DELETE FROM commit_metrics_report WHERE timestamp < ?;";
+
+  @VisibleForTesting JdbcClientPool connections;
+
+  @Override
+  public void init(Map<String, String> properties) throws IOException {
+    String uri = properties.get(URI);
+    Preconditions.checkArgument(uri != null, "JDBC metrics store requires a 
\"%s\" property", URI);
+
+    connections =
+        new JdbcClientPool(uri, 
IcebergPropertiesUtils.toIcebergCatalogProperties(properties));
+  }
+
+  @Override
+  public void recordMetric(Namespace namespace, MetricsReport metricsReport) 
throws IOException {

Review Comment:
   Yes, we should add it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to