Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ linters:
# these are in other PRs already
- forcetypeassert
- noctx
- protogetter

# todo: determine if we want this
- canonicalheader
Expand Down
6 changes: 3 additions & 3 deletions packages/api/internal/edge/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ func (c *Cluster) RegisterSandboxInCatalog(ctx context.Context, serviceInstanceI
body := api.V1SandboxCatalogCreateJSONRequestBody{
OrchestratorID: serviceInstanceID,

ExecutionID: sandboxConfig.ExecutionId,
SandboxID: sandboxConfig.SandboxId,
SandboxMaxLength: sandboxConfig.MaxSandboxLength,
ExecutionID: sandboxConfig.GetExecutionId(),
SandboxID: sandboxConfig.GetSandboxId(),
SandboxMaxLength: sandboxConfig.GetMaxSandboxLength(),
SandboxStartTime: sandboxStartTime,
}

Expand Down
4 changes: 2 additions & 2 deletions packages/api/internal/edge/cluster_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func (c *Cluster) syncInstance(ctx context.Context, instance *ClusterInstance) {
instance.mutex.Lock()
defer instance.mutex.Unlock()

instance.status = info.ServiceStatus
instance.roles = info.ServiceRoles
instance.status = info.GetServiceStatus()
instance.roles = info.GetServiceRoles()
}

func (n *ClusterInstance) GetStatus() infogrpc.ServiceInfoStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (a *APIStore) GetTemplatesTemplateIDFilesHash(c *gin.Context, templateID ap
}

c.JSON(http.StatusCreated, &api.TemplateBuildFileUpload{
Present: resp.Present,
Present: resp.GetPresent(),
Url: resp.Url,
})
}
2 changes: 1 addition & 1 deletion packages/api/internal/orchestrator/nodemanager/builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var tracer = otel.Tracer("github.com/e2b-dev/infra/packages/api/internal/orchest

func (n *Node) SyncBuilds(builds []*orchestrator.CachedBuildInfo) {
for _, build := range builds {
n.buildCache.Set(build.BuildId, struct{}{}, time.Until(build.ExpirationTime.AsTime()))
n.buildCache.Set(build.GetBuildId(), struct{}{}, time.Until(build.GetExpirationTime().AsTime()))
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/api/internal/orchestrator/nodemanager/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ func (n *Node) GetSandboxCreateCtx(ctx context.Context, req *orchestrator.Sandbo

md := edge.SerializeSandboxCatalogCreateEvent(
edge.SandboxCatalogCreateEvent{
SandboxID: req.Sandbox.SandboxId,
SandboxMaxLengthInHours: req.Sandbox.MaxSandboxLength,
SandboxStartTime: req.StartTime.AsTime(),
SandboxID: req.GetSandbox().GetSandboxId(),
SandboxMaxLengthInHours: req.GetSandbox().GetMaxSandboxLength(),
SandboxStartTime: req.GetStartTime().AsTime(),

ExecutionID: req.Sandbox.ExecutionId,
ExecutionID: req.GetSandbox().GetExecutionId(),
OrchestratorID: n.Metadata().ServiceInstanceID,
},
)
Expand Down
26 changes: 13 additions & 13 deletions packages/api/internal/orchestrator/nodemanager/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,30 @@ func (n *Node) UpdateMetricsFromServiceInfoResponse(info *orchestratorinfo.Servi
defer n.metricsMu.Unlock()

// Update host usage metrics
n.metrics.CpuPercent = info.MetricCpuPercent
n.metrics.MemoryUsedBytes = info.MetricMemoryUsedBytes
n.metrics.CpuPercent = info.GetMetricCpuPercent()
n.metrics.MemoryUsedBytes = info.GetMetricMemoryUsedBytes()

// Update host total metrics
n.metrics.CpuCount = info.MetricCpuCount
n.metrics.MemoryTotalBytes = info.MetricMemoryTotalBytes
n.metrics.CpuCount = info.GetMetricCpuCount()
n.metrics.MemoryTotalBytes = info.GetMetricMemoryTotalBytes()

// Update allocated resources
n.metrics.CpuAllocated = info.MetricCpuAllocated
n.metrics.MemoryAllocatedBytes = info.MetricMemoryAllocatedBytes
n.metrics.CpuAllocated = info.GetMetricCpuAllocated()
n.metrics.MemoryAllocatedBytes = info.GetMetricMemoryAllocatedBytes()

// Update total sandbox count
n.metrics.SandboxCount = info.MetricSandboxesRunning
n.metrics.SandboxCount = info.GetMetricSandboxesRunning()

// Update detailed disk metrics
disks := info.MetricDisks
disks := info.GetMetricDisks()
n.metrics.HostDisks = make([]DiskMetrics, len(disks))
for i, disk := range disks {
n.metrics.HostDisks[i] = DiskMetrics{
MountPoint: disk.MountPoint,
Device: disk.Device,
FilesystemType: disk.FilesystemType,
UsedBytes: disk.UsedBytes,
TotalBytes: disk.TotalBytes,
MountPoint: disk.GetMountPoint(),
Device: disk.GetDevice(),
FilesystemType: disk.GetFilesystemType(),
UsedBytes: disk.GetUsedBytes(),
TotalBytes: disk.GetTotalBytes(),
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions packages/api/internal/orchestrator/nodemanager/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,25 @@ func New(
return nil, fmt.Errorf("failed to get node service info: %w", err)
}

nodeStatus, ok := OrchestratorToApiNodeStateMapper[nodeInfo.ServiceStatus]
nodeStatus, ok := OrchestratorToApiNodeStateMapper[nodeInfo.GetServiceStatus()]
if !ok {
zap.L().Error("Unknown service info status", zap.Any("status", nodeInfo.ServiceStatus), logger.WithNodeID(nodeInfo.NodeId))
zap.L().Error("Unknown service info status", zap.Any("status", nodeInfo.GetServiceStatus()), logger.WithNodeID(nodeInfo.GetNodeId()))
nodeStatus = api.NodeStatusUnhealthy
}

buildCache := ttlcache.New[string, any]()
go buildCache.Start()

nodeMetadata := NodeMetadata{
ServiceInstanceID: nodeInfo.ServiceId,
Commit: nodeInfo.ServiceCommit,
Version: nodeInfo.ServiceVersion,
ServiceInstanceID: nodeInfo.GetServiceId(),
Commit: nodeInfo.GetServiceCommit(),
Version: nodeInfo.GetServiceVersion(),
}

n := &Node{
NomadNodeShortID: discoveredNode.NomadNodeShortID,
ClusterID: consts.LocalClusterID,
ID: nodeInfo.NodeId,
ID: nodeInfo.GetNodeId(),
IPAddress: discoveredNode.IPAddress,

client: client,
Expand Down
44 changes: 22 additions & 22 deletions packages/api/internal/orchestrator/nodemanager/sandboxes.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,42 @@ func (n *Node) GetSandboxes(ctx context.Context) ([]instance.Data, error) {
return nil, fmt.Errorf("sandbox config is nil when listing sandboxes: %#v", sbx)
}

teamID, parseErr := uuid.Parse(config.TeamId)
teamID, parseErr := uuid.Parse(config.GetTeamId())
if parseErr != nil {
return nil, fmt.Errorf("failed to parse team ID '%s' for job: %w", config.TeamId, parseErr)
return nil, fmt.Errorf("failed to parse team ID '%s' for job: %w", config.GetTeamId(), parseErr)
}

buildID, parseErr := uuid.Parse(config.BuildId)
buildID, parseErr := uuid.Parse(config.GetBuildId())
if parseErr != nil {
return nil, fmt.Errorf("failed to parse build ID '%s' for job: %w", config.BuildId, parseErr)
return nil, fmt.Errorf("failed to parse build ID '%s' for job: %w", config.GetBuildId(), parseErr)
}

sandboxesInfo = append(
sandboxesInfo,
instance.NewSandbox(
config.SandboxId,
config.TemplateId,
config.GetSandboxId(),
config.GetTemplateId(),
consts.ClientID,
config.Alias,
config.ExecutionId,
config.Alias, //nolint:protogetter // we need the nil check too
config.GetExecutionId(),
teamID,
buildID,
config.Metadata,
time.Duration(config.MaxSandboxLength)*time.Hour,
sbx.StartTime.AsTime(),
sbx.EndTime.AsTime(),
config.Vcpu,
config.TotalDiskSizeMb,
config.RamMb,
config.KernelVersion,
config.FirecrackerVersion,
config.EnvdVersion,
config.GetMetadata(),
time.Duration(config.GetMaxSandboxLength())*time.Hour,
sbx.GetStartTime().AsTime(),
sbx.GetEndTime().AsTime(),
config.GetVcpu(),
config.GetTotalDiskSizeMb(),
config.GetRamMb(),
config.GetKernelVersion(),
config.GetFirecrackerVersion(),
config.GetEnvdVersion(),
n.ID,
n.ClusterID,
config.AutoPause,
config.EnvdAccessToken,
config.AllowInternetAccess,
config.BaseTemplateId,
config.GetAutoPause(),
config.EnvdAccessToken, //nolint:protogetter // we need the nil check too
config.AllowInternetAccess, //nolint:protogetter // we need the nil check too
config.GetBaseTemplateId(),
),
)
}
Expand Down
10 changes: 5 additions & 5 deletions packages/api/internal/orchestrator/nodemanager/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ func (n *Node) Sync(ctx context.Context, instanceCache *instance.MemoryStore) {
}

// update node status (if changed)
nodeStatus, ok := OrchestratorToApiNodeStateMapper[nodeInfo.ServiceStatus]
nodeStatus, ok := OrchestratorToApiNodeStateMapper[nodeInfo.GetServiceStatus()]
if !ok {
zap.L().Error("Unknown service info status", zap.Any("status", nodeInfo.ServiceStatus), logger.WithNodeID(n.ID))
zap.L().Error("Unknown service info status", zap.Any("status", nodeInfo.GetServiceStatus()), logger.WithNodeID(n.ID))
nodeStatus = api.NodeStatusUnhealthy
}

n.setStatus(nodeStatus)
n.setMetadata(
NodeMetadata{
ServiceInstanceID: nodeInfo.ServiceId,
Commit: nodeInfo.ServiceCommit,
Version: nodeInfo.ServiceVersion,
ServiceInstanceID: nodeInfo.GetServiceId(),
Commit: nodeInfo.GetServiceCommit(),
Version: nodeInfo.GetServiceVersion(),
},
)
// Update host metrics from service info
Expand Down
20 changes: 10 additions & 10 deletions packages/api/internal/orchestrator/placement/placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ func PlaceSandbox(ctx context.Context, algorithm Algorithm, clusterNodes []*node
return nil, fmt.Errorf("no nodes available")
}

node, err = algorithm.chooseNode(ctx, clusterNodes, nodesExcluded, nodemanager.SandboxResources{CPUs: sbxRequest.Sandbox.Vcpu, MiBMemory: sbxRequest.Sandbox.RamMb})
node, err = algorithm.chooseNode(ctx, clusterNodes, nodesExcluded, nodemanager.SandboxResources{CPUs: sbxRequest.GetSandbox().GetVcpu(), MiBMemory: sbxRequest.GetSandbox().GetRamMb()})
if err != nil {
return nil, err
}

telemetry.ReportEvent(ctx, "Placing sandbox on the node", telemetry.WithNodeID(node.ID))
}

node.PlacementMetrics.StartPlacing(sbxRequest.Sandbox.SandboxId, nodemanager.SandboxResources{
CPUs: sbxRequest.Sandbox.Vcpu,
MiBMemory: sbxRequest.Sandbox.RamMb,
node.PlacementMetrics.StartPlacing(sbxRequest.GetSandbox().GetSandboxId(), nodemanager.SandboxResources{
CPUs: sbxRequest.GetSandbox().GetVcpu(),
MiBMemory: sbxRequest.GetSandbox().GetRamMb(),
})

ctx, span := tracer.Start(ctx, "create-sandbox")
Expand All @@ -78,26 +78,26 @@ func PlaceSandbox(ctx context.Context, algorithm Algorithm, clusterNodes []*node
span.End()
if err != nil {
if algorithm.excludeNode(err) {
zap.L().Warn("Excluding node", logger.WithSandboxID(sbxRequest.Sandbox.SandboxId), logger.WithNodeID(node.ID))
zap.L().Warn("Excluding node", logger.WithSandboxID(sbxRequest.GetSandbox().GetSandboxId()), logger.WithNodeID(node.ID))
nodesExcluded[node.ID] = struct{}{}
}

st, ok := status.FromError(err)
if !ok || st.Code() != codes.ResourceExhausted {
node.PlacementMetrics.Fail(sbxRequest.Sandbox.SandboxId)
zap.L().Error("Failed to create sandbox", logger.WithSandboxID(sbxRequest.Sandbox.SandboxId), logger.WithNodeID(node.ID), zap.Int("attempt", attempt+1), zap.Error(utils.UnwrapGRPCError(err)))
node.PlacementMetrics.Fail(sbxRequest.GetSandbox().GetSandboxId())
zap.L().Error("Failed to create sandbox", logger.WithSandboxID(sbxRequest.GetSandbox().GetSandboxId()), logger.WithNodeID(node.ID), zap.Int("attempt", attempt+1), zap.Error(utils.UnwrapGRPCError(err)))
attempt++
} else {
node.PlacementMetrics.Skip(sbxRequest.Sandbox.SandboxId)
zap.L().Warn("Node exhausted, trying another node", logger.WithSandboxID(sbxRequest.Sandbox.SandboxId), logger.WithNodeID(node.ID))
node.PlacementMetrics.Skip(sbxRequest.GetSandbox().GetSandboxId())
zap.L().Warn("Node exhausted, trying another node", logger.WithSandboxID(sbxRequest.GetSandbox().GetSandboxId()), logger.WithNodeID(node.ID))
}

node = nil

continue
}

node.PlacementMetrics.Success(sbxRequest.Sandbox.SandboxId)
node.PlacementMetrics.Success(sbxRequest.GetSandbox().GetSandboxId())
return node, nil
}

Expand Down
4 changes: 2 additions & 2 deletions packages/api/internal/template-manager/template_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (c *PollBuildStatus) dispatchBasedOnStatus(ctx context.Context, status *tem
switch status.GetStatus() {
case templatemanagergrpc.TemplateBuildState_Failed:
// build failed
err := c.client.SetStatus(ctx, c.templateID, c.buildID, envbuild.StatusFailed, status.Reason)
err := c.client.SetStatus(ctx, c.templateID, c.buildID, envbuild.StatusFailed, status.GetReason())
if err != nil {
return false, errors.Wrap(err, "error when setting build status")
}
Expand All @@ -184,7 +184,7 @@ func (c *PollBuildStatus) dispatchBasedOnStatus(ctx context.Context, status *tem
return false, errors.New("nil metadata")
}

err := c.client.SetFinished(ctx, c.templateID, c.buildID, int64(meta.RootfsSizeKey), meta.EnvdVersionKey)
err := c.client.SetFinished(ctx, c.templateID, c.buildID, int64(meta.GetRootfsSizeKey()), meta.GetEnvdVersionKey())
if err != nil {
return false, errors.Wrap(err, "error when finishing build")
}
Expand Down
22 changes: 11 additions & 11 deletions packages/client-proxy/internal/edge/pool/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ func (o *OrchestratorInstance) sync(ctx context.Context) error {
continue
}

freshInfo.NodeID = status.NodeId
freshInfo.ServiceInstanceID = status.ServiceId
freshInfo.ServiceStartup = status.ServiceStartup.AsTime()
freshInfo.ServiceStatus = getMappedStatus(status.ServiceStatus)
freshInfo.ServiceVersion = status.ServiceVersion
freshInfo.ServiceVersionCommit = status.ServiceCommit
freshInfo.Roles = status.ServiceRoles
freshInfo.NodeID = status.GetNodeId()
freshInfo.ServiceInstanceID = status.GetServiceId()
freshInfo.ServiceStartup = status.GetServiceStartup().AsTime()
freshInfo.ServiceStatus = getMappedStatus(status.GetServiceStatus())
freshInfo.ServiceVersion = status.GetServiceVersion()
freshInfo.ServiceVersionCommit = status.GetServiceCommit()
freshInfo.Roles = status.GetServiceRoles()
o.setInfo(freshInfo)

o.MetricSandboxesRunning.Store(status.MetricSandboxesRunning)
o.MetricMemoryUsedBytes.Store(status.MetricMemoryUsedBytes)
o.MetricDiskUsedBytes.Store(status.MetricDiskAllocatedBytes)
o.MetricVCpuUsed.Store(status.MetricCpuCount)
o.MetricSandboxesRunning.Store(status.GetMetricSandboxesRunning())
o.MetricMemoryUsedBytes.Store(status.GetMetricMemoryUsedBytes())
o.MetricDiskUsedBytes.Store(status.GetMetricDiskAllocatedBytes())
o.MetricVCpuUsed.Store(status.GetMetricCpuCount())

return nil
}
Expand Down
Loading
Loading