config.h 6.9 KB

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