Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Feast Serving gRPC call metrics #509

Merged
merged 4 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import feast.core.StoreProto.Store;
import feast.serving.ServingAPIProto.GetFeastServingInfoRequest;
import feast.serving.interceptors.GrpcMonitoringInterceptor;
import feast.serving.service.ServingService;
import feast.serving.specs.CachedSpecService;
import io.grpc.health.v1.HealthGrpc.HealthImplBase;
Expand All @@ -30,7 +31,7 @@

// Reference: https://github.com/grpc/grpc/blob/master/doc/health-checking.md

@GRpcService
@GRpcService(interceptors = {GrpcMonitoringInterceptor.class})
public class HealthServiceController extends HealthImplBase {
private CachedSpecService specService;
private ServingService servingService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import feast.serving.ServingAPIProto.GetOnlineFeaturesRequest;
import feast.serving.ServingAPIProto.GetOnlineFeaturesResponse;
import feast.serving.ServingServiceGrpc.ServingServiceImplBase;
import feast.serving.interceptors.GrpcMonitoringInterceptor;
import feast.serving.service.ServingService;
import feast.serving.util.RequestHelper;
import io.grpc.stub.StreamObserver;
Expand All @@ -36,7 +37,7 @@
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

@GRpcService
@GRpcService(interceptors = {GrpcMonitoringInterceptor.class})
public class ServingServiceGRpcController extends ServingServiceImplBase {

private static final Logger log =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2018-2020 The Feast Authors
*
* Licensed 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
*
* https://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 feast.serving.interceptors;

import feast.serving.util.Metrics;
import io.grpc.ForwardingServerCall.SimpleForwardingServerCall;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.ServerCall;
import io.grpc.ServerCall.Listener;
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;
import io.grpc.Status;

/**
* GrpcMonitoringInterceptor intercepts GRPC calls to provide request latency histogram metrics in
* the Prometheus client.
*/
public class GrpcMonitoringInterceptor implements ServerInterceptor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bikeshedding on naming if you'll bear with me… it's more about request/response metrics than monitoring, monitoring would be what you might externally do with the metrics ☺️

Also I wonder if anyone would object to dropping the Grpc prefix, I imagine everything in the interceptors package will be a gRPC interceptor so perhaps it's redundant. What do you think of:

Suggested change
public class GrpcMonitoringInterceptor implements ServerInterceptor {
public class RequestMetricsInterceptor implements ServerInterceptor {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sounds reasonable to me. I think we need to create a new PR?

Although the sample library for integrating Prometheus with GRPC in Java uses the monitoring term as well :)
https://github.com/grpc-ecosystem/java-grpc-prometheus/tree/master/src/main/java/me/dinowernli/grpc/prometheus

I guess as long as we're consistent.


@Override
public <ReqT, RespT> Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {

long startCallMillis = System.currentTimeMillis();
String fullMethodName = call.getMethodDescriptor().getFullMethodName();
String serviceName = MethodDescriptor.extractFullServiceName(fullMethodName);
String methodName = fullMethodName.substring(fullMethodName.indexOf("/") + 1);

return next.startCall(
new SimpleForwardingServerCall<ReqT, RespT>(call) {
@Override
public void close(Status status, Metadata trailers) {
Metrics.requestLatency
ches marked this conversation as resolved.
Show resolved Hide resolved
.labels(serviceName, methodName, status.getCode().name())
.observe((System.currentTimeMillis() - startCallMillis) / 1000f);
super.close(status, trailers);
}
},
headers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static feast.serving.store.bigquery.QueryTemplater.createEntityTableUUIDQuery;
import static feast.serving.store.bigquery.QueryTemplater.generateFullTableName;
import static feast.serving.util.Metrics.requestLatency;

import com.google.cloud.RetryOption;
import com.google.cloud.bigquery.BigQuery;
Expand Down Expand Up @@ -116,7 +115,6 @@ public GetOnlineFeaturesResponse getOnlineFeatures(GetOnlineFeaturesRequest getF
/** {@inheritDoc} */
@Override
public GetBatchFeaturesResponse getBatchFeatures(GetBatchFeaturesRequest getFeaturesRequest) {
long startTime = System.currentTimeMillis();
List<FeatureSetRequest> featureSetRequests =
specService.getFeatureSets(getFeaturesRequest.getFeaturesList());

Expand Down Expand Up @@ -168,9 +166,6 @@ public GetBatchFeaturesResponse getBatchFeatures(GetBatchFeaturesRequest getFeat
.build())
.start();

requestLatency
.labels("getBatchFeatures")
.observe((System.currentTimeMillis() - startTime) / 1000);
return GetBatchFeaturesResponse.newBuilder().setJob(feastJob).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

public class RedisServingService implements ServingService {

private static final String SERVICE_NAME = "feast.serving.ServingService";
private static final Logger log = org.slf4j.LoggerFactory.getLogger(RedisServingService.class);
private final CachedSpecService specService;
private final Tracer tracer;
Expand Down Expand Up @@ -87,7 +88,6 @@ public GetFeastServingInfoResponse getFeastServingInfo(
@Override
public GetOnlineFeaturesResponse getOnlineFeatures(GetOnlineFeaturesRequest request) {
try (Scope scope = tracer.buildSpan("Redis-getOnlineFeatures").startActive(true)) {
long startTime = System.currentTimeMillis();
GetOnlineFeaturesResponse.Builder getOnlineFeaturesResponseBuilder =
GetOnlineFeaturesResponse.newBuilder();

Expand Down Expand Up @@ -120,9 +120,6 @@ public GetOnlineFeaturesResponse getOnlineFeatures(GetOnlineFeaturesRequest requ
featureValuesMap.values().stream()
.map(valueMap -> FieldValues.newBuilder().putAllFields(valueMap).build())
.collect(Collectors.toList());
requestLatency
.labels("getOnlineFeatures")
.observe((System.currentTimeMillis() - startTime) / 1000);
return getOnlineFeaturesResponseBuilder.addAllFieldValues(fieldValues).build();
}
}
Expand Down Expand Up @@ -274,7 +271,7 @@ private void sendAndProcessMultiGet(
}
} finally {
requestLatency
.labels("processResponse")
.labels(SERVICE_NAME, "processResponse", "NA")
.observe((System.currentTimeMillis() - startTime) / 1000);
}
}
Expand Down Expand Up @@ -317,7 +314,7 @@ private List<byte[]> sendMultiGet(List<RedisKey> keys) {
.asRuntimeException();
} finally {
requestLatency
.labels("sendMultiGet")
.labels(SERVICE_NAME, "sendMultiGet", "NA")
.observe((System.currentTimeMillis() - startTime) / 1000d);
}
}
Expand Down
2 changes: 1 addition & 1 deletion serving/src/main/java/feast/serving/util/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Metrics {
.name("request_latency_seconds")
.subsystem("feast_serving")
.help("Request latency in seconds")
.labelNames("method")
.labelNames("service", "method", "status_code")
woop marked this conversation as resolved.
Show resolved Hide resolved
.register();

public static final Counter requestCount =
Expand Down