Skip to content

Commit

Permalink
ticket parser: Add priority to access service requests (ydb-platform#…
Browse files Browse the repository at this point in the history
  • Loading branch information
molotkov-and committed Nov 20, 2024
1 parent bbe9214 commit f5a08b5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ydb/core/security/ticket_parser_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class TTicketParserImpl : public TActorBootstrapped<TDerived> {
TStackVec<TString> AdditionalSIDs;
bool RefreshRetryableErrorImmediately = false;
TExternalAuthInfo ExternalAuthInfo;
bool IsLowAccessServiceRequestPriority = false;

TTokenRecordBase(const TStringBuf ticket)
: Ticket(ticket)
Expand Down Expand Up @@ -394,6 +395,11 @@ class TTicketParserImpl : public TActorBootstrapped<TDerived> {
}
}

if (record.IsLowAccessServiceRequestPriority) {
auto& headers = request->Headers;
headers["x-ya-priority"] = "low";
}

return request;
}

Expand Down Expand Up @@ -1704,6 +1710,7 @@ class TTicketParserImpl : public TActorBootstrapped<TDerived> {
CounterTicketsBuildTime->Collect((now - record.InitTime).MilliSeconds());
BLOG_D("Ticket " << record.GetMaskedTicket() << " ("
<< record.PeerName << ") has now valid token of " << record.Subject);
record.IsLowAccessServiceRequestPriority = true;
RefreshQueue.push({.Key = key, .RefreshTime = record.RefreshTime});
}

Expand Down Expand Up @@ -1732,6 +1739,7 @@ class TTicketParserImpl : public TActorBootstrapped<TDerived> {
<< record.PeerName << ") has now permanent error message '" << error.Message << "'");
}
CounterTicketsErrors->Inc();
record.IsLowAccessServiceRequestPriority = true;
RefreshQueue.push({.Key = key, .RefreshTime = record.RefreshTime});
}

Expand Down
3 changes: 3 additions & 0 deletions ydb/library/grpc/actor_client/grpc_service_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class TGrpcServiceClient {
if (requestId) {
meta.Aux.push_back({"x-request-id", requestId});
}
for (const auto& [k, v] : ev->Get()->Headers) {
meta.Aux.push_back({k, v});
}

NYdbGrpc::TResponseCallback<TResponseType> callback =
[actorSystem = NActors::TActivationContext::ActorSystem(), prefix = Prefix(requestId), request = ev](NYdbGrpc::TGrpcStatus&& status, TResponseType&& response) -> void {
Expand Down
1 change: 1 addition & 0 deletions ydb/library/ncloud/api/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct TEvGrpcProtoRequest : NActors::TEventLocal<TEv, TEventType> {
TProtoMessage Request;
TString Token;
TString RequestId;
std::unordered_map<TString, TString> Headers;
};

template <typename TEv, ui32 TEventType, typename TProtoMessage>
Expand Down
1 change: 1 addition & 0 deletions ydb/library/ycloud/api/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct TEvGrpcProtoRequest : NActors::TEventLocal<TEv, TEventType> {
TProtoMessage Request;
TString Token;
TString RequestId;
std::unordered_map<TString, TString> Headers;
};

template <typename TEv, ui32 TEventType, typename TProtoMessage>
Expand Down

0 comments on commit f5a08b5

Please sign in to comment.