forked from buildbarn/bb-clientd
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bb_clientd.jsonnet
260 lines (241 loc) · 9.42 KB
/
bb_clientd.jsonnet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
// List of clusters to which bb_clientd is permitted to connect.
local clusters = {
'mycluster-prod.example.com': 'api.mycluster-prod.example.com',
'mycluster-qa.example.com': 'api.mycluster-qa.example.com',
'mycluster-dev.example.com': 'api.mycluster-dev.example.com',
};
local grpcClient(hostname, authorizationHeader, proxyURL) = {
address: hostname + ':443',
tls: {},
[if authorizationHeader != null then 'addMetadata']: [
{ header: 'authorization', values: [authorizationHeader] },
],
addMetadataJmespathExpression: '{"build.bazel.remote.execution.v2.requestmetadata-bin": incomingGRPCMetadata."build.bazel.remote.execution.v2.requestmetadata-bin"}',
// Enable gRPC keepalives. Make sure to tune these settings based on
// what your cluster permits.
keepalive: {
time: '60s',
timeout: '30s',
},
proxyUrl: proxyURL,
};
// Route requests to one of the clusters listed above by parsing the
// prefix of the instance name. This prefix will be stripped on outgoing
// requests.
local blobstoreConfig(authorizationHeader, proxyURL) = {
demultiplexing: {
instanceNamePrefixes: {
[cluster]: { backend: {
grpc: grpcClient(clusters[cluster], authorizationHeader, proxyURL),
} }
for cluster in std.objectFields(clusters)
},
},
};
local homeDirectory = std.extVar('HOME');
local cacheDirectory = homeDirectory + '/.cache/bb_clientd';
{
// Options that users can override.
casKeyLocationMapSizeBytes:: 512 * 1024 * 1024,
casBlocksSizeBytes:: 100 * 1024 * 1024 * 1024,
filePoolSizeBytes:: 100 * 1024 * 1024 * 1024,
// Maximum supported Protobuf message size.
maximumMessageSizeBytes: 16 * 1024 * 1024,
maximumTreeSizeBytes: 256 * 1024 * 1024,
// When set, don't forward credentials from Bazel to clusters and
// office caches. Instead, use a static credentials in the form of a
// HTTP "Authorization" header.
authorizationHeader:: null,
// HTTP proxy to use for all outgoing requests not going to office caches.
proxyURL:: '',
// If enabled, use NFSv4 instead of FUSE.
useNFSv4:: std.extVar('OS') == 'Darwin',
// Backends for the Action Cache and Content Addressable Storage.
blobstore: {
actionCache: { demultiplexing: { instanceNamePrefixes: {
// Instance names starting with 'local' can be used to set up
// bb_clientd as a system-local cache.
'local': { backend: { 'local': {
keyLocationMapOnBlockDevice: { file: {
path: cacheDirectory + '/ac/key_location_map',
sizeBytes: 128 * 1024 * 1024,
} },
keyLocationMapMaximumGetAttempts: 8,
keyLocationMapMaximumPutAttempts: 32,
oldBlocks: 1,
currentBlocks: 5,
newBlocks: 1,
blocksOnBlockDevice: {
source: { file: {
path: cacheDirectory + '/ac/blocks',
sizeBytes: 1024 * 1024 * 1024,
} },
spareBlocks: 1,
},
persistent: {
stateDirectoryPath: cacheDirectory + '/ac/persistent_state',
minimumEpochInterval: '300s',
},
} } },
// Other instance names are assumed to correspond to remote clusters.
'': { backend: blobstoreConfig($.authorizationHeader, $.proxyURL) },
} } },
contentAddressableStorage: { withLabels: {
backend: { demultiplexing: { instanceNamePrefixes: {
// Instance names starting with 'local' can be used to use
// bb_clientd as a system-local cache.
'local': { backend: { label: 'localCAS' } },
// Other instance names are assumed to correspond to remote clusters.
'': { backend: { readCaching: {
slow: {
existenceCaching: {
backend: { label: 'clustersCAS' },
// Assume that if FindMissingBlobs() reports a blob as being
// present, it's going to stay around for five more minutes.
// This significantly reduces the combined size of
// FindMissingBlobs() calls generated by Bazel.
existenceCache: {
cacheSize: 1000 * 1000,
cacheDuration: '300s',
cacheReplacementPolicy: 'LEAST_RECENTLY_USED',
},
},
},
// On-disk cache to speed up access to recently used objects.
fast: { label: 'localCAS' },
replicator: {
deduplicating: {
// Bazel's -j flag not only affects the number of actions
// executed concurrently, it also influences the concurrency
// of ByteStream requests. Prevent starvation by limiting
// the number of requests that are forwarded when cache
// misses occur.
concurrencyLimiting: {
base: { 'local': {} },
maximumConcurrency: 100,
},
},
},
} } },
} } },
labels: {
// Let the local CAS consume up to 100 GiB of disk space. A 64
// MiB index is large enough to accomodate approximately one
// million objects.
localCAS: { 'local': {
keyLocationMapOnBlockDevice: { file: {
path: cacheDirectory + '/cas/key_location_map',
sizeBytes: $.casKeyLocationMapSizeBytes,
} },
keyLocationMapMaximumGetAttempts: 8,
keyLocationMapMaximumPutAttempts: 32,
oldBlocks: 1,
currentBlocks: 5,
newBlocks: 1,
blocksOnBlockDevice: {
source: { file: {
path: cacheDirectory + '/cas/blocks',
sizeBytes: $.casBlocksSizeBytes,
} },
spareBlocks: 1,
dataIntegrityValidationCache: {
cacheSize: 100000,
cacheDuration: '14400s',
cacheReplacementPolicy: 'LEAST_RECENTLY_USED',
},
},
persistent: {
stateDirectoryPath: cacheDirectory + '/cas/persistent_state',
minimumEpochInterval: '300s',
},
} },
clustersCAS: blobstoreConfig($.authorizationHeader, $.proxyURL),
},
} },
},
// Schedulers to which to route execution requests. This uses the same
// routing policy as the storage configuration above.
schedulers: {
[cluster]: {
endpoint: grpcClient(clusters[cluster], $.authorizationHeader, $.proxyURL),
}
for cluster in std.objectFields(clusters)
},
// A gRPC server to which Bazel can send requests, as opposed to
// contacting clusters directly. This allows bb_clientd to capture
// credentials.
grpcServers: [{
listenPaths: [cacheDirectory + '/grpc'],
authenticationPolicy: { allow: {} },
}],
// The FUSE or NFSv4 file system through which data stored in the
// Content Addressable Storage can be loaded lazily. This file system
// relies on credentials captured through gRPC.
mount: if $.useNFSv4 then {
mountPath: homeDirectory + '/bb_clientd',
nfsv4: {
enforcedLeaseTime: '120s',
announcedLeaseTime: '60s',
darwin: {
minimumDirectoriesAttributeCacheTimeout: '0s',
maximumDirectoriesAttributeCacheTimeout: '0s',
},
},
} else {
mountPath: homeDirectory + '/bb_clientd',
fuse: {
directoryEntryValidity: '300s',
inodeAttributeValidity: '300s',
// Enabling this option may be necessary if you want to permit
// super-user access to the FUSE file system. It is strongly
// recommended that the permissions on the parent directory of the
// FUSE file system are locked down before enabling this option.
allowOther: true,
},
},
// The location where locally created files in the "scratch" and
// "outputs" directories of the FUSE file system are stored. These
// files are not necessarily backed by remote storage.
filePool: { blockDevice: { file: {
path: cacheDirectory + '/filepool',
sizeBytes: $.filePoolSizeBytes,
} } },
// The location where contents of the "outputs" are stored, so that
// they may be restored after restarts of bb_clientd. Because data is
// stored densely, and only the metadata of files is stored (i.e.,
// REv2 digests), these files tend to be small.
outputPathPersistency: {
stateDirectoryPath: cacheDirectory + '/outputs',
maximumStateFileSizeBytes: 1024 * 1024 * 1024,
maximumStateFileAge: '604800s',
},
// Keep a small number of unmarshaled REv2 Directory objects in memory
// to speed up their instantiation under "outputs".
directoryCache: {
maximumCount: 10000,
maximumSizeBytes: 1024 * self.maximumCount,
cacheReplacementPolicy: 'LEAST_RECENTLY_USED',
},
// Retry read operations performed through the virtual file system.
// This prevents EIO errors in case of transient network issues.
maximumFileSystemRetryDelay: '300s',
global: {
// Multiplex logs into a file. That way they remain accessible, even
// if bb_clientd is run through a system that doesn't maintain logs
// for us.
logPaths: [cacheDirectory + '/log'],
// Attach credentials provided by Bazel to all outgoing gRPC calls.
[if $.authorizationHeader == null then 'grpcForwardAndReuseMetadata']: ['authorization'],
// Optional: create a HTTP server that exposes Prometheus metrics
// and allows debugging using pprof. Make sure to only enable it
// when you need it, or at least make sure that access is limited.
/*
diagnosticsHttpServer: {
listenAddress: '127.0.0.1:12345',
enablePrometheus: true,
enablePprof: true,
enableActiveSpans: true,
},
*/
},
}