Просмотр исходного кода

[yql] Activation by revision

YQL-16743
udovichenko-r 1 год назад
Родитель
Сommit
a99a9ca804

+ 1 - 0
ydb/library/yql/providers/common/activation/CMakeLists.darwin-x86_64.txt

@@ -12,6 +12,7 @@ target_link_libraries(providers-common-activation PUBLIC
   contrib-libs-cxxsupp
   yutil
   providers-common-proto
+  library-cpp-svnversion
 )
 target_sources(providers-common-activation PRIVATE
   ${CMAKE_SOURCE_DIR}/ydb/library/yql/providers/common/activation/yql_activation.cpp

+ 1 - 0
ydb/library/yql/providers/common/activation/CMakeLists.linux-aarch64.txt

@@ -13,6 +13,7 @@ target_link_libraries(providers-common-activation PUBLIC
   contrib-libs-cxxsupp
   yutil
   providers-common-proto
+  library-cpp-svnversion
 )
 target_sources(providers-common-activation PRIVATE
   ${CMAKE_SOURCE_DIR}/ydb/library/yql/providers/common/activation/yql_activation.cpp

+ 1 - 0
ydb/library/yql/providers/common/activation/CMakeLists.linux-x86_64.txt

@@ -13,6 +13,7 @@ target_link_libraries(providers-common-activation PUBLIC
   contrib-libs-cxxsupp
   yutil
   providers-common-proto
+  library-cpp-svnversion
 )
 target_sources(providers-common-activation PRIVATE
   ${CMAKE_SOURCE_DIR}/ydb/library/yql/providers/common/activation/yql_activation.cpp

+ 1 - 0
ydb/library/yql/providers/common/activation/CMakeLists.windows-x86_64.txt

@@ -12,6 +12,7 @@ target_link_libraries(providers-common-activation PUBLIC
   contrib-libs-cxxsupp
   yutil
   providers-common-proto
+  library-cpp-svnversion
 )
 target_sources(providers-common-activation PRIVATE
   ${CMAKE_SOURCE_DIR}/ydb/library/yql/providers/common/activation/yql_activation.cpp

+ 1 - 0
ydb/library/yql/providers/common/activation/ya.make

@@ -6,6 +6,7 @@ SRCS(
 
 PEERDIR(
     ydb/library/yql/providers/common/proto
+    library/cpp/svnversion
 )
 
 END()

+ 11 - 2
ydb/library/yql/providers/common/activation/yql_activation.cpp

@@ -2,6 +2,8 @@
 
 #include <ydb/library/yql/providers/common/proto/gateways_config.pb.h>
 
+#include <library/cpp/svnversion/svnversion.h>
+
 #include <util/random/random.h>
 #include <util/generic/algorithm.h>
 #include <util/datetime/base.h>
@@ -14,13 +16,20 @@ ui32 GetPercentage(const TActivation& activation, const TString& userName, const
     if (AnyOf(activation.GetIncludeUsers(), [&](const auto& user) { return user == userName; })) {
         return 100;
     }
-    if (AnyOf(activation.GetIncludeGroups(), [&](const auto& includeGroup) { return groups.contains(includeGroup); })) {
+    if (!groups.empty() && AnyOf(activation.GetIncludeGroups(), [&](const auto& includeGroup) { return groups.contains(includeGroup); })) {
+        return 100;
+    }
+    const auto currentRev =  GetProgramCommitId();
+    if (currentRev && AnyOf(activation.GetIncludeRevisions(), [&](const auto& rev) { return rev == currentRev; })) {
         return 100;
     }
     if (AnyOf(activation.GetExcludeUsers(), [&](const auto& user) { return user == userName; })) {
         return 0;
     }
-    if (AnyOf(activation.GetExcludeGroups(), [&](const auto& excludeGroup) { return groups.contains(excludeGroup); })) {
+    if (!groups.empty() && AnyOf(activation.GetExcludeGroups(), [&](const auto& excludeGroup) { return groups.contains(excludeGroup); })) {
+        return 0;
+    }
+    if (currentRev && AnyOf(activation.GetExcludeRevisions(), [&](const auto& rev) { return rev == currentRev; })) {
         return 0;
     }
     if ((userName.StartsWith("robot-") || userName.StartsWith("zomb-")) && activation.GetExcludeRobots()) {

+ 5 - 3
ydb/library/yql/providers/common/proto/gateways_config.proto

@@ -22,6 +22,8 @@ message TActivationPercentage {
     repeated string Tags = 6;
     repeated string IncludeGroups = 7;
     repeated string ExcludeGroups = 8;
+    repeated string IncludeRevisions = 9;
+    repeated string ExcludeRevisions = 10;
 }
 
 message TAttr {
@@ -559,7 +561,7 @@ message TGenericClusterConfig {
     required NYql.NConnector.NApi.TCredentials Credentials = 10;
 
     // Credentials used to access MDB API.
-    // When working with data source instances deployed in a cloud, 
+    // When working with data source instances deployed in a cloud,
     // you should either set (ServiceAccountId, ServiceAccountIdSignature) pair,
     // or set IAM Token.
     // The names of these fields must satisfy this template function:
@@ -568,7 +570,7 @@ message TGenericClusterConfig {
     optional string ServiceAccountIdSignature = 7;
     optional string Token = 11;
 
-    // If true, the generic provider will ask connector server to use secure connections 
+    // If true, the generic provider will ask connector server to use secure connections
     // to access remote data sources.
     optional bool UseSsl = 12;
 
@@ -592,7 +594,7 @@ message TGenericConnectorConfig {
 }
 
 message TGenericGatewayConfig {
-    // Connector service network endpoint 
+    // Connector service network endpoint
     // TODO: replace with map<DataSourceKind, TGenericConnectorConfig>
     required TGenericConnectorConfig Connector = 5;