From de1f23d9d9fa391f24b3198d1ed6685e5d3700af Mon Sep 17 00:00:00 2001 From: david-leifker <114954101+david-leifker@users.noreply.github.com> Date: Mon, 31 Jul 2023 09:10:40 -0500 Subject: [PATCH] feat(metrics): add metrics for aspect write and bytes (#8526) --- .../com/linkedin/metadata/entity/AspectDao.java | 10 ++++++++++ .../metadata/entity/EntityServiceImpl.java | 17 +++++++++++++++-- .../entity/cassandra/CassandraAspectDao.java | 4 ++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/metadata-io/src/main/java/com/linkedin/metadata/entity/AspectDao.java b/metadata-io/src/main/java/com/linkedin/metadata/entity/AspectDao.java index bf74b1025267f..9967df9207ec7 100644 --- a/metadata-io/src/main/java/com/linkedin/metadata/entity/AspectDao.java +++ b/metadata-io/src/main/java/com/linkedin/metadata/entity/AspectDao.java @@ -3,6 +3,7 @@ import com.linkedin.common.urn.Urn; import com.linkedin.metadata.entity.ebean.EbeanAspectV2; import com.linkedin.metadata.entity.restoreindices.RestoreIndicesArgs; +import com.linkedin.metadata.utils.metrics.MetricUtils; import io.ebean.PagedList; import javax.annotation.Nonnull; @@ -28,6 +29,8 @@ * worth looking into ways to move this responsibility inside {@link AspectDao} implementations. */ public interface AspectDao { + String ASPECT_WRITE_COUNT_METRIC_NAME = "aspectWriteCount"; + String ASPECT_WRITE_BYTES_METRIC_NAME = "aspectWriteBytes"; @Nullable EntityAspect getAspect(@Nonnull final String urn, @Nonnull final String aspectName, final long version); @@ -116,4 +119,11 @@ ListResult listAspectMetadata( @Nonnull T runInTransactionWithRetry(@Nonnull final Supplier block, final int maxTransactionRetry); + + default void incrementWriteMetrics(String aspectName, long count, long bytes) { + MetricUtils.counter(this.getClass(), + String.join(MetricUtils.DELIMITER, List.of(ASPECT_WRITE_COUNT_METRIC_NAME, aspectName))).inc(count); + MetricUtils.counter(this.getClass(), + String.join(MetricUtils.DELIMITER, List.of(ASPECT_WRITE_BYTES_METRIC_NAME, aspectName))).inc(bytes); + } } diff --git a/metadata-io/src/main/java/com/linkedin/metadata/entity/EntityServiceImpl.java b/metadata-io/src/main/java/com/linkedin/metadata/entity/EntityServiceImpl.java index c7a9895992d90..e070944b49a05 100644 --- a/metadata-io/src/main/java/com/linkedin/metadata/entity/EntityServiceImpl.java +++ b/metadata-io/src/main/java/com/linkedin/metadata/entity/EntityServiceImpl.java @@ -1811,6 +1811,8 @@ public RollbackResult deleteAspect(String urn, String aspectName, @Nonnull Map