|
1 | 1 | #include "shared_resources.h" |
2 | 2 |
|
3 | | -#include <ydb/library/services/services.pb.h> |
4 | 3 | #include <ydb/core/fq/libs/events/events.h> |
| 4 | +#include <ydb/library/actors/core/actorsystem.h> |
5 | 5 | #include <ydb/library/logger/actor.h> |
| 6 | +#include <ydb/library/services/services.pb.h> |
6 | 7 |
|
7 | | -#include <ydb/library/actors/core/actorsystem.h> |
| 8 | +#include <ydb/public/api/protos/ydb_discovery.pb.h> |
| 9 | +#include <ydb/public/sdk/cpp/client/extensions/discovery_mutator/discovery_mutator.h> |
8 | 10 |
|
9 | 11 | #include <util/generic/cast.h> |
10 | 12 | #include <util/generic/strbuf.h> |
@@ -33,6 +35,7 @@ struct TYqSharedResourcesImpl : public TActorSystemPtrMixin, public TYqSharedRes |
33 | 35 | : TYqSharedResources(NYdb::TDriver(GetYdbDriverConfig(config.GetCommon().GetYdbDriverConfig()))) |
34 | 36 | { |
35 | 37 | CreateDbPoolHolder(PrepareDbPoolConfig(config), credentialsProviderFactory, counters); |
| 38 | + AddUnderlayDiscoveryMutator(); |
36 | 39 | } |
37 | 40 |
|
38 | 41 | NDbPool::TConfig PrepareDbPoolConfig(const NFq::NConfig::TConfig& config) { |
@@ -81,6 +84,27 @@ struct TYqSharedResourcesImpl : public TActorSystemPtrMixin, public TYqSharedRes |
81 | 84 | const ::NMonitoring::TDynamicCounterPtr& counters) { |
82 | 85 | DbPoolHolder = MakeIntrusive<NDbPool::TDbPoolHolder>(config, CoreYdbDriver, credentialsProviderFactory, counters); |
83 | 86 | } |
| 87 | + |
| 88 | + void AddUnderlayDiscoveryMutator() { |
| 89 | + |
| 90 | + auto mutator = [](Ydb::Discovery::ListEndpointsResult* proto, NYdb::TStatus status, const NYdb::IDiscoveryMutatorApi::TAuxInfo& aux) { |
| 91 | + TStringBuf underlayPrefix{"u-"}; |
| 92 | + if (!aux.DiscoveryEndpoint.starts_with(underlayPrefix) || !proto) { |
| 93 | + return status; |
| 94 | + } |
| 95 | + |
| 96 | + for (size_t i = 0; i < proto->endpointsSize(); ++i) { |
| 97 | + Ydb::Discovery::EndpointInfo* endpointInfo = proto->Mutableendpoints(i); |
| 98 | + const TString& address = endpointInfo->address(); |
| 99 | + if (address.StartsWith(underlayPrefix)) { |
| 100 | + continue; |
| 101 | + } |
| 102 | + endpointInfo->set_address(underlayPrefix + address); |
| 103 | + } |
| 104 | + return status; |
| 105 | + }; |
| 106 | + UserSpaceYdbDriver.AddExtension<NDiscoveryMutator::TDiscoveryMutator>(NDiscoveryMutator::TDiscoveryMutator::TParams(std::move(mutator))); |
| 107 | + } |
84 | 108 | }; |
85 | 109 |
|
86 | 110 | } // namespace |
|
0 commit comments