config.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. TString LogPath;
  65. // Compression for data that is sent to YT cluster.
  66. EEncoding ContentEncoding;
  67. // Compression for data that is read from YT cluster.
  68. EEncoding AcceptEncoding;
  69. TString GlobalTxId;
  70. bool ForceIpV4;
  71. bool ForceIpV6;
  72. bool UseHosts;
  73. TDuration HostListUpdateInterval;
  74. TNode Spec;
  75. TNode TableWriter;
  76. TDuration ConnectTimeout;
  77. TDuration SocketTimeout;
  78. TDuration AddressCacheExpirationTimeout;
  79. TDuration TxTimeout;
  80. TDuration PingTimeout;
  81. TDuration PingInterval;
  82. bool UseAsyncTxPinger;
  83. int AsyncHttpClientThreads;
  84. int AsyncTxPingerPoolThreads;
  85. // How often should we poll for lock state
  86. TDuration WaitLockPollInterval;
  87. TDuration RetryInterval;
  88. TDuration ChunkErrorsRetryInterval;
  89. TDuration RateLimitExceededRetryInterval;
  90. TDuration StartOperationRetryInterval;
  91. int RetryCount;
  92. int ReadRetryCount;
  93. int StartOperationRetryCount;
  94. /// @brief Period for checking status of running operation.
  95. TDuration OperationTrackerPollPeriod = TDuration::Seconds(5);
  96. TString RemoteTempFilesDirectory;
  97. TString RemoteTempTablesDirectory;
  98. // @brief Keep temp tables produced by TTempTable (despite their name). Should not be used in user programs,
  99. // but may be useful for setting via environment variable for debugging purposes.
  100. bool KeepTempTables = false;
  101. //
  102. // Infer schemas for nonexstent tables from typed rows (e.g. protobuf)
  103. // when writing from operation or client writer.
  104. // This options can be overridden in TOperationOptions and TTableWriterOptions.
  105. bool InferTableSchema;
  106. bool UseClientProtobuf;
  107. ENodeReaderFormat NodeReaderFormat;
  108. bool ProtobufFormatWithDescriptors;
  109. int ConnectionPoolSize;
  110. /// Defines replication factor that is used for files that are uploaded to YT
  111. /// to use them in operations.
  112. int FileCacheReplicationFactor = 10;
  113. /// @brief Used when waiting for other process which uploads the same file to the file cache.
  114. ///
  115. /// If CacheUploadDeduplicationMode is not Disabled, current process can wait for some other
  116. /// process which is uploading the same file. This value is proportional to the timeout of waiting,
  117. /// actual timeout computes as follows: fileSizeGb * CacheLockTimeoutPerGb.
  118. /// Default timeout assumes that host has uploading speed equal to 20 Mb/s.
  119. /// If timeout was reached, the file will be uploaded by current process without any other waits.
  120. TDuration CacheLockTimeoutPerGb;
  121. /// @brief Used to prevent concurrent uploading of the same file to the file cache.
  122. /// NB: Each mode affects only users with the same mode enabled.
  123. EUploadDeduplicationMode CacheUploadDeduplicationMode;
  124. // @brief Minimum byte size for files to undergo deduplication at upload
  125. i64 CacheUploadDeduplicationThreshold;
  126. bool MountSandboxInTmpfs;
  127. /// @brief Set upload options (e.g.) for files created by library.
  128. ///
  129. /// Path itself is always ignored but path options (e.g. `BypassArtifactCache`) are used when uploading system files:
  130. /// cppbinary, job state, etc
  131. TRichYPath ApiFilePathOptions;
  132. // Testing options, should never be used in user programs.
  133. bool UseAbortableResponse = false;
  134. bool EnableDebugMetrics = false;
  135. //
  136. // There is optimization used with local YT that enables to skip binary upload and use real binary path.
  137. // When EnableLocalModeOptimization is set to false this optimization is completely disabled.
  138. bool EnableLocalModeOptimization = true;
  139. //
  140. // If you want see stderr even if you jobs not failed set this true.
  141. bool WriteStderrSuccessfulJobs = false;
  142. //
  143. // This configuration is useful for debug.
  144. // If set to ETraceHttpRequestsMode::Error library will dump all http error requests.
  145. // If set to ETraceHttpRequestsMode::All library will dump all http requests.
  146. // All tracing occurres as DEBUG level logging.
  147. ETraceHttpRequestsMode TraceHttpRequestsMode = ETraceHttpRequestsMode::Never;
  148. TString SkynetApiHost;
  149. // Sets SO_PRIORITY option on the socket
  150. TMaybe<int> SocketPriority;
  151. // Framing settings
  152. // (cf. https://ytsaurus.tech/docs/en/user-guide/proxy/http-reference#framing).
  153. THashSet<TString> CommandsWithFraming;
  154. /// Which implemetation of table writer to use.
  155. ETableWriterVersion TableWriterVersion = ETableWriterVersion::Auto;
  156. /// Redirects stdout to stderr for jobs.
  157. bool RedirectStdoutToStderr = false;
  158. static bool GetBool(const char* var, bool defaultValue = false);
  159. static int GetInt(const char* var, int defaultValue);
  160. static TDuration GetDuration(const char* var, TDuration defaultValue);
  161. static EEncoding GetEncoding(const char* var);
  162. static EUploadDeduplicationMode GetUploadingDeduplicationMode(
  163. const char* var,
  164. EUploadDeduplicationMode defaultValue);
  165. static void ValidateToken(const TString& token);
  166. static TString LoadTokenFromFile(const TString& tokenPath);
  167. static TNode LoadJsonSpec(const TString& strSpec);
  168. static TRichYPath LoadApiFilePathOptions(const TString& ysonMap);
  169. void LoadToken();
  170. void LoadSpec();
  171. void LoadTimings();
  172. void Reset();
  173. TConfig();
  174. static TConfigPtr Get();
  175. };
  176. ////////////////////////////////////////////////////////////////////////////////
  177. struct TProcessState
  178. {
  179. TString FqdnHostName;
  180. TString UserName;
  181. TVector<TString> CommandLine;
  182. // Command line with everything that looks like tokens censored.
  183. TVector<TString> CensoredCommandLine;
  184. int Pid;
  185. TString ClientVersion;
  186. TProcessState();
  187. void SetCommandLine(int argc, const char* argv[]);
  188. static TProcessState* Get();
  189. };
  190. ////////////////////////////////////////////////////////////////////////////////
  191. } // namespace NYT