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
24 changes: 0 additions & 24 deletions packages/api/internal/handlers/sandbox_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import (
"net/http"

"github.com/gin-gonic/gin"
"github.com/launchdarkly/go-sdk-common/v3/ldcontext"

"github.com/e2b-dev/infra/packages/api/internal/api"
"github.com/e2b-dev/infra/packages/api/internal/utils"
"github.com/e2b-dev/infra/packages/auth/pkg/auth"
"github.com/e2b-dev/infra/packages/shared/pkg/clusters"
"github.com/e2b-dev/infra/packages/shared/pkg/featureflags"
"github.com/e2b-dev/infra/packages/shared/pkg/logger"
"github.com/e2b-dev/infra/packages/shared/pkg/telemetry"
)
Expand All @@ -29,28 +27,6 @@ func (a *APIStore) GetSandboxesSandboxIDMetrics(c *gin.Context, sandboxID string

team := auth.MustGetTeamInfo(c)

// Build the context for feature flags
ctx = featureflags.AddToContext(
ctx,
ldcontext.NewBuilder(sandboxID).
Kind(featureflags.SandboxKind).
Build(),
ldcontext.NewBuilder(team.ID.String()).
Kind(featureflags.TeamKind).
Build(),
)

metricsReadFlag := a.featureFlags.BoolFlag(ctx, featureflags.MetricsReadFlag)
if !metricsReadFlag {
logger.L().Debug(ctx, "sandbox metrics read feature flag is disabled")
// If we are not reading from ClickHouse, we can return an empty map
// This is here just to have the possibility to turn off ClickHouse metrics reading

c.JSON(http.StatusOK, []api.SandboxMetric{})

return
}

clusterID := clusters.WithClusterFallback(team.ClusterID)
cluster, found := a.clusters.GetClusterById(clusterID)
if !found {
Expand Down
18 changes: 0 additions & 18 deletions packages/api/internal/handlers/sandboxes_list_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import (

"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/launchdarkly/go-sdk-common/v3/ldcontext"
"go.opentelemetry.io/otel/attribute"
"go.uber.org/zap"

"github.com/e2b-dev/infra/packages/api/internal/api"
"github.com/e2b-dev/infra/packages/api/internal/utils"
"github.com/e2b-dev/infra/packages/auth/pkg/auth"
"github.com/e2b-dev/infra/packages/shared/pkg/clusters"
"github.com/e2b-dev/infra/packages/shared/pkg/featureflags"
"github.com/e2b-dev/infra/packages/shared/pkg/logger"
"github.com/e2b-dev/infra/packages/shared/pkg/telemetry"
)
Expand Down Expand Up @@ -50,14 +48,6 @@ func (a *APIStore) getSandboxesMetrics(
)

// Get metrics for all sandboxes
metricsReadFlag := a.featureFlags.BoolFlag(ctx, featureflags.MetricsReadFlag)
if !metricsReadFlag {
logger.L().Debug(ctx, "sandbox metrics read feature flag is disabled")
// If we are not reading from ClickHouse, we can return an empty map
// This is here just to have the possibility to turn off ClickHouse metrics reading
return make(map[string]api.SandboxMetric), nil
}

cluster, found := a.clusters.GetClusterById(clusterID)
if !found {
return nil, &api.APIError{
Expand Down Expand Up @@ -93,14 +83,6 @@ func (a *APIStore) GetSandboxesMetrics(c *gin.Context, params api.GetSandboxesMe
properties := a.posthog.GetPackageToPosthogProperties(&c.Request.Header)
a.posthog.CreateAnalyticsTeamEvent(ctx, team.ID.String(), "listed running instances with metrics", properties)

// Build the context for feature flags
ctx = featureflags.AddToContext(
ctx,
ldcontext.NewBuilder(team.ID.String()).
Kind(featureflags.TeamKind).
Build(),
)

sandboxesWithMetrics, apiErr := a.getSandboxesMetrics(ctx, team.ID, clusters.WithClusterFallback(team.ClusterID), params.SandboxIds)
if apiErr != nil {
telemetry.ReportCriticalError(ctx, "error fetching sandboxes metrics", apiErr.Err)
Expand Down
14 changes: 0 additions & 14 deletions packages/api/internal/handlers/team_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"github.com/e2b-dev/infra/packages/api/internal/api"
"github.com/e2b-dev/infra/packages/auth/pkg/auth"
clickhouseUtils "github.com/e2b-dev/infra/packages/clickhouse/pkg/utils"
"github.com/e2b-dev/infra/packages/shared/pkg/featureflags"
"github.com/e2b-dev/infra/packages/shared/pkg/logger"
"github.com/e2b-dev/infra/packages/shared/pkg/telemetry"
)

Expand All @@ -31,18 +29,6 @@ func (a *APIStore) GetTeamsTeamIDMetrics(c *gin.Context, teamID string, params a
return
}

metricsReadFlag := a.featureFlags.BoolFlag(ctx, featureflags.MetricsReadFlag)

if !metricsReadFlag {
logger.L().Debug(ctx, "sandbox metrics read feature flag is disabled")
// If we are not reading from ClickHouse, we can return an empty map
// This is here just to have the possibility to turn off ClickHouse metrics reading

c.JSON(http.StatusOK, []api.TeamMetric{})

return
}

// Default time range is the last 7 days
start, end := time.Now().Add(-defaultTimeRange), time.Now()
if params.Start != nil {
Expand Down
14 changes: 0 additions & 14 deletions packages/api/internal/handlers/team_metrics_max.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"github.com/e2b-dev/infra/packages/auth/pkg/auth"
clickhouse "github.com/e2b-dev/infra/packages/clickhouse/pkg"
clickhouseUtils "github.com/e2b-dev/infra/packages/clickhouse/pkg/utils"
"github.com/e2b-dev/infra/packages/shared/pkg/featureflags"
"github.com/e2b-dev/infra/packages/shared/pkg/logger"
"github.com/e2b-dev/infra/packages/shared/pkg/telemetry"
)

Expand All @@ -31,18 +29,6 @@ func (a *APIStore) GetTeamsTeamIDMetricsMax(c *gin.Context, teamID string, param
return
}

metricsReadFlag := a.featureFlags.BoolFlag(ctx, featureflags.MetricsReadFlag)

if !metricsReadFlag {
logger.L().Debug(ctx, "sandbox metrics read feature flag is disabled")
// If we are not reading from ClickHouse, we can return an empty map
// This is here just to have the possibility to turn off ClickHouse metrics reading

c.JSON(http.StatusOK, api.MaxTeamMetric{})

return
}

// Default time range is the last 7 days
start, end := time.Now().Add(-defaultTimeRange), time.Now()
if params.Start != nil {
Expand Down
4 changes: 0 additions & 4 deletions packages/orchestrator/pkg/metrics/sandboxes.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ func (so *SandboxObserver) startObserving() (metric.Registration, error) {
continue
}

if !sbx.Checks.UseClickhouseMetrics {
continue
}

wg.Go(func() error {
Comment thread
arkamar marked this conversation as resolved.
// Make sure the sandbox doesn't change while we are getting metrics (the slot could be assigned to another sandbox)
sbxMetrics, err := sbx.Checks.GetMetrics(ctx, timeoutGetMetrics)
Expand Down
9 changes: 3 additions & 6 deletions packages/orchestrator/pkg/sandbox/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,15 @@ type Checks struct {
stopped bool

healthy atomic.Bool

UseClickhouseMetrics bool
}

var ErrChecksStopped = errors.New("checks stopped")

func NewChecks(sandbox *Sandbox, useClickhouseMetrics bool) *Checks {
func NewChecks(sandbox *Sandbox) *Checks {
// Create background context, passed ctx is from create/resume request and will be canceled after the request is processed.
h := &Checks{
sandbox: sandbox,
healthy: atomic.Bool{}, // defaults to `false`
UseClickhouseMetrics: useClickhouseMetrics,
sandbox: sandbox,
healthy: atomic.Bool{}, // defaults to `false`
}

// By default, the sandbox should be healthy, if the status change we report it.
Expand Down
6 changes: 2 additions & 4 deletions packages/orchestrator/pkg/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,7 @@ func (f *Factory) CreateSandbox(
}
telemetry.ReportEvent(ctx, "created fc process")

useClickhouseMetrics := f.featureFlags.BoolFlag(ctx, featureflags.MetricsWriteFlag)
sbx.Checks = NewChecks(sbx, useClickhouseMetrics)
sbx.Checks = NewChecks(sbx)
Comment thread
arkamar marked this conversation as resolved.

// Stop the sandbox first if it is still running, otherwise do nothing
cleanup.AddPriority(ctx, sbx.Stop)
Expand Down Expand Up @@ -974,13 +973,12 @@ func (f *Factory) ResumeSandbox(
skipStartupMetrics: ropts.skipLiveRegistration,
}

useClickhouseMetrics := f.featureFlags.BoolFlag(ctx, featureflags.MetricsWriteFlag)
useMemfd := fc.FCSupportsMemfd(config.FirecrackerConfig.FirecrackerVersion) &&
f.featureFlags.BoolFlag(ctx, featureflags.UseMemFdFlag, sandboxLDContext(runtime, config))

// Part of the sandbox as we need to stop Checks before pausing the sandbox
// This is to prevent race condition of reporting unhealthy sandbox
sbx.Checks = NewChecks(sbx, useClickhouseMetrics)
sbx.Checks = NewChecks(sbx)

cleanup.AddPriority(ctx, func(ctx context.Context) error {
// Stop the sandbox first if it is still running, otherwise do nothing
Expand Down
2 changes: 0 additions & 2 deletions packages/shared/pkg/featureflags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ func OverrideJSONFlag(flag JSONFlag, value ldvalue.Value) {
}

var (
MetricsWriteFlag = NewBoolFlag("sandbox-metrics-write", true)
MetricsReadFlag = NewBoolFlag("sandbox-metrics-read", true)
SnapshotFeatureFlag = NewBoolFlag("use-nfs-for-snapshots", env.IsDevelopment())
TemplateFeatureFlag = NewBoolFlag("use-nfs-for-templates", env.IsDevelopment())
EnableWriteThroughCacheFlag = NewBoolFlag("write-to-cache-on-writes", false)
Expand Down
Loading