Skip to content

Commit

Permalink
adding api requested to returned headers (#1669)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranlavanet authored Sep 4, 2024
1 parent 200972c commit e576026
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions protocol/common/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
ERRORED_PROVIDERS_HEADER_NAME = "Lava-Errored-Providers"
NODE_ERRORS_PROVIDERS_HEADER_NAME = "Lava-Node-Errors-providers"
REPORTED_PROVIDERS_HEADER_NAME = "Lava-Reported-Providers"
USER_REQUEST_TYPE = "lava-user-request-type"
LAVAP_VERSION_HEADER_NAME = "Lavap-Version"
LAVA_CONSUMER_PROCESS_GUID = "lava-consumer-process-guid"
// these headers need to be lowercase
Expand Down
11 changes: 9 additions & 2 deletions protocol/rpcconsumer/rpcconsumer_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func (rpccs *RPCConsumerServer) SendParsedRelay(
}

returnedResult, err := relayProcessor.ProcessingResult()
rpccs.appendHeadersToRelayResult(ctx, returnedResult, relayProcessor.ProtocolErrors(), relayProcessor, protocolMessage.GetDirectiveHeaders())
rpccs.appendHeadersToRelayResult(ctx, returnedResult, relayProcessor.ProtocolErrors(), relayProcessor, protocolMessage.GetDirectiveHeaders(), protocolMessage.GetApi().GetName())
if err != nil {
return returnedResult, utils.LavaFormatError("failed processing responses from providers", err, utils.Attribute{Key: "GUID", Value: ctx}, utils.LogAttr("endpoint", rpccs.listenEndpoint.Key()))
}
Expand Down Expand Up @@ -1342,7 +1342,7 @@ func (rpccs *RPCConsumerServer) HandleDirectiveHeadersForMessage(chainMessage ch
chainMessage.SetForceCacheRefresh(ok)
}

func (rpccs *RPCConsumerServer) appendHeadersToRelayResult(ctx context.Context, relayResult *common.RelayResult, protocolErrors uint64, relayProcessor *RelayProcessor, directiveHeaders map[string]string) {
func (rpccs *RPCConsumerServer) appendHeadersToRelayResult(ctx context.Context, relayResult *common.RelayResult, protocolErrors uint64, relayProcessor *RelayProcessor, directiveHeaders map[string]string, apiName string) {
if relayResult == nil {
return
}
Expand Down Expand Up @@ -1387,6 +1387,13 @@ func (rpccs *RPCConsumerServer) appendHeadersToRelayResult(ctx context.Context,
})
}

// add user requested API
metadataReply = append(metadataReply,
pairingtypes.Metadata{
Name: common.USER_REQUEST_TYPE,
Value: apiName,
})

// fetch trailer information from the provider by using the provider trailer field.
providerNodeExtensions := relayResult.ProviderTrailer.Get(chainlib.RPCProviderNodeExtension)
if len(providerNodeExtensions) > 0 {
Expand Down

0 comments on commit e576026

Please sign in to comment.