Skip to content

Commit a7d4b05

Browse files
authored
Merge pull request #117 from depot/feat/report-cache-path
feat: report statistics of cache path
2 parents 9493448 + 74b0989 commit a7d4b05

File tree

7 files changed

+34
-62
lines changed

7 files changed

+34
-62
lines changed

proto/depot/cloud/v3/machine.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ message PingMachineHealthRequest {
121121
}
122122

123123
message DiskSpace {
124-
string device = 1;
124+
reserved 1;
125125
string path = 2;
126126
int64 free_mb = 3;
127127
int64 total_mb = 4;

src/gen/ts/depot/cloud/v3/machine_pb.ts

-6
Original file line numberDiff line numberDiff line change
@@ -794,11 +794,6 @@ export class PingMachineHealthRequest extends Message<PingMachineHealthRequest>
794794
* @generated from message depot.cloud.v3.DiskSpace
795795
*/
796796
export class DiskSpace extends Message<DiskSpace> {
797-
/**
798-
* @generated from field: string device = 1;
799-
*/
800-
device = ''
801-
802797
/**
803798
* @generated from field: string path = 2;
804799
*/
@@ -832,7 +827,6 @@ export class DiskSpace extends Message<DiskSpace> {
832827
static readonly runtime: typeof proto3 = proto3
833828
static readonly typeName = 'depot.cloud.v3.DiskSpace'
834829
static readonly fields: FieldList = proto3.util.newFieldList(() => [
835-
{no: 1, name: 'device', kind: 'scalar', T: 9 /* ScalarType.STRING */},
836830
{no: 2, name: 'path', kind: 'scalar', T: 9 /* ScalarType.STRING */},
837831
{no: 3, name: 'free_mb', kind: 'scalar', T: 3 /* ScalarType.INT64 */},
838832
{no: 4, name: 'total_mb', kind: 'scalar', T: 3 /* ScalarType.INT64 */},

src/tasks/buildkit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ keepBytes = ${cacheSizeBytes}
250250
try {
251251
await Promise.all([
252252
buildkit,
253-
reportHealth({machineId, signal, headers, mounts: task.mounts}),
253+
reportHealth({machineId, signal, headers, path: '/var/lib/buildkit'}),
254254
reportUsage({machineId, signal, headers}),
255255
])
256256
} catch (error) {

src/tasks/engine.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export async function startEngine(message: RegisterMachineResponse, task: Regist
110110
try {
111111
await Promise.all([
112112
engine,
113-
reportEngineHealth({machineId, signal, headers, mounts: task.mounts}),
113+
reportEngineHealth({machineId, signal, headers, path: '/var/lib/engine'}),
114114
// reportUsage({machineId, signal, headers}),
115115
])
116116
} catch (error) {

src/tasks/engineHealth.ts

+15-25
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
import {PlainMessage} from '@bufbuild/protobuf'
21
import {execa} from 'execa'
3-
import {DiskSpace} from '../gen/ts/depot/cloud/v3/machine_pb'
42
import {sleep} from '../utils/common'
5-
import {DiskStats, stats} from '../utils/disk'
3+
import {stats} from '../utils/disk'
64
import {client} from '../utils/grpc'
75

86
export interface ReportHealthParams {
97
machineId: string
108
signal: AbortSignal
119
headers: HeadersInit
12-
mounts: Mount[]
13-
}
14-
15-
export interface Mount {
16-
device: string
1710
path: string
1811
}
1912

20-
export async function reportEngineHealth({machineId, signal, headers, mounts}: ReportHealthParams) {
13+
export async function reportEngineHealth({machineId, signal, headers, path}: ReportHealthParams) {
2114
while (true) {
2215
if (signal.aborted) return
2316

@@ -27,23 +20,20 @@ export async function reportEngineHealth({machineId, signal, headers, mounts}: R
2720
while (true) {
2821
if (signal.aborted) return
2922

30-
const disk_stats = await Promise.all(mounts.map(({device, path}) => stats(device, path)))
31-
const disks: PlainMessage<DiskSpace>[] = disk_stats
32-
.filter((item: DiskStats | undefined): item is DiskStats => {
33-
return item !== undefined
34-
})
35-
.map(({device, path, freeMb, totalMb, freeInodes, totalInodes}) => {
36-
return {
37-
device,
38-
path,
39-
freeMb,
40-
totalMb,
41-
freeInodes,
42-
totalInodes,
43-
}
44-
})
23+
const disk_stats = await stats(path)
24+
const disk_space = disk_stats
25+
? [
26+
{
27+
path,
28+
freeMb: disk_stats.freeMb,
29+
totalMb: disk_stats.totalMb,
30+
freeInodes: disk_stats.freeInodes,
31+
totalInodes: disk_stats.totalInodes,
32+
},
33+
]
34+
: undefined
4535

46-
await client.pingMachineHealth({machineId, disks}, {headers, signal})
36+
await client.pingMachineHealth({machineId, disks: disk_space}, {headers, signal})
4737
await sleep(1000)
4838
}
4939
} catch (error) {

src/tasks/health.ts

+15-25
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
import {PlainMessage} from '@bufbuild/protobuf'
21
import {execa} from 'execa'
3-
import {DiskSpace} from '../gen/ts/depot/cloud/v3/machine_pb'
42
import {sleep} from '../utils/common'
5-
import {DiskStats, stats} from '../utils/disk'
3+
import {stats} from '../utils/disk'
64
import {client} from '../utils/grpc'
75

86
export interface ReportHealthParams {
97
machineId: string
108
signal: AbortSignal
119
headers: HeadersInit
12-
mounts: Mount[]
13-
}
14-
15-
export interface Mount {
16-
device: string
1710
path: string
1811
}
1912

20-
export async function reportHealth({machineId, signal, headers, mounts}: ReportHealthParams) {
13+
export async function reportHealth({machineId, signal, headers, path}: ReportHealthParams) {
2114
while (true) {
2215
if (signal.aborted) return
2316

@@ -27,23 +20,20 @@ export async function reportHealth({machineId, signal, headers, mounts}: ReportH
2720
while (true) {
2821
if (signal.aborted) return
2922

30-
const disk_stats = await Promise.all(mounts.map(({device, path}) => stats(device, path)))
31-
const disks: PlainMessage<DiskSpace>[] = disk_stats
32-
.filter((item: DiskStats | undefined): item is DiskStats => {
33-
return item !== undefined
34-
})
35-
.map(({device, path, freeMb, totalMb, freeInodes, totalInodes}) => {
36-
return {
37-
device,
38-
path,
39-
freeMb,
40-
totalMb,
41-
freeInodes,
42-
totalInodes,
43-
}
44-
})
23+
const disk_stats = await stats(path)
24+
const disk_space = disk_stats
25+
? [
26+
{
27+
path,
28+
freeMb: disk_stats.freeMb,
29+
totalMb: disk_stats.totalMb,
30+
freeInodes: disk_stats.freeInodes,
31+
totalInodes: disk_stats.totalInodes,
32+
},
33+
]
34+
: undefined
4535

46-
await client.pingMachineHealth({machineId, disks}, {headers, signal})
36+
await client.pingMachineHealth({machineId, disks: disk_space}, {headers, signal})
4737
await sleep(1000)
4838
}
4939
} catch (error) {

src/utils/disk.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import {execa} from 'execa'
22

33
export interface DiskStats {
4-
device: string
54
path: string
65
freeMb: bigint
76
totalMb: bigint
87
freeInodes: bigint
98
totalInodes: bigint
109
}
1110

12-
export async function stats(device: string, path: string): Promise<DiskStats | undefined> {
11+
export async function stats(path: string): Promise<DiskStats | undefined> {
1312
try {
1413
const {exitCode, stdout} = await execa('stat', ['-f', '-c', '%S %a %b %d %c', path])
1514
if (exitCode == 0) {
1615
const output = stdout as string
1716
const [blockSize, freeBlocks, totalBlocks, freeInodes, totalInodes] = output.split(' ')
1817
const diskStats = {
19-
device,
2018
path,
2119
freeMb: (BigInt(blockSize) * BigInt(freeBlocks)) / BigInt(1024) / BigInt(1024),
2220
totalMb: (BigInt(blockSize) * BigInt(totalBlocks)) / BigInt(1024) / BigInt(1024),

0 commit comments

Comments
 (0)