Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/egress/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Fast Sandbox credential-bound (experimental): lower the default `OPENSANDBOX_EGRESS_FSB_PROCESS_TLS_CAPACITY` from 131072 to 32768. Measurements in two KVM environments found 158–166 KB of egress memory per held decrypted connection, so the old default allowed about 21 GB. Set the variable explicitly to keep a different budget.
- Report upstream TLS failures with a connection ID and a bounded certificate verification reason. Unknown transport failures remain unclassified; request and credential data are not logged by this diagnostic.
- On the Classic non-revision policy path, attempt to restore the previous policy file before logging an nft apply failure, so a stalled error log cannot delay file rollback.
- When ordinary logs and internal logging errors use the same file path, they now rotate together so diagnostics continue in the active file after rotation.

# components/egress 1.0.4

Expand Down
11 changes: 9 additions & 2 deletions components/internal/logger/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,18 @@ func newWithRotate(cfg Config, extra ...zapcore.Core) (Logger, error) {

// Fail fast on bad paths/permissions, matching the original zap.Config.Build
// behaviour that opens sinks at init time.
// Each configured route still receives a copy, but repeated paths must
// share the file handle and size accounting across rotations.
writers := make(map[string]zapcore.WriteSyncer, len(cfg.OutputPaths))
for _, paths := range [][]string{cfg.OutputPaths, cfg.ErrorOutputPaths} {
for _, path := range paths {
if _, ok := writers[path]; ok {
continue
}
if err := validateOutputPath(path); err != nil {
return nil, fmt.Errorf("invalid output path %q: %w", path, err)
}
writers[path] = rotateWriter(path, cfg.Rotate)
}
}

Expand All @@ -127,7 +134,7 @@ func newWithRotate(cfg Config, extra ...zapcore.Core) (Logger, error) {

var cores []zapcore.Core
for _, path := range cfg.OutputPaths {
cores = append(cores, zapcore.NewCore(encoder, rotateWriter(path, cfg.Rotate), atom))
cores = append(cores, zapcore.NewCore(encoder, writers[path], atom))
}

core := teeCores(cores)
Expand All @@ -139,7 +146,7 @@ func newWithRotate(cfg Config, extra ...zapcore.Core) (Logger, error) {
// failures, etc.) so they respect the same rotation config as regular logs.
var errSinks []zapcore.WriteSyncer
for _, path := range cfg.ErrorOutputPaths {
errSinks = append(errSinks, rotateWriter(path, cfg.Rotate))
errSinks = append(errSinks, writers[path])
}

base := zap.New(core,
Expand Down
85 changes: 85 additions & 0 deletions components/internal/logger/zap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright 2026 The OpenSandbox Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package logger

import (
"bytes"
"flag"
"io"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

func TestFileRotationAcrossLogRoutes(t *testing.T) {
const helper = "write-rotation-fixture"
if flag.Arg(0) == helper {
paths := []string{"events.log"}
if flag.Arg(1) == "duplicate" {
paths = append(paths, paths[0])
}
// A failing extra core makes Zap emit real internal diagnostics for
// the two warnings without changing the ordinary file output.
r, w := io.Pipe()
_ = r.Close()
defer w.Close()
failWarn := zapcore.NewCore(zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), zapcore.AddSync(w), zap.WarnLevel)
l, err := NewWithExtraCores(Config{OutputPaths: paths, Rotate: &RotateConfig{MaxSize: 1}}, failWarn)
if err != nil {
t.Fatal(err)
}
l.Warnf("before rotation") // Open both routes before the file is renamed.
payload := strings.Repeat("x", 600<<10)
for range 2 / len(paths) {
l.Infof("large record: %s", payload)
}
l.Warnf("after rotation")
return
}

for i, name := range []string{"single", "duplicate"} {
t.Run(name, func(t *testing.T) {
dir := t.TempDir()
// The logger has no Close API. Let its process release the files
// before inspecting them and removing the temporary directory.
cmd := exec.CommandContext(t.Context(), os.Args[0], "-test.run=^TestFileRotationAcrossLogRoutes$", "--", helper, name)
cmd.Dir = dir
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("write fixture: %v\n%s", err, out)
}
backups, err := filepath.Glob(filepath.Join(dir, "events-*.log"))
if err != nil || len(backups) != 1 {
t.Fatalf("expected one rotation, got %v (err=%v)", backups, err)
}
for _, path := range []string{backups[0], filepath.Join(dir, "events.log")} {
data, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
if n := bytes.Count(data, []byte("large record:")); n != 1 {
t.Errorf("%s: got %d large records, want 1", filepath.Base(path), n)
}
if n := bytes.Count(data, []byte(io.ErrClosedPipe.Error())); n != i+1 {
t.Errorf("%s: got %d internal diagnostics, want %d", filepath.Base(path), n, i+1)
}
}
})
}
}
Loading