Skip to content

Commit 5610e58

Browse files
authored
Add dns resolution logs and handle error correctly (#1287)
1 parent 9fbd1d6 commit 5610e58

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

packages/client-proxy/internal/proxy/proxy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func dnsResolution(sandboxId string, logger *zap.Logger) (string, error) {
5757
// the api server wasn't found, maybe the API server is rolling and the DNS server is not updated yet
5858
if dnsErr != nil || len(resp.Answer) == 0 {
5959
err = dnsErr
60-
logger.Warn(fmt.Sprintf("host for sandbox %s not found: %s", sandboxId, err), zap.Error(err), zap.Int("retry", i+1))
60+
logger.Warn("host for sandbox not found", zap.Error(err), l.WithSandboxID(sandboxId), zap.Int("retry", i+1))
6161

6262
// Jitter
6363
time.Sleep(time.Duration(rand.Intn(10)) * time.Millisecond)
@@ -76,7 +76,7 @@ func dnsResolution(sandboxId string, logger *zap.Logger) (string, error) {
7676

7777
// there's no answer, we can't proxy the request
7878
if err != nil {
79-
return "", ErrNodeNotFound
79+
return "", fmt.Errorf("failed to resolve sandbox: %w", err)
8080
}
8181

8282
return node, nil

packages/shared/pkg/proxy/handler.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"go.uber.org/zap"
1010

11+
"github.com/e2b-dev/infra/packages/shared/pkg/logger"
1112
"github.com/e2b-dev/infra/packages/shared/pkg/proxy/pool"
1213
"github.com/e2b-dev/infra/packages/shared/pkg/proxy/template"
1314
)
@@ -60,13 +61,13 @@ func handler(p *pool.ProxyPool, getDestination func(r *http.Request) (*pool.Dest
6061

6162
var notFoundErr *SandboxNotFoundError
6263
if errors.As(err, &notFoundErr) {
63-
zap.L().Warn("sandbox not found", zap.String("host", r.Host))
64+
zap.L().Warn("sandbox not found", zap.String("host", r.Host), logger.WithSandboxID(notFoundErr.SandboxId))
6465

6566
err := template.
6667
NewSandboxNotFoundError(notFoundErr.SandboxId, r.Host).
6768
HandleError(w, r)
6869
if err != nil {
69-
zap.L().Error("failed to handle sandbox not found error", zap.Error(err))
70+
zap.L().Error("failed to handle sandbox not found error", zap.Error(err), logger.WithSandboxID(notFoundErr.SandboxId))
7071
http.Error(w, "Failed to handle sandbox not found error", http.StatusInternalServerError)
7172

7273
return

0 commit comments

Comments
 (0)