config.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #pragma once
  2. #include "fwd.h"
  3. #include "common.h"
  4. #include "node.h"
  5. #include <library/cpp/yt/misc/enum.h>
  6. #include <util/generic/maybe.h>
  7. #include <util/generic/string.h>
  8. #include <util/generic/hash_set.h>
  9. #include <util/datetime/base.h>
  10. namespace NYT {
  11. enum EEncoding : int
  12. {
  13. E_IDENTITY /* "identity" */,
  14. E_GZIP /* "gzip" */,
  15. E_BROTLI /* "br" */,
  16. E_Z_LZ4 /* "z-lz4" */,
  17. };
  18. enum class ENodeReaderFormat : int
  19. {
  20. Yson, // Always use YSON format,
  21. Skiff, // Always use Skiff format, throw exception if it's not possible (non-strict schema, dynamic table etc.)
  22. Auto, // Use Skiff format if it's possible, YSON otherwise
  23. };
  24. enum class ETraceHttpRequestsMode
  25. {
  26. // Never dump http requests.
  27. Never /* "never" */,
  28. // Dump failed http requests.
  29. Error /* "error" */,
  30. // Dump all http requests.
  31. Always /* "always" */,
  32. };
  33. DEFINE_ENUM(EUploadDeduplicationMode,
  34. // For each file only one process' thread from all possible hosts can upload it to the file cache at the same time.
  35. // The others will wait for the uploading to finish and use already cached file.
  36. ((Global) (0))
  37. // For each file and each particular host only one process' thread can upload it to the file cache at the same time.
  38. // The others will wait for the uploading to finish and use already cached file.
  39. ((Host) (1))
  40. // All processes' threads will upload a file to the cache concurrently.
  41. ((Disabled) (2))
  42. );
  43. ////////////////////////////////////////////////////////////////////////////////
  44. /// Enum describing possible versions of table writer implemetation.
  45. enum class ETableWriterVersion
  46. {
  47. /// Allow library to choose version of writer.
  48. Auto,
  49. /// Stable but slower version of writer.
  50. V1,
  51. /// Unstable but faster version of writer (going to be default in the future).
  52. V2,
  53. };
  54. ////////////////////////////////////////////////////////////////////////////////
  55. struct TConfig
  56. : public TThrRefBase
  57. {
  58. TString Hosts;
  59. TString Pool;
  60. TString Token;
  61. TString Prefix;
  62. TString ApiVersion;
  63. TString LogLevel;
  64. // Compression for data that is sent to YT cluster.
  65. EEncoding ContentEncoding;
  66. // Compression for data that is read from YT cluster.
  67. EEncoding AcceptEncoding;
  68. TString GlobalTxId;
  69. bool ForceIpV4;
  70. bool ForceIpV6;
  71. bool UseHosts;
  72. TDuration HostListUpdateInterval;
  73. TNode Spec;
  74. TNode TableWriter;
  75. TDuration ConnectTimeout;
  76. TDuration SocketTimeout;
  77. TDuration AddressCacheExpirationTimeout;
  78. TDuration TxTimeout;
  79. TDuration PingTimeout;
  80. TDuration PingInterval;
  81. bool UseAsyncTxPinger;
  82. int AsyncHttpClientThreads;
  83. int AsyncTxPingerPoolThreads;
  84. // How often should we poll for lock state
  85. TDuration WaitLockPollInterval;
  86. TDuration RetryInterval;
  87. TDuration ChunkErrorsRetryInterval;
  88. TDuration RateLimitExceededRetryInterval;
  89. TDuration StartOperationRetryInterval;
  90. int RetryCount;
  91. int ReadRetryCount;
  92. int StartOperationRetryCount;
  93. /// @brief Period for checking status of running operation.
  94. TDuration OperationTrackerPollPeriod = TDuration::Seconds(5);
  95. TString RemoteTempFilesDirectory;
  96. TString RemoteTempTablesDirectory;
  97. //
  98. // Infer schemas for nonexstent tables from typed rows (e.g. protobuf)
  99. // when writing from operation or client writer.
  100. // This options can be overridden in TOperationOptions and TTableWriterOptions.
  101. bool InferTableSchema;
  102. bool UseClientProtobuf;
  103. ENodeReaderFormat NodeReaderFormat;
  104. bool ProtobufFormatWithDescriptors;
  105. int ConnectionPoolSize;
  106. /// Defines replication factor that is used for files that are uploaded to YT
  107. /// to use them in operations.
  108. int FileCacheReplicationFactor = 10;
  109. /// @brief Used when waiting for other process which uploads the same file to the file cache.
  110. ///
  111. /// If CacheUploadDeduplicationMode is not Disabled, current process can wait for some other
  112. /// process which is uploading the same file. This value is proportional to the timeout of waiting,
  113. /// actual timeout computes as follows: fileSizeGb * CacheLockTimeoutPerGb.
  114. /// Default timeout assumes that host has uploading speed equal to 20 Mb/s.
  115. /// If timeout was reached, the file will be uploaded by current process without any other waits.
  116. TDuration CacheLockTimeoutPerGb;
  117. /// @brief Used to prevent concurrent uploading of the same file to the file cache.
  118. /// NB: Each mode affects only users with the same mode enabled.
  119. EUploadDeduplicationMode CacheUploadDeduplicationMode;
  120. // @brief Minimum byte size for files to undergo deduplication at upload
  121. i64 CacheUploadDeduplicationThreshold;
  122. bool MountSandboxInTmpfs;
  123. /// @brief Set upload options (e.g.) for files created by library.
  124. ///
  125. /// Path itself is always ignored but path options (e.g. `BypassArtifactCache`) are used when uploading system files:
  126. /// cppbinary, job state, etc
  127. TRichYPath ApiFilePathOptions;
  128. // Testing options, should never be used in user programs.
  129. bool UseAbortableResponse = false;
  130. bool EnableDebugMetrics = false;
  131. //
  132. // There is optimization used with local YT that enables to skip binary upload and use real binary path.
  133. // When EnableLocalModeOptimization is set to false this optimization is completely disabled.
  134. bool EnableLocalModeOptimization = true;
  135. //
  136. // If you want see stderr even if you jobs not failed set this true.
  137. bool WriteStderrSuccessfulJobs = false;
  138. //
  139. // This configuration is useful for debug.
  140. // If set to ETraceHttpRequestsMode::Error library will dump all http error requests.
  141. // If set to ETraceHttpRequestsMode::All library will dump all http requests.
  142. // All tracing occurres as DEBUG level logging.
  143. ETraceHttpRequestsMode TraceHttpRequestsMode = ETraceHttpRequestsMode::Never;
  144. TString SkynetApiHost;
  145. // Sets SO_PRIORITY option on the socket
  146. TMaybe<int> SocketPriority;
  147. // Framing settings
  148. // (cf. https://ytsaurus.tech/docs/en/user-guide/proxy/http-reference#framing).
  149. THashSet<TString> CommandsWithFraming;
  150. /// Which implemetation of table writer to use.
  151. ETableWriterVersion TableWriterVersion = ETableWriterVersion::Auto;
  152. /// Redirects stdout to stderr for jobs.
  153. bool RedirectStdoutToStderr = false;
  154. static bool GetBool(const char* var, bool defaultValue = false);
  155. static int GetInt(const char* var, int defaultValue);
  156. static TDuration GetDuration(const char* var, TDuration defaultValue);
  157. static EEncoding GetEncoding(const char* var);
  158. static EUploadDeduplicationMode GetUploadingDeduplicationMode(
  159. const char* var,
  160. EUploadDeduplicationMode defaultValue);
  161. static void ValidateToken(const TString& token);
  162. static TString LoadTokenFromFile(const TString& tokenPath);
  163. static TNode LoadJsonSpec(const TString& strSpec);
  164. static TRichYPath LoadApiFilePathOptions(const TString& ysonMap);
  165. void LoadToken();
  166. void LoadSpec();
  167. void LoadTimings();
  168. void Reset();
  169. TConfig();
  170. static TConfigPtr Get();
  171. };
  172. ////////////////////////////////////////////////////////////////////////////////
  173. struct TProcessState
  174. {
  175. TString FqdnHostName;
  176. TString UserName;
  177. TVector<TString> CommandLine;
  178. // Command line with everything that looks like tokens censored.
  179. TVector<TString> CensoredCommandLine;
  180. int Pid;
  181. TString ClientVersion;
  182. TProcessState();
  183. void SetCommandLine(int argc, const char* argv[]);
  184. static TProcessState* Get();
  185. };
  186. ////////////////////////////////////////////////////////////////////////////////
  187. } // namespace NYT