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

Increase ext proc timeout #2535

Merged
merged 2 commits into from
Oct 4, 2024
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
3 changes: 2 additions & 1 deletion adapter/internal/oasparser/envoyconf/http_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,15 @@ func getRateLimitFilter() *hcmv3.HttpFilter {

// getExtProcessHTTPFilter gets ExtAauthz http filter.
func getExtProcessHTTPFilter() *hcmv3.HttpFilter {
// conf := config.ReadConfigs()
conf := config.ReadConfigs()
externalProcessor := &ext_process.ExternalProcessor{
GrpcService: &corev3.GrpcService{
TargetSpecifier: &corev3.GrpcService_EnvoyGrpc_{
EnvoyGrpc: &corev3.GrpcService_EnvoyGrpc{
ClusterName: extAuthzClusterName,
},
},
Timeout: durationpb.New(conf.Envoy.EnforcerResponseTimeoutInSeconds * time.Second),
},
ProcessingMode: &ext_process.ProcessingMode{
ResponseBodyMode: ext_process.ProcessingMode_BUFFERED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public StreamObserver<ProcessingRequest> process(
@Override
public void onNext(ProcessingRequest request) {
ProcessingRequest.RequestCase r = request.getRequestCase();
logger.info("Starting to serve external processing request");
switch (r) {
case RESPONSE_HEADERS:
if (!request.getAttributesMap().isEmpty() && request.getAttributesMap().get(MetadataConstants.EXT_PROC_METADATA_CONTEXT_KEY) != null && request.getAttributesMap().get(MetadataConstants.EXT_PROC_METADATA_CONTEXT_KEY).getFieldsMap().get("xds.route_metadata") != null){
Expand Down Expand Up @@ -122,7 +123,16 @@ public void onNext(ProcessingRequest request) {
ratelimitClient.shouldRatelimit(configs);
});
if (usage != null) {

Struct.Builder structBuilder = Struct.newBuilder();
addMetadata(structBuilder, MetadataConstants.AI_PROVIDER_API_VERSION, providerAPIVersion);
addMetadata(structBuilder, MetadataConstants.AI_PROVIDER_NAME, providerName);
addMetadata(structBuilder, MetadataConstants.MODEL, usage.model);
addMetadata(structBuilder, MetadataConstants.COMPLETION_TOKEN_COUNT, usage.completion_tokens);
addMetadata(structBuilder, MetadataConstants.TOTAL_TOKEN_COUNT, usage.total_tokens);
addMetadata(structBuilder, MetadataConstants.PROMPT_TOKEN_COUNT, usage.prompt_tokens);
Struct.Builder rootStructBuilder = Struct.newBuilder();
rootStructBuilder.putFields(MetadataConstants.EXT_PROC_METADATA_CONTEXT_KEY, Value.newBuilder().setStructValue(structBuilder.build()).build());
responseObserver.onNext(ProcessingResponse.newBuilder().setDynamicMetadata(rootStructBuilder.build()).setResponseHeaders(prepareHeadersResponse()).build());
}
}
responseObserver.onCompleted();
Expand Down Expand Up @@ -195,6 +205,7 @@ public void onNext(ProcessingRequest request) {
}
responseObserver.onCompleted();
} else {
logger.error("Response body not found");
responseObserver.onCompleted();
}

Expand Down Expand Up @@ -230,10 +241,10 @@ protected HeadersResponse prepareHeadersResponse() {
.setResponse(
CommonResponse.newBuilder()
.setStatus(CommonResponse.ResponseStatus.CONTINUE)
.setHeaderMutation(
HeaderMutation.newBuilder()
.build())
.setBodyMutation(BodyMutation.newBuilder().build())
// .setHeaderMutation(
// HeaderMutation.newBuilder()
// .build())
// .setBodyMutation(BodyMutation.newBuilder().build())
.build())
.build();
}
Expand Down
Loading