Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -25,6 +25,7 @@
import feast.proto.serving.ServingServiceGrpc.ServingServiceImplBase;
import feast.serving.config.FeastProperties;
import feast.serving.exception.SpecRetrievalException;
import feast.serving.interceptors.GrpcMonitoringContext;
import feast.serving.interceptors.GrpcMonitoringInterceptor;
import feast.serving.service.ServingServiceV2;
import feast.serving.util.RequestHelper;
Expand Down Expand Up @@ -86,6 +87,9 @@ public void getOnlineFeaturesV2(
// project set at root level overrides the project set at feature table level
this.authorizationService.authorizeRequest(
SecurityContextHolder.getContext(), request.getProject());

// update monitoring context
GrpcMonitoringContext.getInstance().setProject(request.getProject());
}
RequestHelper.validateOnlineRequest(request);
Span span = tracer.buildSpan("getOnlineFeaturesV2").start();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2018-2021 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 java.util.Optional;

public class GrpcMonitoringContext {
private static GrpcMonitoringContext INSTANCE;

final ThreadLocal<String> project = new ThreadLocal();

private GrpcMonitoringContext() {}

public static GrpcMonitoringContext getInstance() {
if (INSTANCE == null) {
INSTANCE = new GrpcMonitoringContext();
}

return INSTANCE;
}

public void setProject(String name) {
this.project.set(name);
}

public Optional<String> getProject() {
return Optional.ofNullable(this.project.get());
}

public void clearProject() {
this.project.set(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;
import io.grpc.Status;
import java.util.Optional;

/**
* GrpcMonitoringInterceptor intercepts GRPC calls to provide request latency histogram metrics in
Expand All @@ -39,12 +40,16 @@ public <ReqT, RespT> Listener<ReqT> interceptCall(
String fullMethodName = call.getMethodDescriptor().getFullMethodName();
String methodName = fullMethodName.substring(fullMethodName.indexOf("/") + 1);

GrpcMonitoringContext.getInstance().clearProject();

return next.startCall(
new SimpleForwardingServerCall<ReqT, RespT>(call) {
@Override
public void close(Status status, Metadata trailers) {
Optional<String> projectName = GrpcMonitoringContext.getInstance().getProject();

Metrics.requestLatency
.labels(methodName)
.labels(methodName, projectName.orElse(""))
.observe((System.currentTimeMillis() - startCallMillis) / 1000f);
Metrics.grpcRequestCount.labels(methodName, status.getCode().name()).inc();
super.close(status, trailers);
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 @@ -26,7 +26,7 @@ public class Metrics {
.name("request_latency_seconds")
.subsystem("feast_serving")
.help("Request latency in seconds")
.labelNames("method")
.labelNames("method", "project")
.register();

public static final Histogram requestEntityCountDistribution =
Expand Down