Skip to content

Commit 6db1ec0

Browse files
authored
Add Feast Serving histogram metrics (#1240)
* Add serving histogram metrics Signed-off-by: Terence <terencelimxp@gmail.com> * Clean ups Signed-off-by: Terence <terencelimxp@gmail.com> * Add more buckets Signed-off-by: Terence <terencelimxp@gmail.com> * Fix conflict Signed-off-by: Terence <terencelimxp@gmail.com>
1 parent 04d2b47 commit 6db1ec0

2 files changed

Lines changed: 50 additions & 4 deletions

File tree

serving/src/main/java/feast/serving/service/OnlineServingServiceV2.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package feast.serving.service;
1818

19+
import static feast.common.models.FeatureTable.getFeatureTableStringRef;
20+
1921
import com.google.protobuf.Duration;
2022
import feast.common.models.FeatureV2;
2123
import feast.proto.core.FeatureProto;
@@ -162,6 +164,7 @@ public GetOnlineFeaturesResponse getOnlineFeatures(GetOnlineFeaturesRequestV2 re
162164
entityValuesMap.get(entityRow).putAll(allValueMaps);
163165
entityStatusesMap.get(entityRow).putAll(allStatusMaps);
164166
}
167+
populateHistogramMetrics(entityRows, featureReferences, projectName);
165168

166169
// Build response field values from entityValuesMap and entityStatusesMap
167170
// Response field values should be in the same order as the entityRows provided by the user.
@@ -295,6 +298,30 @@ private static boolean checkOutsideMaxAge(
295298
return timeDifference > maxAge.getSeconds();
296299
}
297300

301+
/**
302+
* Populate histogram metrics that can be used for analysing online retrieval calls
303+
*
304+
* @param entityRows entity rows provided in request
305+
* @param featureReferences feature references provided in request
306+
* @param project project name provided in request
307+
*/
308+
private void populateHistogramMetrics(
309+
List<GetOnlineFeaturesRequestV2.EntityRow> entityRows,
310+
List<FeatureReferenceV2> featureReferences,
311+
String project) {
312+
Metrics.requestEntityCount.labels(project).observe(Double.valueOf(entityRows.size()));
313+
Metrics.requestFeatureCount.labels(project).observe(Double.valueOf(featureReferences.size()));
314+
315+
long countDistinctFeatureTables =
316+
featureReferences.stream()
317+
.map(featureReference -> getFeatureTableStringRef(project, featureReference))
318+
.distinct()
319+
.count();
320+
Metrics.requestFeatureTableCount
321+
.labels(project)
322+
.observe(Double.valueOf(countDistinctFeatureTables));
323+
}
324+
298325
/**
299326
* Populate count metrics that can be used for analysing online retrieval calls
300327
*

serving/src/main/java/feast/serving/util/Metrics.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,31 @@ public class Metrics {
2929
.labelNames("method")
3030
.register();
3131

32-
public static final Counter requestCount =
33-
Counter.build()
32+
public static final Histogram requestEntityCount =
33+
Histogram.build()
34+
.buckets(1, 2, 5, 10, 20, 50, 100, 200)
35+
.name("request_entity_count")
36+
.subsystem("feast_serving")
37+
.help("Number of entity rows per request")
38+
.labelNames("project")
39+
.register();
40+
41+
public static final Histogram requestFeatureCount =
42+
Histogram.build()
43+
.buckets(1, 2, 5, 10, 15, 20, 30, 50)
3444
.name("request_feature_count")
3545
.subsystem("feast_serving")
36-
.help("number of feature rows requested")
37-
.labelNames("project", "feature_name")
46+
.help("Number of feature rows per request")
47+
.labelNames("project")
48+
.register();
49+
50+
public static final Histogram requestFeatureTableCount =
51+
Histogram.build()
52+
.buckets(1, 2, 5, 10, 20)
53+
.name("request_feature_table_count")
54+
.subsystem("feast_serving")
55+
.help("Number of feature tables per request")
56+
.labelNames("project")
3857
.register();
3958

4059
public static final Counter notFoundKeyCount =

0 commit comments

Comments
 (0)