diff --git a/serving/src/main/java/feast/serving/service/OnlineServingServiceV2.java b/serving/src/main/java/feast/serving/service/OnlineServingServiceV2.java index a78a94ab00..748b587e8f 100644 --- a/serving/src/main/java/feast/serving/service/OnlineServingServiceV2.java +++ b/serving/src/main/java/feast/serving/service/OnlineServingServiceV2.java @@ -16,6 +16,8 @@ */ package feast.serving.service; +import static feast.common.models.FeatureTable.getFeatureTableStringRef; + import com.google.protobuf.Duration; import feast.common.models.FeatureV2; import feast.proto.core.FeatureProto; @@ -162,6 +164,7 @@ public GetOnlineFeaturesResponse getOnlineFeatures(GetOnlineFeaturesRequestV2 re entityValuesMap.get(entityRow).putAll(allValueMaps); entityStatusesMap.get(entityRow).putAll(allStatusMaps); } + populateHistogramMetrics(entityRows, featureReferences, projectName); // Build response field values from entityValuesMap and entityStatusesMap // Response field values should be in the same order as the entityRows provided by the user. @@ -295,6 +298,30 @@ private static boolean checkOutsideMaxAge( return timeDifference > maxAge.getSeconds(); } + /** + * Populate histogram metrics that can be used for analysing online retrieval calls + * + * @param entityRows entity rows provided in request + * @param featureReferences feature references provided in request + * @param project project name provided in request + */ + private void populateHistogramMetrics( + List entityRows, + List featureReferences, + String project) { + Metrics.requestEntityCount.labels(project).observe(Double.valueOf(entityRows.size())); + Metrics.requestFeatureCount.labels(project).observe(Double.valueOf(featureReferences.size())); + + long countDistinctFeatureTables = + featureReferences.stream() + .map(featureReference -> getFeatureTableStringRef(project, featureReference)) + .distinct() + .count(); + Metrics.requestFeatureTableCount + .labels(project) + .observe(Double.valueOf(countDistinctFeatureTables)); + } + /** * Populate count metrics that can be used for analysing online retrieval calls * diff --git a/serving/src/main/java/feast/serving/util/Metrics.java b/serving/src/main/java/feast/serving/util/Metrics.java index 13cbe0e1cc..8879531840 100644 --- a/serving/src/main/java/feast/serving/util/Metrics.java +++ b/serving/src/main/java/feast/serving/util/Metrics.java @@ -29,12 +29,31 @@ public class Metrics { .labelNames("method") .register(); - public static final Counter requestCount = - Counter.build() + public static final Histogram requestEntityCount = + Histogram.build() + .buckets(1, 2, 5, 10, 20, 50, 100, 200) + .name("request_entity_count") + .subsystem("feast_serving") + .help("Number of entity rows per request") + .labelNames("project") + .register(); + + public static final Histogram requestFeatureCount = + Histogram.build() + .buckets(1, 2, 5, 10, 15, 20, 30, 50) .name("request_feature_count") .subsystem("feast_serving") - .help("number of feature rows requested") - .labelNames("project", "feature_name") + .help("Number of feature rows per request") + .labelNames("project") + .register(); + + public static final Histogram requestFeatureTableCount = + Histogram.build() + .buckets(1, 2, 5, 10, 20) + .name("request_feature_table_count") + .subsystem("feast_serving") + .help("Number of feature tables per request") + .labelNames("project") .register(); public static final Counter notFoundKeyCount =