Coverage Report

Created: 2025-04-19 16:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/build/source/nativelink-config/src/cas_server.rs
Line
Count
Source
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
#[derive(Deserialize, Debug, Default, Clone, Copy)]
36
#[serde(rename_all = "snake_case")]
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
#[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
#[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
#[derive(Deserialize, Debug, Clone, Copy)]
133
#[serde(deny_unknown_fields)]
134
pub struct FetchConfig {}
135
136
#[derive(Deserialize, Debug, Clone, Copy)]
137
#[serde(deny_unknown_fields)]
138
pub struct PushConfig {}
139
140
0
#[derive(Deserialize, Debug, Default)]
141
#[serde(deny_unknown_fields)]
142
pub struct ByteStreamConfig {
143
    /// Name of the store in the "stores" configuration.
144
    pub cas_stores: HashMap<InstanceName, StoreRefName>,
145
146
    /// Max number of bytes to send on each grpc stream chunk.
147
    /// According to <https://github.com/grpc/grpc.github.io/issues/371>
148
    /// 16KiB - 64KiB is optimal.
149
    ///
150
    ///
151
    /// Default: 64KiB
152
    #[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
153
    pub max_bytes_per_stream: usize,
154
155
    /// Maximum number of bytes to decode on each grpc stream chunk.
156
    /// Default: 4 MiB
157
    #[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
158
    pub max_decoding_message_size: usize,
159
160
    /// In the event a client disconnects while uploading a blob, we will hold
161
    /// the internal stream open for this many seconds before closing it.
162
    /// This allows clients that disconnect to reconnect and continue uploading
163
    /// the same blob.
164
    ///
165
    /// Default: 10 (seconds)
166
    #[serde(default, deserialize_with = "convert_duration_with_shellexpand")]
167
    pub persist_stream_on_disconnect_timeout: usize,
168
}
169
170
0
#[derive(Deserialize, Debug)]
171
#[serde(deny_unknown_fields)]
172
pub struct WorkerApiConfig {
173
    /// The scheduler name referenced in the `schedulers` map in the main config.
174
    #[serde(deserialize_with = "convert_string_with_shellexpand")]
175
    pub scheduler: SchedulerRefName,
176
}
177
178
#[derive(Deserialize, Debug, Default)]
179
#[serde(deny_unknown_fields)]
180
pub struct AdminConfig {
181
    /// Path to register the admin API. If path is "/admin", and your
182
    /// domain is "example.com", you can reach the endpoint with:
183
    /// <http://example.com/admin>.
184
    ///
185
    /// Default: "/admin"
186
    #[serde(default)]
187
    pub path: String,
188
}
189
190
#[derive(Deserialize, Debug, Default)]
191
#[serde(deny_unknown_fields)]
192
pub struct HealthConfig {
193
    /// Path to register the health status check. If path is "/status", and your
194
    /// domain is "example.com", you can reach the endpoint with:
195
    /// <http://example.com/status>.
196
    ///
197
    /// Default: "/status"
198
    #[serde(default)]
199
    pub path: String,
200
}
201
202
0
#[derive(Deserialize, Debug)]
203
pub struct BepConfig {
204
    /// The store to publish build events to.
205
    /// The store name referenced in the `stores` map in the main config.
206
    #[serde(deserialize_with = "convert_string_with_shellexpand")]
207
    pub store: StoreRefName,
208
}
209
210
0
#[derive(Deserialize, Clone, Debug, Default)]
211
pub struct IdentityHeaderSpec {
212
    /// The name of the header to look for the identity in.
213
    /// Default: "x-identity"
214
    #[serde(default, deserialize_with = "convert_optional_string_with_shellexpand")]
215
    pub header_name: Option<String>,
216
217
    /// If the header is required to be set or fail the request.
218
    #[serde(default)]
219
    pub required: bool,
220
}
221
222
0
#[derive(Deserialize, Clone, Debug)]
223
pub struct OriginEventsPublisherSpec {
224
    /// The store to publish nativelink events to.
225
    /// The store name referenced in the `stores` map in the main config.
226
    #[serde(deserialize_with = "convert_string_with_shellexpand")]
227
    pub store: StoreRefName,
228
}
229
230
0
#[derive(Deserialize, Clone, Debug)]
231
pub struct OriginEventsSpec {
232
    /// The publisher configuration for origin events.
233
    pub publisher: OriginEventsPublisherSpec,
234
235
    /// The maximum number of events to queue before applying back pressure.
236
    /// IMPORTANT: Backpressure causes all clients to slow down significantly.
237
    /// Zero is default.
238
    ///
239
    /// Default: 65536 (zero defaults to this)
240
    #[serde(default, deserialize_with = "convert_numeric_with_shellexpand")]
241
    pub max_event_queue_size: usize,
242
}
243
244
#[derive(Deserialize, Debug)]
245
#[serde(deny_unknown_fields)]
246
pub struct ServicesConfig {
247
    /// The Content Addressable Storage (CAS) backend config.
248
    /// The key is the `instance_name` used in the protocol and the
249
    /// value is the underlying CAS store config.
250
    pub cas: Option<HashMap<InstanceName, CasStoreConfig>>,
251
252
    /// The Action Cache (AC) backend config.
253
    /// The key is the `instance_name` used in the protocol and the
254
    /// value is the underlying AC store config.
255
    pub ac: Option<HashMap<InstanceName, AcStoreConfig>>,
256
257
    /// Capabilities service is required in order to use most of the
258
    /// bazel protocol. This service is used to provide the supported
259
    /// features and versions of this bazel GRPC service.
260
    pub capabilities: Option<HashMap<InstanceName, CapabilitiesConfig>>,
261
262
    /// The remote execution service configuration.
263
    /// NOTE: This service is under development and is currently just a
264
    /// place holder.
265
    pub execution: Option<HashMap<InstanceName, ExecutionConfig>>,
266
267
    /// This is the service used to stream data to and from the CAS.
268
    /// Bazel's protocol strongly encourages users to use this streaming
269
    /// interface to interact with the CAS when the data is large.
270
    pub bytestream: Option<ByteStreamConfig>,
271
272
    /// These two are collectively the Remote Asset protocol, but it's
273
    /// defined as two separate services
274
    pub fetch: Option<FetchConfig>,
275
    pub push: Option<PushConfig>,
276
277
    /// This is the service used for workers to connect and communicate
278
    /// through.
279
    /// NOTE: This service should be served on a different, non-public port.
280
    /// In other words, `worker_api` configuration should not have any other
281
    /// services that are served on the same port. Doing so is a security
282
    /// risk, as workers have a different permission set than a client
283
    /// that makes the remote execution/cache requests.
284
    pub worker_api: Option<WorkerApiConfig>,
285
286
    /// Experimental - Build Event Protocol (BEP) configuration. This is
287
    /// the service that will consume build events from the client and
288
    /// publish them to a store for processing by an external service.
289
    pub experimental_bep: Option<BepConfig>,
290
291
    /// This is the service for any administrative tasks.
292
    /// It provides a REST API endpoint for administrative purposes.
293
    pub admin: Option<AdminConfig>,
294
295
    /// This is the service for health status check.
296
    pub health: Option<HealthConfig>,
297
}
298
299
0
#[derive(Deserialize, Debug)]
300
#[serde(deny_unknown_fields)]
301
pub struct TlsConfig {
302
    /// Path to the certificate file.
303
    #[serde(deserialize_with = "convert_string_with_shellexpand")]
304
    pub cert_file: String,
305
306
    /// Path to the private key file.
307
    #[serde(deserialize_with = "convert_string_with_shellexpand")]
308
    pub key_file: String,
309
310
    /// Path to the certificate authority for mTLS, if client authentication is
311
    /// required for this endpoint.
312
    #[serde(default, deserialize_with = "convert_optional_string_with_shellexpand")]
313
    pub client_ca_file: Option<String>,
314
315
    /// Path to the certificate revocation list for mTLS, if client
316
    /// authentication is required for this endpoint.
317
    #[serde(default, deserialize_with = "convert_optional_string_with_shellexpand")]
318
    pub client_crl_file: Option<String>,
319
}
320
321
/// Advanced Http configurations. These are generally should not be set.
322
/// For documentation on what each of these do, see the hyper documentation:
323
/// See: <https://docs.rs/hyper/latest/hyper/server/conn/struct.Http.html>
324
///
325
/// Note: All of these default to hyper's default values unless otherwise
326
/// specified.
327
0
#[derive(Deserialize, Debug, Default, Clone, Copy)]
328
#[serde(deny_unknown_fields)]
329
pub struct HttpServerConfig {
330
    /// Interval to send keep-alive pings via HTTP2.
331
    /// Note: This is in seconds.
332
    #[serde(
333
        default,
334
        deserialize_with = "convert_optional_numeric_with_shellexpand"
335
    )]
336
    pub http2_keep_alive_interval: Option<u32>,
337
338
    #[serde(
339
        default,
340
        deserialize_with = "convert_optional_numeric_with_shellexpand"
341
    )]
342
    pub experimental_http2_max_pending_accept_reset_streams: Option<u32>,
343
344
    #[serde(
345
        default,
346
        deserialize_with = "convert_optional_numeric_with_shellexpand"
347
    )]
348
    pub experimental_http2_initial_stream_window_size: Option<u32>,
349
350
    #[serde(
351
        default,
352
        deserialize_with = "convert_optional_numeric_with_shellexpand"
353
    )]
354
    pub experimental_http2_initial_connection_window_size: Option<u32>,
355
356
    #[serde(default)]
357
    pub experimental_http2_adaptive_window: Option<bool>,
358
359
    #[serde(
360
        default,
361
        deserialize_with = "convert_optional_numeric_with_shellexpand"
362
    )]
363
    pub experimental_http2_max_frame_size: Option<u32>,
364
365
    #[serde(
366
        default,
367
        deserialize_with = "convert_optional_numeric_with_shellexpand"
368
    )]
369
    pub experimental_http2_max_concurrent_streams: Option<u32>,
370
371
    /// Note: This is in seconds.
372
    #[serde(
373
        default,
374
        deserialize_with = "convert_optional_numeric_with_shellexpand"
375
    )]
376
    pub experimental_http2_keep_alive_timeout: Option<u32>,
377
378
    #[serde(
379
        default,
380
        deserialize_with = "convert_optional_numeric_with_shellexpand"
381
    )]
382
    pub experimental_http2_max_send_buf_size: Option<u32>,
383
384
    #[serde(default)]
385
    pub experimental_http2_enable_connect_protocol: Option<bool>,
386
387
    #[serde(
388
        default,
389
        deserialize_with = "convert_optional_numeric_with_shellexpand"
390
    )]
391
    pub experimental_http2_max_header_list_size: Option<u32>,
392
}
393
394
#[derive(Deserialize, Debug)]
395
#[serde(rename_all = "snake_case")]
396
pub enum ListenerConfig {
397
    /// Listener for HTTP/HTTPS/HTTP2 sockets.
398
    Http(HttpListener),
399
}
400
401
0
#[derive(Deserialize, Debug)]
402
#[serde(deny_unknown_fields)]
403
pub struct HttpListener {
404
    /// Address to listen on. Example: `127.0.0.1:8080` or `:8080` to listen
405
    /// to all IPs.
406
    #[serde(deserialize_with = "convert_string_with_shellexpand")]
407
    pub socket_address: String,
408
409
    /// Data transport compression configuration to use for this service.
410
    #[serde(default)]
411
    pub compression: HttpCompressionConfig,
412
413
    /// Advanced Http server configuration.
414
    #[serde(default)]
415
    pub advanced_http: HttpServerConfig,
416
417
    /// Tls Configuration for this server.
418
    /// If not set, the server will not use TLS.
419
    ///
420
    /// Default: None
421
    #[serde(default)]
422
    pub tls: Option<TlsConfig>,
423
}
424
425
0
#[derive(Deserialize, Debug)]
426
#[serde(deny_unknown_fields)]
427
pub struct ServerConfig {
428
    /// Name of the server. This is used to help identify the service
429
    /// for telemetry and logs.
430
    ///
431
    /// Default: {index of server in config}
432
    #[serde(default, deserialize_with = "convert_string_with_shellexpand")]
433
    pub name: String,
434
435
    /// Configuration
436
    pub listener: ListenerConfig,
437
438
    /// Services to attach to server.
439
    pub services: Option<ServicesConfig>,
440
441
    /// The config related to identifying the client.
442
    /// Default: {see `IdentityHeaderSpec`}
443
    #[serde(default)]
444
    pub experimental_identity_header: IdentityHeaderSpec,
445
}
446
447
0
#[derive(Deserialize, Debug)]
448
#[serde(rename_all = "snake_case")]
449
pub enum WorkerProperty {
450
    /// List of static values.
451
    /// Note: Generally there should only ever be 1 value, but if the platform
452
    /// property key is `PropertyType::Priority` it may have more than one value.
453
    #[serde(deserialize_with = "convert_vec_string_with_shellexpand")]
454
    Values(Vec<String>),
455
456
    /// A dynamic configuration. The string will be executed as a command
457
    /// (not sell) and will be split by "\n" (new line character).
458
    QueryCmd(String),
459
}
460
461
/// Generic config for an endpoint and associated configs.
462
0
#[derive(Deserialize, Debug, Default)]
463
#[serde(deny_unknown_fields)]
464
pub struct EndpointConfig {
465
    /// URI of the endpoint.
466
    #[serde(deserialize_with = "convert_string_with_shellexpand")]
467
    pub uri: String,
468
469
    /// Timeout in seconds that a request should take.
470
    /// Default: 5 (seconds)
471
    pub timeout: Option<f32>,
472
473
    /// The TLS configuration to use to connect to the endpoint.
474
    pub tls_config: Option<ClientTlsConfig>,
475
}
476
477
#[derive(Copy, Clone, Deserialize, Debug, Default)]
478
#[serde(rename_all = "snake_case")]
479
pub enum UploadCacheResultsStrategy {
480
    /// Only upload action results with an exit code of 0.
481
    #[default]
482
    SuccessOnly,
483
484
    /// Don't upload any action results.
485
    Never,
486
487
    /// Upload all action results that complete.
488
    Everything,
489
490
    /// Only upload action results that fail.
491
    FailuresOnly,
492
}
493
494
0
#[derive(Clone, Deserialize, Debug)]
495
#[serde(rename_all = "snake_case")]
496
pub enum EnvironmentSource {
497
    /// The name of the platform property in the action to get the value from.
498
    Property(String),
499
500
    /// The raw value to set.
501
    Value(#[serde(deserialize_with = "convert_string_with_shellexpand")] String),
502
503
    /// The max amount of time in milliseconds the command is allowed to run
504
    /// (requested by the client).
505
    TimeoutMillis,
506
507
    /// A special file path will be provided that can be used to communicate
508
    /// with the parent process about out-of-band information. This file
509
    /// will be read after the command has finished executing. Based on the
510
    /// contents of the file, the behavior of the result may be modified.
511
    ///
512
    /// The format of the file contents should be json with the following
513
    /// schema:
514
    /// {
515
    ///   // If set the command will be considered a failure.
516
    ///   // May be one of the following static strings:
517
    ///   // "timeout": Will Consider this task to be a timeout.
518
    ///   "failure": "timeout",
519
    /// }
520
    ///
521
    /// All fields are optional, file does not need to be created and may be
522
    /// empty.
523
    SideChannelFile,
524
525
    /// A "root" directory for the action. This directory can be used to
526
    /// store temporary files that are not needed after the action has
527
    /// completed. This directory will be purged after the action has
528
    /// completed.
529
    ///
530
    /// For example:
531
    /// If an action writes temporary data to a path but nativelink should
532
    /// clean up this path after the job has executed, you may create any
533
    /// directory under the path provided in this variable. A common pattern
534
    /// would be to use `entrypoint` to set a shell script that reads this
535
    /// variable, `mkdir $ENV_VAR_NAME/tmp` and `export TMPDIR=$ENV_VAR_NAME/tmp`.
536
    /// Another example might be to bind-mount the `/tmp` path in a container to
537
    /// this path in `entrypoint`.
538
    ActionDirectory,
539
}
540
541
0
#[derive(Deserialize, Debug, Default)]
542
#[serde(deny_unknown_fields)]
543
pub struct UploadActionResultConfig {
544
    /// Underlying AC store that the worker will use to publish execution results
545
    /// into. Objects placed in this store should be reachable from the
546
    /// scheduler/client-cas after they have finished updating.
547
    /// Default: {No uploading is done}
548
    pub ac_store: Option<StoreRefName>,
549
550
    /// In which situations should the results be published to the `ac_store`,
551
    /// if set to `SuccessOnly` then only results with an exit code of 0 will be
552
    /// uploaded, if set to Everything all completed results will be uploaded.
553
    ///
554
    /// Default: `UploadCacheResultsStrategy::SuccessOnly`
555
    #[serde(default)]
556
    pub upload_ac_results_strategy: UploadCacheResultsStrategy,
557
558
    /// Store to upload historical results to. This should be a CAS store if set.
559
    ///
560
    /// Default: {CAS store of parent}
561
    pub historical_results_store: Option<StoreRefName>,
562
563
    /// In which situations should the results be published to the historical CAS.
564
    /// The historical CAS is where failures are published. These messages conform
565
    /// to the CAS key-value lookup format and are always a `HistoricalExecuteResponse`
566
    /// serialized message.
567
    ///
568
    /// Default: `UploadCacheResultsStrategy::FailuresOnly`
569
    #[serde(default)]
570
    pub upload_historical_results_strategy: Option<UploadCacheResultsStrategy>,
571
572
    /// Template to use for the `ExecuteResponse.message` property. This message
573
    /// is attached to the response before it is sent to the client. The following
574
    /// special variables are supported:
575
    /// - `digest_function`: Digest function used to calculate the action digest.
576
    /// - `action_digest_hash`: Action digest hash.
577
    /// - `action_digest_size`: Action digest size.
578
    /// - `historical_results_hash`: `HistoricalExecuteResponse` digest hash.
579
    /// - `historical_results_size`: `HistoricalExecuteResponse` digest size.
580
    ///
581
    /// A common use case of this is to provide a link to the web page that
582
    /// contains more useful information for the user.
583
    ///
584
    /// An example that is fully compatible with `bb_browser` is:
585
    /// <https://example.com/my-instance-name-here/blobs/{digest_function}/action/{action_digest_hash}-{action_digest_size}/>
586
    ///
587
    /// Default: "" (no message)
588
    #[serde(default, deserialize_with = "convert_string_with_shellexpand")]
589
    pub success_message_template: String,
590
591
    /// Same as `success_message_template` but for failure case.
592
    ///
593
    /// An example that is fully compatible with `bb_browser` is:
594
    /// <https://example.com/my-instance-name-here/blobs/{digest_function}/historical_execute_response/{historical_results_hash}-{historical_results_size}/>
595
    ///
596
    /// Default: "" (no message)
597
    #[serde(default, deserialize_with = "convert_string_with_shellexpand")]
598
    pub failure_message_template: String,
599
}
600
601
0
#[derive(Deserialize, Debug, Default)]
602
#[serde(deny_unknown_fields)]
603
pub struct LocalWorkerConfig {
604
    /// Name of the worker. This is give a more friendly name to a worker for logging
605
    /// and metric publishing. This is also the prefix of the worker id
606
    /// (ie: "{name}{uuidv6}").
607
    /// Default: {Index position in the workers list}
608
    #[serde(default, deserialize_with = "convert_string_with_shellexpand")]
609
    pub name: String,
610
611
    /// Endpoint which the worker will connect to the scheduler's `WorkerApiService`.
612
    pub worker_api_endpoint: EndpointConfig,
613
614
    /// The maximum time an action is allowed to run. If a task requests for a timeout
615
    /// longer than this time limit, the task will be rejected. Value in seconds.
616
    ///
617
    /// Default: 1200 (seconds / 20 mins)
618
    #[serde(default, deserialize_with = "convert_duration_with_shellexpand")]
619
    pub max_action_timeout: usize,
620
621
    /// If timeout is handled in `entrypoint` or another wrapper script.
622
    /// If set to true `NativeLink` will not honor the timeout the action requested
623
    /// and instead will always force kill the action after `max_action_timeout`
624
    /// has been reached. If this is set to false, the smaller value of the action's
625
    /// timeout and `max_action_timeout` will be used to which `NativeLink` will kill
626
    /// the action.
627
    ///
628
    /// The real timeout can be received via an environment variable set in:
629
    /// `EnvironmentSource::TimeoutMillis`.
630
    ///
631
    /// Example on where this is useful: `entrypoint` launches the action inside
632
    /// a docker container, but the docker container may need to be downloaded. Thus
633
    /// the timer should not start until the docker container has started executing
634
    /// the action. In this case, action will likely be wrapped in another program,
635
    /// like `timeout` and propagate timeouts via `EnvironmentSource::SideChannelFile`.
636
    ///
637
    /// Default: false (`NativeLink` fully handles timeouts)
638
    #[serde(default)]
639
    pub timeout_handled_externally: bool,
640
641
    /// The command to execute on every execution request. This will be parsed as
642
    /// a command + arguments (not shell).
643
    /// Example: "run.sh" and a job with command: "sleep 5" will result in a
644
    /// command like: "run.sh sleep 5".
645
    /// Default: {Use the command from the job request}.
646
    #[serde(default, deserialize_with = "convert_string_with_shellexpand")]
647
    pub entrypoint: String,
648
649
    /// An optional script to run before every action is processed on the worker.
650
    /// The value should be the full path to the script to execute and will pause
651
    /// all actions on the worker if it returns an exit code other than 0.
652
    /// If not set, then the worker will never pause and will continue to accept
653
    /// jobs according to the scheduler configuration.
654
    /// This is useful, for example, if the worker should not take any more
655
    /// actions until there is enough resource available on the machine to
656
    /// handle them.
657
    pub experimental_precondition_script: Option<String>,
658
659
    /// Underlying CAS store that the worker will use to download CAS artifacts.
660
    /// This store must be a `FastSlowStore`. The `fast` store must be a
661
    /// `FileSystemStore` because it will use hardlinks when building out the files
662
    /// instead of copying the files. The slow store must eventually resolve to the
663
    /// same store the scheduler/client uses to send job requests.
664
    #[serde(deserialize_with = "convert_string_with_shellexpand")]
665
    pub cas_fast_slow_store: StoreRefName,
666
667
    /// Configuration for uploading action results.
668
    #[serde(default)]
669
    pub upload_action_result: UploadActionResultConfig,
670
671
    /// The directory work jobs will be executed from. This directory will be fully
672
    /// managed by the worker service and will be purged on startup.
673
    /// This directory and the directory referenced in `local_filesystem_store_ref`'s
674
    /// `stores::FilesystemStore::content_path` must be on the same filesystem.
675
    /// Hardlinks will be used when placing files that are accessible to the jobs
676
    /// that are sourced from `local_filesystem_store_ref`'s `content_path`.
677
    #[serde(deserialize_with = "convert_string_with_shellexpand")]
678
    pub work_directory: String,
679
680
    /// Properties of this worker. This configuration will be sent to the scheduler
681
    /// and used to tell the scheduler to restrict what should be executed on this
682
    /// worker.
683
    pub platform_properties: HashMap<String, WorkerProperty>,
684
685
    /// An optional mapping of environment names to set for the execution
686
    /// as well as those specified in the action itself.  If set, will set each
687
    /// key as an environment variable before executing the job with the value
688
    /// of the environment variable being the value of the property of the
689
    /// action being executed of that name or the fixed value.
690
    pub additional_environment: Option<HashMap<String, EnvironmentSource>>,
691
}
692
693
#[derive(Deserialize, Debug)]
694
#[serde(rename_all = "snake_case")]
695
pub enum WorkerConfig {
696
    /// A worker type that executes jobs locally on this machine.
697
    Local(LocalWorkerConfig),
698
}
699
700
0
#[derive(Deserialize, Debug, Clone, Copy)]
701
#[serde(deny_unknown_fields)]
702
pub struct GlobalConfig {
703
    /// Maximum number of open files that can be opened at one time.
704
    /// This value is not strictly enforced, it is a best effort. Some internal libraries
705
    /// open files or read metadata from a files which do not obey this limit, however
706
    /// the vast majority of cases will have this limit be honored.
707
    /// This value must be larger than `ulimit -n` to have any effect.
708
    /// Any network open file descriptors is not counted in this limit, but is counted
709
    /// in the kernel limit. It is a good idea to set a very large `ulimit -n`.
710
    /// Note: This value must be greater than 10.
711
    ///
712
    /// Default: 24576 (= 24 * 1024)
713
    #[serde(deserialize_with = "convert_numeric_with_shellexpand")]
714
    pub max_open_files: usize,
715
716
    /// Default hash function to use while uploading blobs to the CAS when not set
717
    /// by client.
718
    ///
719
    /// Default: `ConfigDigestHashFunction::sha256`
720
    pub default_digest_hash_function: Option<ConfigDigestHashFunction>,
721
722
    /// Default digest size to use for health check when running
723
    /// diagnostics checks. Health checks are expected to use this
724
    /// size for filling a buffer that is used for creation of
725
    /// digest.
726
    ///
727
    /// Default: 1024*1024 (1MiB)
728
    #[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
729
    pub default_digest_size_health_check: usize,
730
}
731
732
#[derive(Debug, Clone, Deserialize)]
733
pub struct NamedConfig<Spec> {
734
    pub name: String,
735
    #[serde(flatten)]
736
    pub spec: Spec,
737
}
738
739
pub type StoreConfig = NamedConfig<StoreSpec>;
740
pub type SchedulerConfig = NamedConfig<SchedulerSpec>;
741
742
#[derive(Deserialize, Debug)]
743
#[serde(deny_unknown_fields)]
744
pub struct CasConfig {
745
    /// List of stores available to use in this config.
746
    /// The keys can be used in other configs when needing to reference a store.
747
    pub stores: Vec<StoreConfig>,
748
749
    /// Worker configurations used to execute jobs.
750
    pub workers: Option<Vec<WorkerConfig>>,
751
752
    /// List of schedulers available to use in this config.
753
    /// The keys can be used in other configs when needing to reference a
754
    /// scheduler.
755
    pub schedulers: Option<Vec<SchedulerConfig>>,
756
757
    /// Servers to setup for this process.
758
    pub servers: Vec<ServerConfig>,
759
760
    /// Experimental - Origin events configuration. This is the service that will
761
    /// collect and publish nativelink events to a store for processing by an
762
    /// external service.
763
    pub experimental_origin_events: Option<OriginEventsSpec>,
764
765
    /// Any global configurations that apply to all modules live here.
766
    pub global: Option<GlobalConfig>,
767
}