/build/source/nativelink-config/src/cas_server.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2024 The NativeLink Authors. All rights reserved. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | use std::collections::HashMap; |
16 | | |
17 | | use serde::Deserialize; |
18 | | |
19 | | use crate::schedulers::SchedulerSpec; |
20 | | use crate::serde_utils::{ |
21 | | convert_data_size_with_shellexpand, convert_duration_with_shellexpand, |
22 | | convert_numeric_with_shellexpand, convert_optional_numeric_with_shellexpand, |
23 | | convert_optional_string_with_shellexpand, convert_string_with_shellexpand, |
24 | | convert_vec_string_with_shellexpand, |
25 | | }; |
26 | | use crate::stores::{ClientTlsConfig, ConfigDigestHashFunction, StoreRefName, StoreSpec}; |
27 | | |
28 | | /// Name of the scheduler. This type will be used when referencing a |
29 | | /// scheduler in the `CasConfig::schedulers`'s map key. |
30 | | pub type SchedulerRefName = String; |
31 | | |
32 | | /// Used when the config references `instance_name` in the protocol. |
33 | | pub type InstanceName = String; |
34 | | |
35 | | #[allow(non_camel_case_types)] |
36 | 0 | #[derive(Deserialize, Debug, Default, Clone, Copy)] |
37 | | pub enum HttpCompressionAlgorithm { |
38 | | /// No compression. |
39 | | #[default] |
40 | | none, |
41 | | |
42 | | /// Zlib compression. |
43 | | gzip, |
44 | | } |
45 | | |
46 | | /// Note: Compressing data in the cloud rarely has a benefit, since most |
47 | | /// cloud providers have very high bandwidth backplanes. However, for |
48 | | /// clients not inside the data center, it might be a good idea to |
49 | | /// compress data to and from the cloud. This will however come at a high |
50 | | /// CPU and performance cost. If you are making remote execution share the |
51 | | /// same CAS/AC servers as client's remote cache, you can create multiple |
52 | | /// services with different compression settings that are served on |
53 | | /// different ports. Then configure the non-cloud clients to use one port |
54 | | /// and cloud-clients to use another. |
55 | 0 | #[derive(Deserialize, Debug, Default)] |
56 | | #[serde(deny_unknown_fields)] |
57 | | pub struct HttpCompressionConfig { |
58 | | /// The compression algorithm that the server will use when sending |
59 | | /// responses to clients. Enabling this will likely save a lot of |
60 | | /// data transfer, but will consume a lot of CPU and add a lot of |
61 | | /// latency. |
62 | | /// see: <https://github.com/tracemachina/nativelink/issues/109> |
63 | | /// |
64 | | /// Default: `HttpCompressionAlgorithm::none` |
65 | | pub send_compression_algorithm: Option<HttpCompressionAlgorithm>, |
66 | | |
67 | | /// The compression algorithm that the server will accept from clients. |
68 | | /// The server will broadcast the supported compression algorithms to |
69 | | /// clients and the client will choose which compression algorithm to |
70 | | /// use. Enabling this will likely save a lot of data transfer, but |
71 | | /// will consume a lot of CPU and add a lot of latency. |
72 | | /// see: <https://github.com/tracemachina/nativelink/issues/109> |
73 | | /// |
74 | | /// Default: {no supported compression} |
75 | | pub accepted_compression_algorithms: Vec<HttpCompressionAlgorithm>, |
76 | | } |
77 | | |
78 | 0 | #[derive(Deserialize, Debug)] |
79 | | #[serde(deny_unknown_fields)] |
80 | | pub struct AcStoreConfig { |
81 | | /// The store name referenced in the `stores` map in the main config. |
82 | | /// This store name referenced here may be reused multiple times. |
83 | | #[serde(deserialize_with = "convert_string_with_shellexpand")] |
84 | | pub ac_store: StoreRefName, |
85 | | |
86 | | /// Whether the Action Cache store may be written to, this if set to false |
87 | | /// it is only possible to read from the Action Cache. |
88 | | #[serde(default)] |
89 | | pub read_only: bool, |
90 | | } |
91 | | |
92 | 0 | #[derive(Deserialize, Debug)] |
93 | | #[serde(deny_unknown_fields)] |
94 | | pub struct CasStoreConfig { |
95 | | /// The store name referenced in the `stores` map in the main config. |
96 | | /// This store name referenced here may be reused multiple times. |
97 | | #[serde(deserialize_with = "convert_string_with_shellexpand")] |
98 | | pub cas_store: StoreRefName, |
99 | | } |
100 | | |
101 | 0 | #[derive(Deserialize, Debug, Default)] |
102 | | #[serde(deny_unknown_fields)] |
103 | | pub struct CapabilitiesRemoteExecutionConfig { |
104 | | /// Scheduler used to configure the capabilities of remote execution. |
105 | | #[serde(deserialize_with = "convert_string_with_shellexpand")] |
106 | | pub scheduler: SchedulerRefName, |
107 | | } |
108 | | |
109 | 0 | #[derive(Deserialize, Debug, Default)] |
110 | | #[serde(deny_unknown_fields)] |
111 | | pub struct CapabilitiesConfig { |
112 | | /// Configuration for remote execution capabilities. |
113 | | /// If not set the capabilities service will inform the client that remote |
114 | | /// execution is not supported. |
115 | | pub remote_execution: Option<CapabilitiesRemoteExecutionConfig>, |
116 | | } |
117 | | |
118 | 0 | #[derive(Deserialize, Debug)] |
119 | | #[serde(deny_unknown_fields)] |
120 | | pub struct ExecutionConfig { |
121 | | /// The store name referenced in the `stores` map in the main config. |
122 | | /// This store name referenced here may be reused multiple times. |
123 | | /// This value must be a CAS store reference. |
124 | | #[serde(deserialize_with = "convert_string_with_shellexpand")] |
125 | | pub cas_store: StoreRefName, |
126 | | |
127 | | /// The scheduler name referenced in the `schedulers` map in the main config. |
128 | | #[serde(deserialize_with = "convert_string_with_shellexpand")] |
129 | | pub scheduler: SchedulerRefName, |
130 | | } |
131 | | |
132 | 0 | #[derive(Deserialize, Debug, Default)] |
133 | | #[serde(deny_unknown_fields)] |
134 | | pub struct ByteStreamConfig { |
135 | | /// Name of the store in the "stores" configuration. |
136 | | pub cas_stores: HashMap<InstanceName, StoreRefName>, |
137 | | |
138 | | /// Max number of bytes to send on each grpc stream chunk. |
139 | | /// According to <https://github.com/grpc/grpc.github.io/issues/371> |
140 | | /// 16KiB - 64KiB is optimal. |
141 | | /// |
142 | | /// |
143 | | /// Default: 64KiB |
144 | | #[serde(default, deserialize_with = "convert_data_size_with_shellexpand")] |
145 | | pub max_bytes_per_stream: usize, |
146 | | |
147 | | /// Maximum number of bytes to decode on each grpc stream chunk. |
148 | | /// Default: 4 MiB |
149 | | #[serde(default, deserialize_with = "convert_data_size_with_shellexpand")] |
150 | | pub max_decoding_message_size: usize, |
151 | | |
152 | | /// In the event a client disconnects while uploading a blob, we will hold |
153 | | /// the internal stream open for this many seconds before closing it. |
154 | | /// This allows clients that disconnect to reconnect and continue uploading |
155 | | /// the same blob. |
156 | | /// |
157 | | /// Default: 10 (seconds) |
158 | | #[serde(default, deserialize_with = "convert_duration_with_shellexpand")] |
159 | | pub persist_stream_on_disconnect_timeout: usize, |
160 | | } |
161 | | |
162 | 0 | #[derive(Deserialize, Debug)] |
163 | | #[serde(deny_unknown_fields)] |
164 | | pub struct WorkerApiConfig { |
165 | | /// The scheduler name referenced in the `schedulers` map in the main config. |
166 | | #[serde(deserialize_with = "convert_string_with_shellexpand")] |
167 | | pub scheduler: SchedulerRefName, |
168 | | } |
169 | | |
170 | 0 | #[derive(Deserialize, Debug, Default)] |
171 | | #[serde(deny_unknown_fields)] |
172 | | pub struct PrometheusConfig { |
173 | | /// Path to register prometheus metrics. If path is "/metrics", and your |
174 | | /// domain is "example.com", you can reach the endpoint with: |
175 | | /// <http://example.com/metrics>. |
176 | | /// |
177 | | /// Default: "/metrics" |
178 | | #[serde(default)] |
179 | | pub path: String, |
180 | | } |
181 | | |
182 | 0 | #[derive(Deserialize, Debug, Default)] |
183 | | #[serde(deny_unknown_fields)] |
184 | | pub struct AdminConfig { |
185 | | /// Path to register the admin API. If path is "/admin", and your |
186 | | /// domain is "example.com", you can reach the endpoint with: |
187 | | /// <http://example.com/admin>. |
188 | | /// |
189 | | /// Default: "/admin" |
190 | | #[serde(default)] |
191 | | pub path: String, |
192 | | } |
193 | | |
194 | 0 | #[derive(Deserialize, Debug, Default)] |
195 | | #[serde(deny_unknown_fields)] |
196 | | pub struct HealthConfig { |
197 | | /// Path to register the health status check. If path is "/status", and your |
198 | | /// domain is "example.com", you can reach the endpoint with: |
199 | | /// <http://example.com/status>. |
200 | | /// |
201 | | /// Default: "/status" |
202 | | #[serde(default)] |
203 | | pub path: String, |
204 | | } |
205 | | |
206 | 0 | #[derive(Deserialize, Debug)] |
207 | | pub struct BepConfig { |
208 | | /// The store to publish build events to. |
209 | | /// The store name referenced in the `stores` map in the main config. |
210 | | #[serde(deserialize_with = "convert_string_with_shellexpand")] |
211 | | pub store: StoreRefName, |
212 | | } |
213 | | |
214 | 0 | #[derive(Deserialize, Debug)] |
215 | | #[serde(deny_unknown_fields)] |
216 | | pub struct ServicesConfig { |
217 | | /// The Content Addressable Storage (CAS) backend config. |
218 | | /// The key is the `instance_name` used in the protocol and the |
219 | | /// value is the underlying CAS store config. |
220 | | pub cas: Option<HashMap<InstanceName, CasStoreConfig>>, |
221 | | |
222 | | /// The Action Cache (AC) backend config. |
223 | | /// The key is the `instance_name` used in the protocol and the |
224 | | /// value is the underlying AC store config. |
225 | | pub ac: Option<HashMap<InstanceName, AcStoreConfig>>, |
226 | | |
227 | | /// Capabilities service is required in order to use most of the |
228 | | /// bazel protocol. This service is used to provide the supported |
229 | | /// features and versions of this bazel GRPC service. |
230 | | pub capabilities: Option<HashMap<InstanceName, CapabilitiesConfig>>, |
231 | | |
232 | | /// The remote execution service configuration. |
233 | | /// NOTE: This service is under development and is currently just a |
234 | | /// place holder. |
235 | | pub execution: Option<HashMap<InstanceName, ExecutionConfig>>, |
236 | | |
237 | | /// This is the service used to stream data to and from the CAS. |
238 | | /// Bazel's protocol strongly encourages users to use this streaming |
239 | | /// interface to interact with the CAS when the data is large. |
240 | | pub bytestream: Option<ByteStreamConfig>, |
241 | | |
242 | | /// This is the service used for workers to connect and communicate |
243 | | /// through. |
244 | | /// NOTE: This service should be served on a different, non-public port. |
245 | | /// In other words, `worker_api` configuration should not have any other |
246 | | /// services that are served on the same port. Doing so is a security |
247 | | /// risk, as workers have a different permission set than a client |
248 | | /// that makes the remote execution/cache requests. |
249 | | pub worker_api: Option<WorkerApiConfig>, |
250 | | |
251 | | /// Experimental - Build Event Protocol (BEP) configuration. This is |
252 | | /// the service that will consume build events from the client and |
253 | | /// publish them to a store for processing by an external service. |
254 | | pub experimental_bep: Option<BepConfig>, |
255 | | |
256 | | /// Experimental - Prometheus metrics configuration. Metrics are gathered |
257 | | /// as a singleton but may be served on multiple endpoints. |
258 | | pub experimental_prometheus: Option<PrometheusConfig>, |
259 | | |
260 | | /// This is the service for any administrative tasks. |
261 | | /// It provides a REST API endpoint for administrative purposes. |
262 | | pub admin: Option<AdminConfig>, |
263 | | |
264 | | /// This is the service for health status check. |
265 | | pub health: Option<HealthConfig>, |
266 | | } |
267 | | |
268 | 0 | #[derive(Deserialize, Debug)] |
269 | | #[serde(deny_unknown_fields)] |
270 | | pub struct TlsConfig { |
271 | | /// Path to the certificate file. |
272 | | #[serde(deserialize_with = "convert_string_with_shellexpand")] |
273 | | pub cert_file: String, |
274 | | |
275 | | /// Path to the private key file. |
276 | | #[serde(deserialize_with = "convert_string_with_shellexpand")] |
277 | | pub key_file: String, |
278 | | |
279 | | /// Path to the certificate authority for mTLS, if client authentication is |
280 | | /// required for this endpoint. |
281 | | #[serde(default, deserialize_with = "convert_optional_string_with_shellexpand")] |
282 | | pub client_ca_file: Option<String>, |
283 | | |
284 | | /// Path to the certificate revocation list for mTLS, if client |
285 | | /// authentication is required for this endpoint. |
286 | | #[serde(default, deserialize_with = "convert_optional_string_with_shellexpand")] |
287 | | pub client_crl_file: Option<String>, |
288 | | } |
289 | | |
290 | | /// Advanced Http configurations. These are generally should not be set. |
291 | | /// For documentation on what each of these do, see the hyper documentation: |
292 | | /// See: <https://docs.rs/hyper/latest/hyper/server/conn/struct.Http.html> |
293 | | /// |
294 | | /// Note: All of these default to hyper's default values unless otherwise |
295 | | /// specified. |
296 | 0 | #[derive(Deserialize, Debug, Default)] |
297 | | #[serde(deny_unknown_fields)] |
298 | | pub struct HttpServerConfig { |
299 | | /// Interval to send keep-alive pings via HTTP2. |
300 | | /// Note: This is in seconds. |
301 | | #[serde( |
302 | | default, |
303 | | deserialize_with = "convert_optional_numeric_with_shellexpand" |
304 | | )] |
305 | | pub http2_keep_alive_interval: Option<u32>, |
306 | | |
307 | | #[serde( |
308 | | default, |
309 | | deserialize_with = "convert_optional_numeric_with_shellexpand" |
310 | | )] |
311 | | pub experimental_http2_max_pending_accept_reset_streams: Option<u32>, |
312 | | |
313 | | #[serde( |
314 | | default, |
315 | | deserialize_with = "convert_optional_numeric_with_shellexpand" |
316 | | )] |
317 | | pub experimental_http2_initial_stream_window_size: Option<u32>, |
318 | | |
319 | | #[serde( |
320 | | default, |
321 | | deserialize_with = "convert_optional_numeric_with_shellexpand" |
322 | | )] |
323 | | pub experimental_http2_initial_connection_window_size: Option<u32>, |
324 | | |
325 | | #[serde(default)] |
326 | | pub experimental_http2_adaptive_window: Option<bool>, |
327 | | |
328 | | #[serde( |
329 | | default, |
330 | | deserialize_with = "convert_optional_numeric_with_shellexpand" |
331 | | )] |
332 | | pub experimental_http2_max_frame_size: Option<u32>, |
333 | | |
334 | | #[serde( |
335 | | default, |
336 | | deserialize_with = "convert_optional_numeric_with_shellexpand" |
337 | | )] |
338 | | pub experimental_http2_max_concurrent_streams: Option<u32>, |
339 | | |
340 | | /// Note: This is in seconds. |
341 | | #[serde( |
342 | | default, |
343 | | deserialize_with = "convert_optional_numeric_with_shellexpand" |
344 | | )] |
345 | | pub experimental_http2_keep_alive_timeout: Option<u32>, |
346 | | |
347 | | #[serde( |
348 | | default, |
349 | | deserialize_with = "convert_optional_numeric_with_shellexpand" |
350 | | )] |
351 | | pub experimental_http2_max_send_buf_size: Option<u32>, |
352 | | |
353 | | #[serde(default)] |
354 | | pub experimental_http2_enable_connect_protocol: Option<bool>, |
355 | | |
356 | | #[serde( |
357 | | default, |
358 | | deserialize_with = "convert_optional_numeric_with_shellexpand" |
359 | | )] |
360 | | pub experimental_http2_max_header_list_size: Option<u32>, |
361 | | } |
362 | | |
363 | | #[allow(non_camel_case_types)] |
364 | 0 | #[derive(Deserialize, Debug)] |
365 | | pub enum ListenerConfig { |
366 | | /// Listener for HTTP/HTTPS/HTTP2 sockets. |
367 | | http(HttpListener), |
368 | | } |
369 | | |
370 | 0 | #[derive(Deserialize, Debug)] |
371 | | #[serde(deny_unknown_fields)] |
372 | | pub struct HttpListener { |
373 | | /// Address to listen on. Example: `127.0.0.1:8080` or `:8080` to listen |
374 | | /// to all IPs. |
375 | | #[serde(deserialize_with = "convert_string_with_shellexpand")] |
376 | | pub socket_address: String, |
377 | | |
378 | | /// Data transport compression configuration to use for this service. |
379 | | #[serde(default)] |
380 | | pub compression: HttpCompressionConfig, |
381 | | |
382 | | /// Advanced Http server configuration. |
383 | | #[serde(default)] |
384 | | pub advanced_http: HttpServerConfig, |
385 | | |
386 | | /// Tls Configuration for this server. |
387 | | /// If not set, the server will not use TLS. |
388 | | /// |
389 | | /// Default: None |
390 | | #[serde(default)] |
391 | | pub tls: Option<TlsConfig>, |
392 | | } |
393 | | |
394 | 0 | #[derive(Deserialize, Debug)] |
395 | | #[serde(deny_unknown_fields)] |
396 | | pub struct ServerConfig { |
397 | | /// Name of the server. This is used to help identify the service |
398 | | /// for telemetry and logs. |
399 | | /// |
400 | | /// Default: {index of server in config} |
401 | | #[serde(default, deserialize_with = "convert_string_with_shellexpand")] |
402 | | pub name: String, |
403 | | |
404 | | /// Configuration |
405 | | pub listener: ListenerConfig, |
406 | | |
407 | | /// Services to attach to server. |
408 | | pub services: Option<ServicesConfig>, |
409 | | } |
410 | | |
411 | | #[allow(non_camel_case_types)] |
412 | 0 | #[derive(Deserialize, Debug)] |
413 | | pub enum WorkerProperty { |
414 | | /// List of static values. |
415 | | /// Note: Generally there should only ever be 1 value, but if the platform |
416 | | /// property key is `PropertyType::Priority` it may have more than one value. |
417 | | #[serde(deserialize_with = "convert_vec_string_with_shellexpand")] |
418 | | values(Vec<String>), |
419 | | |
420 | | /// A dynamic configuration. The string will be executed as a command |
421 | | /// (not sell) and will be split by "\n" (new line character). |
422 | | query_cmd(String), |
423 | | } |
424 | | |
425 | | /// Generic config for an endpoint and associated configs. |
426 | 0 | #[derive(Deserialize, Debug, Default)] |
427 | | #[serde(deny_unknown_fields)] |
428 | | pub struct EndpointConfig { |
429 | | /// URI of the endpoint. |
430 | | #[serde(deserialize_with = "convert_string_with_shellexpand")] |
431 | | pub uri: String, |
432 | | |
433 | | /// Timeout in seconds that a request should take. |
434 | | /// Default: 5 (seconds) |
435 | | pub timeout: Option<f32>, |
436 | | |
437 | | /// The TLS configuration to use to connect to the endpoint. |
438 | | pub tls_config: Option<ClientTlsConfig>, |
439 | | } |
440 | | |
441 | | #[allow(non_camel_case_types)] |
442 | 0 | #[derive(Copy, Clone, Deserialize, Debug, Default)] |
443 | | pub enum UploadCacheResultsStrategy { |
444 | | /// Only upload action results with an exit code of 0. |
445 | | #[default] |
446 | | success_only, |
447 | | |
448 | | /// Don't upload any action results. |
449 | | never, |
450 | | |
451 | | /// Upload all action results that complete. |
452 | | everything, |
453 | | |
454 | | /// Only upload action results that fail. |
455 | | failures_only, |
456 | | } |
457 | | |
458 | | #[allow(non_camel_case_types)] |
459 | 0 | #[derive(Clone, Deserialize, Debug)] |
460 | | pub enum EnvironmentSource { |
461 | | /// The name of the platform property in the action to get the value from. |
462 | | property(String), |
463 | | |
464 | | /// The raw value to set. |
465 | | value(#[serde(deserialize_with = "convert_string_with_shellexpand")] String), |
466 | | |
467 | | /// The max amount of time in milliseconds the command is allowed to run |
468 | | /// (requested by the client). |
469 | | timeout_millis, |
470 | | |
471 | | /// A special file path will be provided that can be used to communicate |
472 | | /// with the parent process about out-of-band information. This file |
473 | | /// will be read after the command has finished executing. Based on the |
474 | | /// contents of the file, the behavior of the result may be modified. |
475 | | /// |
476 | | /// The format of the file contents should be json with the following |
477 | | /// schema: |
478 | | /// { |
479 | | /// // If set the command will be considered a failure. |
480 | | /// // May be one of the following static strings: |
481 | | /// // "timeout": Will Consider this task to be a timeout. |
482 | | /// "failure": "timeout", |
483 | | /// } |
484 | | /// |
485 | | /// All fields are optional, file does not need to be created and may be |
486 | | /// empty. |
487 | | side_channel_file, |
488 | | |
489 | | /// A "root" directory for the action. This directory can be used to |
490 | | /// store temporary files that are not needed after the action has |
491 | | /// completed. This directory will be purged after the action has |
492 | | /// completed. |
493 | | /// |
494 | | /// For example: |
495 | | /// If an action writes temporary data to a path but nativelink should |
496 | | /// clean up this path after the job has executed, you may create any |
497 | | /// directory under the path provided in this variable. A common pattern |
498 | | /// would be to use `entrypoint` to set a shell script that reads this |
499 | | /// variable, `mkdir $ENV_VAR_NAME/tmp` and `export TMPDIR=$ENV_VAR_NAME/tmp`. |
500 | | /// Another example might be to bind-mount the `/tmp` path in a container to |
501 | | /// this path in `entrypoint`. |
502 | | action_directory, |
503 | | } |
504 | | |
505 | 0 | #[derive(Deserialize, Debug, Default)] |
506 | | #[serde(deny_unknown_fields)] |
507 | | pub struct UploadActionResultConfig { |
508 | | /// Underlying AC store that the worker will use to publish execution results |
509 | | /// into. Objects placed in this store should be reachable from the |
510 | | /// scheduler/client-cas after they have finished updating. |
511 | | /// Default: {No uploading is done} |
512 | | pub ac_store: Option<StoreRefName>, |
513 | | |
514 | | /// In which situations should the results be published to the `ac_store`, |
515 | | /// if set to `SuccessOnly` then only results with an exit code of 0 will be |
516 | | /// uploaded, if set to Everything all completed results will be uploaded. |
517 | | /// |
518 | | /// Default: `UploadCacheResultsStrategy::SuccessOnly` |
519 | | #[serde(default)] |
520 | | pub upload_ac_results_strategy: UploadCacheResultsStrategy, |
521 | | |
522 | | /// Store to upload historical results to. This should be a CAS store if set. |
523 | | /// |
524 | | /// Default: {CAS store of parent} |
525 | | pub historical_results_store: Option<StoreRefName>, |
526 | | |
527 | | /// In which situations should the results be published to the historical CAS. |
528 | | /// The historical CAS is where failures are published. These messages conform |
529 | | /// to the CAS key-value lookup format and are always a `HistoricalExecuteResponse` |
530 | | /// serialized message. |
531 | | /// |
532 | | /// Default: `UploadCacheResultsStrategy::FailuresOnly` |
533 | | #[serde(default)] |
534 | | pub upload_historical_results_strategy: Option<UploadCacheResultsStrategy>, |
535 | | |
536 | | /// Template to use for the `ExecuteResponse.message` property. This message |
537 | | /// is attached to the response before it is sent to the client. The following |
538 | | /// special variables are supported: |
539 | | /// - `digest_function`: Digest function used to calculate the action digest. |
540 | | /// - `action_digest_hash`: Action digest hash. |
541 | | /// - `action_digest_size`: Action digest size. |
542 | | /// - `historical_results_hash`: `HistoricalExecuteResponse` digest hash. |
543 | | /// - `historical_results_size`: `HistoricalExecuteResponse` digest size. |
544 | | /// |
545 | | /// A common use case of this is to provide a link to the web page that |
546 | | /// contains more useful information for the user. |
547 | | /// |
548 | | /// An example that is fully compatible with `bb_browser` is: |
549 | | /// <https://example.com/my-instance-name-here/blobs/{digest_function}/action/{action_digest_hash}-{action_digest_size}/> |
550 | | /// |
551 | | /// Default: "" (no message) |
552 | | #[serde(default, deserialize_with = "convert_string_with_shellexpand")] |
553 | | pub success_message_template: String, |
554 | | |
555 | | /// Same as `success_message_template` but for failure case. |
556 | | /// |
557 | | /// An example that is fully compatible with `bb_browser` is: |
558 | | /// <https://example.com/my-instance-name-here/blobs/{digest_function}/historical_execute_response/{historical_results_hash}-{historical_results_size}/> |
559 | | /// |
560 | | /// Default: "" (no message) |
561 | | #[serde(default, deserialize_with = "convert_string_with_shellexpand")] |
562 | | pub failure_message_template: String, |
563 | | } |
564 | | |
565 | 0 | #[derive(Deserialize, Debug, Default)] |
566 | | #[serde(deny_unknown_fields)] |
567 | | pub struct LocalWorkerConfig { |
568 | | /// Name of the worker. This is give a more friendly name to a worker for logging |
569 | | /// and metric publishing. |
570 | | /// Default: {Index position in the workers list} |
571 | | #[serde(default, deserialize_with = "convert_string_with_shellexpand")] |
572 | | pub name: String, |
573 | | |
574 | | /// Endpoint which the worker will connect to the scheduler's `WorkerApiService`. |
575 | | pub worker_api_endpoint: EndpointConfig, |
576 | | |
577 | | /// The maximum time an action is allowed to run. If a task requests for a timeout |
578 | | /// longer than this time limit, the task will be rejected. Value in seconds. |
579 | | /// |
580 | | /// Default: 1200 (seconds / 20 mins) |
581 | | #[serde(default, deserialize_with = "convert_duration_with_shellexpand")] |
582 | | pub max_action_timeout: usize, |
583 | | |
584 | | /// If timeout is handled in `entrypoint` or another wrapper script. |
585 | | /// If set to true `NativeLink` will not honor the timeout the action requested |
586 | | /// and instead will always force kill the action after `max_action_timeout` |
587 | | /// has been reached. If this is set to false, the smaller value of the action's |
588 | | /// timeout and `max_action_timeout` will be used to which `NativeLink` will kill |
589 | | /// the action. |
590 | | /// |
591 | | /// The real timeout can be received via an environment variable set in: |
592 | | /// `EnvironmentSource::TimeoutMillis`. |
593 | | /// |
594 | | /// Example on where this is useful: `entrypoint` launches the action inside |
595 | | /// a docker container, but the docker container may need to be downloaded. Thus |
596 | | /// the timer should not start until the docker container has started executing |
597 | | /// the action. In this case, action will likely be wrapped in another program, |
598 | | /// like `timeout` and propagate timeouts via `EnvironmentSource::SideChannelFile`. |
599 | | /// |
600 | | /// Default: false (`NativeLink` fully handles timeouts) |
601 | | #[serde(default)] |
602 | | pub timeout_handled_externally: bool, |
603 | | |
604 | | /// The command to execute on every execution request. This will be parsed as |
605 | | /// a command + arguments (not shell). |
606 | | /// Example: "run.sh" and a job with command: "sleep 5" will result in a |
607 | | /// command like: "run.sh sleep 5". |
608 | | /// Default: {Use the command from the job request}. |
609 | | #[serde(default, deserialize_with = "convert_string_with_shellexpand")] |
610 | | pub entrypoint: String, |
611 | | |
612 | | /// An optional script to run before every action is processed on the worker. |
613 | | /// The value should be the full path to the script to execute and will pause |
614 | | /// all actions on the worker if it returns an exit code other than 0. |
615 | | /// If not set, then the worker will never pause and will continue to accept |
616 | | /// jobs according to the scheduler configuration. |
617 | | /// This is useful, for example, if the worker should not take any more |
618 | | /// actions until there is enough resource available on the machine to |
619 | | /// handle them. |
620 | | pub experimental_precondition_script: Option<String>, |
621 | | |
622 | | /// Underlying CAS store that the worker will use to download CAS artifacts. |
623 | | /// This store must be a `FastSlowStore`. The `fast` store must be a |
624 | | /// `FileSystemStore` because it will use hardlinks when building out the files |
625 | | /// instead of copying the files. The slow store must eventually resolve to the |
626 | | /// same store the scheduler/client uses to send job requests. |
627 | | #[serde(deserialize_with = "convert_string_with_shellexpand")] |
628 | | pub cas_fast_slow_store: StoreRefName, |
629 | | |
630 | | /// Configuration for uploading action results. |
631 | | #[serde(default)] |
632 | | pub upload_action_result: UploadActionResultConfig, |
633 | | |
634 | | /// The directory work jobs will be executed from. This directory will be fully |
635 | | /// managed by the worker service and will be purged on startup. |
636 | | /// This directory and the directory referenced in `local_filesystem_store_ref`'s |
637 | | /// `stores::FilesystemStore::content_path` must be on the same filesystem. |
638 | | /// Hardlinks will be used when placing files that are accessible to the jobs |
639 | | /// that are sourced from `local_filesystem_store_ref`'s `content_path`. |
640 | | #[serde(deserialize_with = "convert_string_with_shellexpand")] |
641 | | pub work_directory: String, |
642 | | |
643 | | /// Properties of this worker. This configuration will be sent to the scheduler |
644 | | /// and used to tell the scheduler to restrict what should be executed on this |
645 | | /// worker. |
646 | | pub platform_properties: HashMap<String, WorkerProperty>, |
647 | | |
648 | | /// An optional mapping of environment names to set for the execution |
649 | | /// as well as those specified in the action itself. If set, will set each |
650 | | /// key as an environment variable before executing the job with the value |
651 | | /// of the environment variable being the value of the property of the |
652 | | /// action being executed of that name or the fixed value. |
653 | | pub additional_environment: Option<HashMap<String, EnvironmentSource>>, |
654 | | } |
655 | | |
656 | | #[allow(non_camel_case_types)] |
657 | 0 | #[derive(Deserialize, Debug)] |
658 | | pub enum WorkerConfig { |
659 | | /// A worker type that executes jobs locally on this machine. |
660 | | local(LocalWorkerConfig), |
661 | | } |
662 | | |
663 | 0 | #[derive(Deserialize, Debug, Clone, Copy)] |
664 | | #[serde(deny_unknown_fields)] |
665 | | pub struct GlobalConfig { |
666 | | /// Maximum number of open files that can be opened at one time. |
667 | | /// This value is not strictly enforced, it is a best effort. Some internal libraries |
668 | | /// open files or read metadata from a files which do not obey this limit, however |
669 | | /// the vast majority of cases will have this limit be honored. |
670 | | /// As a rule of thumb this value should be less than half the value of `ulimit -n`. |
671 | | /// Any network open file descriptors is not counted in this limit, but is counted |
672 | | /// in the kernel limit. It is a good idea to set a very large `ulimit -n`. |
673 | | /// Note: This value must be greater than 10. |
674 | | /// |
675 | | /// Default: 512 |
676 | | #[serde(deserialize_with = "convert_numeric_with_shellexpand")] |
677 | | pub max_open_files: usize, |
678 | | |
679 | | /// If a file descriptor is idle for this many milliseconds, it will be closed. |
680 | | /// In the event a client or store takes a long time to send or receive data |
681 | | /// the file descriptor will be closed, and since `max_open_files` blocks new |
682 | | /// `open_file` requests until a slot opens up, it will allow new requests to be |
683 | | /// processed. If a read or write is attempted on a closed file descriptor, the |
684 | | /// file will be reopened and the operation will continue. |
685 | | /// |
686 | | /// On services where worker(s) and scheduler(s) live in the same process, this |
687 | | /// also prevents deadlocks if a file->file copy is happening, but cannot open |
688 | | /// a new file descriptor because the limit has been reached. |
689 | | /// |
690 | | /// Default: 1000 (1 second) |
691 | | #[serde(default, deserialize_with = "convert_duration_with_shellexpand")] |
692 | | pub idle_file_descriptor_timeout_millis: u64, |
693 | | |
694 | | /// This flag can be used to prevent metrics from being collected at runtime. |
695 | | /// Metrics are still able to be collected, but this flag prevents metrics that |
696 | | /// are collected at runtime (performance metrics) from being tallied. The |
697 | | /// overhead of collecting metrics is very low, so this flag should only be |
698 | | /// used if there is a very good reason to disable metrics. |
699 | | /// This flag can be forcibly set using the `NATIVELINK_DISABLE_METRICS` variable. |
700 | | /// If the variable is set it will always disable metrics regardless of what |
701 | | /// this flag is set to. |
702 | | /// |
703 | | /// Default: <true (disabled) if no prometheus service enabled, false otherwise> |
704 | | #[serde(default)] |
705 | | pub disable_metrics: bool, |
706 | | |
707 | | /// Default hash function to use while uploading blobs to the CAS when not set |
708 | | /// by client. |
709 | | /// |
710 | | /// Default: `ConfigDigestHashFunction::sha256` |
711 | | pub default_digest_hash_function: Option<ConfigDigestHashFunction>, |
712 | | |
713 | | /// Default digest size to use for health check when running |
714 | | /// diagnostics checks. Health checks are expected to use this |
715 | | /// size for filling a buffer that is used for creation of |
716 | | /// digest. |
717 | | /// |
718 | | /// Default: 1024*1024 (1MiB) |
719 | | #[serde(default, deserialize_with = "convert_data_size_with_shellexpand")] |
720 | | pub default_digest_size_health_check: usize, |
721 | | } |
722 | | |
723 | 0 | #[derive(Deserialize, Debug)] |
724 | | #[serde(deny_unknown_fields)] |
725 | | pub struct CasConfig { |
726 | | /// List of stores available to use in this config. |
727 | | /// The keys can be used in other configs when needing to reference a store. |
728 | | pub stores: HashMap<StoreRefName, StoreSpec>, |
729 | | |
730 | | /// Worker configurations used to execute jobs. |
731 | | pub workers: Option<Vec<WorkerConfig>>, |
732 | | |
733 | | /// List of schedulers available to use in this config. |
734 | | /// The keys can be used in other configs when needing to reference a |
735 | | /// scheduler. |
736 | | pub schedulers: Option<HashMap<SchedulerRefName, SchedulerSpec>>, |
737 | | |
738 | | /// Servers to setup for this process. |
739 | | pub servers: Vec<ServerConfig>, |
740 | | |
741 | | /// Any global configurations that apply to all modules live here. |
742 | | pub global: Option<GlobalConfig>, |
743 | | } |