Skip to content

Commit 8614831

Browse files
committed
Merge branch 'main' of github.com:e2b-dev/infra into lev-compression-final
2 parents 39cb074 + f98f20f commit 8614831

15 files changed

Lines changed: 209 additions & 105 deletions

File tree

.github/workflows/build-and-upload-job.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,15 @@ jobs:
4242
with:
4343
ref: ${{ inputs.commit_sha }}
4444

45+
- name: Checkout actions
46+
uses: actions/checkout@v5
47+
with:
48+
sparse-checkout: |
49+
.github/actions
50+
path: actions-from-ref
51+
4552
- name: Setup environment
46-
uses: ./.github/actions/deploy-setup
53+
uses: ./actions-from-ref/.github/actions/deploy-setup
4754
with:
4855
environment: ${{ inputs.environment }}
4956
install_gcloud: "true"

.github/workflows/deploy-infra.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,15 @@ jobs:
4040
with:
4141
ref: ${{ inputs.commit_sha }}
4242

43+
- name: Checkout actions
44+
uses: actions/checkout@v5
45+
with:
46+
sparse-checkout: |
47+
.github/actions
48+
path: actions-from-ref
49+
4350
- name: Setup environment
44-
uses: ./.github/actions/deploy-setup
51+
uses: ./actions-from-ref/.github/actions/deploy-setup
4552
with:
4653
environment: ${{ inputs.environment }}
4754
install_gcloud: "true"

.github/workflows/deploy-job.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,15 @@ jobs:
4343
with:
4444
ref: ${{ inputs.commit_sha }}
4545

46+
- name: Checkout actions
47+
uses: actions/checkout@v5
48+
with:
49+
sparse-checkout: |
50+
.github/actions
51+
path: actions-from-ref
52+
4653
- name: Setup environment
47-
uses: ./.github/actions/deploy-setup
54+
uses: ./actions-from-ref/.github/actions/deploy-setup
4855
with:
4956
environment: ${{ inputs.environment }}
5057
infisical_machine_identity_id: ${{ vars.INFISICAL_MACHINE_IDENTITY_ID }}

.github/workflows/pr-tests.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ jobs:
3939
steps:
4040
- name: Checkout repository
4141
uses: actions/checkout@v5
42-
with:
43-
ref: ${{ inputs.commit_sha }}
4442

4543
- name: Setup Go
4644
uses: ./.github/actions/go-setup-cache

packages/orchestrator/benchmarks/benchmark_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func BenchmarkBaseImageLaunch(b *testing.B) {
8080
return utils.Must(filepath.Abs(s))
8181
}
8282

83-
endpoint := os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT")
83+
endpoint := os.Getenv("OTEL_COLLECTOR_GRPC_ENDPOINT")
8484
if endpoint != "" {
8585
spanExporter, err := telemetry.NewSpanExporter(b.Context(),
8686
otlptracegrpc.WithEndpoint(endpoint),

packages/orchestrator/benchmarks/concurrent_benchmark_test.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ import (
3333
"github.com/stretchr/testify/assert"
3434
"github.com/stretchr/testify/require"
3535
"go.opentelemetry.io/otel"
36+
"go.opentelemetry.io/otel/attribute"
3637
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
3738
"go.opentelemetry.io/otel/metric/noop"
39+
"go.opentelemetry.io/otel/trace"
3840

3941
"github.com/e2b-dev/infra/packages/clickhouse/pkg/hoststats"
4042
"github.com/e2b-dev/infra/packages/orchestrator/pkg/cfg"
@@ -137,11 +139,20 @@ func BenchmarkConcurrentResume(b *testing.B) {
137139
kernelVersion = "vmlinux-6.1.158"
138140
fcVersion = featureflags.DefaultFirecrackerVersion
139141
templateID = "fcb33d09-3141-42c4-8d3b-c2df411681db"
140-
buildID = "ba6aae36-74f7-487a-b6f7-74fd7c94e479"
141-
useHugePages = false
142142
templateVersion = "v2.0.0"
143+
144+
buildIDNormal = "ba6aae36-74f7-487a-b6f7-74fd7c94e479"
145+
buildIDHugePages = "ba6aae36-74f7-487a-b6f7-74fd7c94e480"
143146
)
144147

148+
disableHP, _ := strconv.ParseBool(os.Getenv("DISABLE_HUGE_PAGES"))
149+
useHugePages := !disableHP
150+
buildID := buildIDHugePages
151+
if !useHugePages {
152+
buildID = buildIDNormal
153+
b.Log("huge pages disabled")
154+
}
155+
145156
// cache & ephemeral paths
146157
persistenceDir := getPersistenceDir()
147158
kernelsDir := filepath.Join(persistenceDir, "kernels")
@@ -155,7 +166,7 @@ func BenchmarkConcurrentResume(b *testing.B) {
155166
}
156167

157168
// optional OTEL tracing
158-
endpoint := os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT")
169+
endpoint := os.Getenv("OTEL_COLLECTOR_GRPC_ENDPOINT")
159170
if endpoint != "" {
160171
spanExporter, err := telemetry.NewSpanExporter(b.Context(),
161172
otlptracegrpc.WithEndpoint(endpoint),
@@ -423,9 +434,17 @@ func runConcurrentResume(
423434
// Wait for the barrier.
424435
<-gate
425436

437+
ctx, span := tracer.Start(b.Context(), "bench-resume",
438+
trace.WithAttributes(
439+
attribute.Int("concurrency", n),
440+
attribute.Int("sandbox.index", i),
441+
attribute.String("sandbox.id", runtime.SandboxID),
442+
),
443+
)
444+
426445
start := time.Now()
427446
sbx, err := factory.ResumeSandbox(
428-
b.Context(),
447+
ctx,
429448
tmpl,
430449
config,
431450
runtime,
@@ -434,6 +453,7 @@ func runConcurrentResume(
434453
nil,
435454
)
436455
elapsed := time.Since(start)
456+
span.End()
437457

438458
results[i] = concurrencyResult{
439459
sandboxID: runtime.SandboxID,

packages/orchestrator/cmd/show-build-diff/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func main() {
116116
fmt.Printf("Storage path %s\n", diffSource)
117117
fmt.Printf("========\n")
118118

119-
onlyDiffMappings := make([]*header.BuildMap, 0)
119+
onlyDiffMappings := make([]header.BuildMap, 0)
120120

121121
for _, mapping := range diffHeader.Mapping {
122122
if mapping.BuildId == diffHeader.Metadata.BuildId {

packages/orchestrator/pkg/sandbox/fc/process.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,10 @@ func (p *Process) Resume(
489489
})
490490

491491
eg.Go(func() error {
492-
err := socket.Wait(egCtx, uffdSocketPath)
492+
ctx, uffdSpan := tracer.Start(egCtx, "wait-uffd-socket")
493+
err := socket.Wait(ctx, uffdSocketPath)
494+
uffdSpan.End()
495+
493496
if err != nil {
494497
return fmt.Errorf("error waiting for uffd socket: %w", err)
495498
}
@@ -500,7 +503,10 @@ func (p *Process) Resume(
500503
})
501504

502505
eg.Go(func() error {
506+
_, rootfsSpan := tracer.Start(egCtx, "wait-rootfs-path")
503507
rootfsPath, err := p.rootfsProvider.Path()
508+
rootfsSpan.End()
509+
504510
if err != nil {
505511
return fmt.Errorf("error getting rootfs path: %w", err)
506512
}

packages/orchestrator/pkg/sandbox/nbd/testutils/zero_device.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func NewZeroDevice(size int64, blockSize int64) (*ZeroDevice, error) {
2424
uint64(blockSize),
2525
uint64(size),
2626
),
27-
[]*header.BuildMap{
27+
[]header.BuildMap{
2828
{
2929
Offset: 0,
3030
Length: uint64(size),

packages/shared/pkg/storage/header/header.go

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"fmt"
77
"maps"
88
"slices"
9+
"sort"
910

10-
"github.com/bits-and-blooms/bitset"
1111
"github.com/google/uuid"
1212
"go.uber.org/zap"
1313

@@ -31,27 +31,19 @@ type Header struct {
3131
// This means every V4 header has a complete map of all builds referenced
3232
// in its Mapping. V3 headers have no BuildFiles; the read path falls back
3333
// to a Size() RPC for those.
34-
BuildFiles map[uuid.UUID]BuildFileInfo
35-
blockStarts *bitset.BitSet
36-
startMap map[int64]*BuildMap
34+
BuildFiles map[uuid.UUID]BuildFileInfo
3735

38-
Mapping []*BuildMap
36+
Mapping []BuildMap
3937
}
4038

4139
// CloneForUpload returns a clone with copied Mapping and BuildFiles, safe to
4240
// mutate for serialization without racing with concurrent readers of the
43-
// original. Only serialization-relevant fields are populated (Metadata,
44-
// Mapping, BuildFiles); lookup indices (blockStarts, startMap) are left nil.
41+
// original.
4542
func (t *Header) CloneForUpload() *Header {
46-
mappings := make([]*BuildMap, len(t.Mapping))
47-
for i, m := range t.Mapping {
48-
mappings[i] = m.Copy()
49-
}
50-
5143
metaCopy := *t.Metadata
5244
clone := &Header{
5345
Metadata: &metaCopy,
54-
Mapping: mappings,
46+
Mapping: slices.Clone(t.Mapping),
5547
}
5648

5749
if t.BuildFiles != nil {
@@ -62,37 +54,23 @@ func (t *Header) CloneForUpload() *Header {
6254
return clone
6355
}
6456

65-
func NewHeader(metadata *Metadata, mapping []*BuildMap) (*Header, error) {
57+
func NewHeader(metadata *Metadata, mapping []BuildMap) (*Header, error) {
6658
if metadata.BlockSize == 0 {
6759
return nil, fmt.Errorf("block size cannot be zero")
6860
}
6961

7062
if len(mapping) == 0 {
71-
mapping = []*BuildMap{{
63+
mapping = []BuildMap{{
7264
Offset: 0,
7365
Length: metadata.Size,
7466
BuildId: metadata.BuildId,
7567
BuildStorageOffset: 0,
7668
}}
7769
}
7870

79-
blocks := TotalBlocks(int64(metadata.Size), int64(metadata.BlockSize))
80-
81-
intervals := bitset.New(uint(blocks))
82-
startMap := make(map[int64]*BuildMap, len(mapping))
83-
84-
for _, m := range mapping {
85-
block := BlockIdx(int64(m.Offset), int64(metadata.BlockSize))
86-
87-
intervals.Set(uint(block))
88-
startMap[block] = m
89-
}
90-
9171
return &Header{
92-
blockStarts: intervals,
93-
Metadata: metadata,
94-
Mapping: mapping,
95-
startMap: startMap,
72+
Metadata: metadata,
73+
Mapping: mapping,
9674
}, nil
9775
}
9876

@@ -147,7 +125,6 @@ func (t *Header) GetShiftedMapping(ctx context.Context, offset int64) (BuildMap,
147125
return b, nil
148126
}
149127

150-
// TODO: Maybe we can optimize mapping by automatically assuming the mapping is uuid.Nil if we don't find it + stopping storing the nil mapping.
151128
func (t *Header) getMapping(ctx context.Context, offset int64) (*BuildMap, int64, error) {
152129
if offset < 0 || offset >= int64(t.Metadata.Size) {
153130
if t.IsNormalizeFixApplied() {
@@ -172,30 +149,26 @@ func (t *Header) getMapping(ctx context.Context, offset int64) (*BuildMap, int64
172149
)
173150
}
174151

175-
block := BlockIdx(offset, int64(t.Metadata.BlockSize))
152+
i := sort.Search(len(t.Mapping), func(i int) bool {
153+
return int64(t.Mapping[i].Offset) > offset
154+
})
176155

177-
start, ok := t.blockStarts.PreviousSet(uint(block))
178-
if !ok {
156+
if i == 0 {
179157
return nil, 0, fmt.Errorf("no source found for offset %d", offset)
180158
}
181159

182-
mapping, ok := t.startMap[int64(start)]
183-
if !ok {
184-
return nil, 0, fmt.Errorf("no mapping found for offset %d", offset)
185-
}
186-
187-
shift := (block - int64(start)) * int64(t.Metadata.BlockSize)
160+
mapping := &t.Mapping[i-1]
161+
shift := offset - int64(mapping.Offset)
188162

189163
// Verify that the offset falls within this mapping's range
190164
if shift >= int64(mapping.Length) {
191165
if t.IsNormalizeFixApplied() {
192-
return nil, 0, fmt.Errorf("offset %d (block %d) is beyond the end of mapping at offset %d (ends at %d)",
193-
offset, block, mapping.Offset, mapping.Offset+mapping.Length)
166+
return nil, 0, fmt.Errorf("offset %d is beyond the end of mapping at offset %d (ends at %d)",
167+
offset, mapping.Offset, mapping.Offset+mapping.Length)
194168
}
195169

196170
logger.L().Warn(ctx, "offset is beyond the end of mapping, but normalize fix is not applied",
197171
zap.Int64("offset", offset),
198-
zap.Int64("block", block),
199172
zap.Uint64("mappingOffset", mapping.Offset),
200173
zap.Uint64("mappingEnd", mapping.Offset+mapping.Length),
201174
logger.WithBuildID(t.Metadata.BuildId.String()),
@@ -228,9 +201,8 @@ func ValidateHeader(h *Header) error {
228201
}
229202

230203
// Sort mappings by offset to check for gaps/overlaps
231-
sortedMappings := make([]*BuildMap, len(h.Mapping))
232-
copy(sortedMappings, h.Mapping)
233-
slices.SortFunc(sortedMappings, func(a, b *BuildMap) int {
204+
sortedMappings := slices.Clone(h.Mapping)
205+
slices.SortFunc(sortedMappings, func(a, b BuildMap) int {
234206
return cmp.Compare(a.Offset, b.Offset)
235207
})
236208

0 commit comments

Comments
 (0)