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
3 changes: 0 additions & 3 deletions app/controlplane/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,6 @@ func workflowRunExpirerOpts(c *conf.Bootstrap) *biz.WorkflowRunExpirerOpts {
if configured := c.GetAttestations().GetWorkflowRunExpirationCheckInterval(); configured != nil {
opts.CheckInterval = configured.AsDuration()
}
if configured := c.GetAttestations().GetWorkflowRunEventsRetention(); configured != nil {
opts.EventsRetention = configured.AsDuration()
}

return opts
}
Expand Down
22 changes: 14 additions & 8 deletions app/controlplane/cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func TestWorkflowRunExpirerOptsMapping(t *testing.T) {
config *conf.Bootstrap
want time.Duration
wantCheckInterval time.Duration
wantRetention time.Duration
}{
{
name: "missing attestations configuration",
Expand All @@ -56,12 +55,10 @@ func TestWorkflowRunExpirerOptsMapping(t *testing.T) {
Attestations: &conf.Attestations{
WorkflowRunExpirationWindow: durationpb.New(2 * time.Hour),
WorkflowRunExpirationCheckInterval: durationpb.New(30 * time.Second),
WorkflowRunEventsRetention: durationpb.New(24 * time.Hour),
},
},
wantCheckInterval: 30 * time.Second,
want: 2 * time.Hour,
wantRetention: 24 * time.Hour,
},
}

Expand All @@ -70,7 +67,6 @@ func TestWorkflowRunExpirerOptsMapping(t *testing.T) {
opts := workflowRunExpirerOpts(tt.config)
assert.Equal(t, tt.want, opts.ExpirationWindow)
assert.Equal(t, tt.wantCheckInterval, opts.CheckInterval)
assert.Equal(t, tt.wantRetention, opts.EventsRetention)
})
}
}
Expand Down Expand Up @@ -181,7 +177,6 @@ func TestHelmChartWorkflowRunExpirationDefaults(t *testing.T) {
Attestations struct {
WorkflowRunExpirationWindow string `json:"workflowRunExpirationWindow"`
WorkflowRunExpirationCheckInterval string `json:"workflowRunExpirationCheckInterval"`
WorkflowRunEventsRetention string `json:"workflowRunEventsRetention"`
} `json:"attestations"`
} `json:"controlplane"`
}
Expand All @@ -192,8 +187,8 @@ func TestHelmChartWorkflowRunExpirationDefaults(t *testing.T) {

attestations := values.Controlplane.Attestations
// Same shape as templates/controlplane/configmap.yaml
rendered := fmt.Sprintf("attestations:\n workflow_run_expiration_window: %q\n workflow_run_expiration_check_interval: %q\n workflow_run_events_retention: %q\n",
attestations.WorkflowRunExpirationWindow, attestations.WorkflowRunExpirationCheckInterval, attestations.WorkflowRunEventsRetention)
rendered := fmt.Sprintf("attestations:\n workflow_run_expiration_window: %q\n workflow_run_expiration_check_interval: %q\n",
attestations.WorkflowRunExpirationWindow, attestations.WorkflowRunExpirationCheckInterval)

configPath := filepath.Join(t.TempDir(), "config.yaml")
require.NoError(t, os.WriteFile(configPath, []byte(rendered), 0o600))
Expand All @@ -202,7 +197,18 @@ func TestHelmChartWorkflowRunExpirationDefaults(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, time.Hour, bootstrap.GetAttestations().GetWorkflowRunExpirationWindow().AsDuration())
assert.Equal(t, time.Minute, bootstrap.GetAttestations().GetWorkflowRunExpirationCheckInterval().AsDuration())
assert.Equal(t, 90*24*time.Hour, bootstrap.GetAttestations().GetWorkflowRunEventsRetention().AsDuration())
}

// A configuration that still sets the removed run events retention loads, so that an
// upgrade does not break the control plane. The events are now kept for the life of the run.
func TestRemovedWorkflowRunEventsRetentionIsIgnored(t *testing.T) {
configPath := filepath.Join(t.TempDir(), "config.yaml")
rendered := "attestations:\n workflow_run_expiration_window: \"3600s\"\n workflow_run_events_retention: \"7776000s\"\n"
require.NoError(t, os.WriteFile(configPath, []byte(rendered), 0o600))

bootstrap, err := loadBootstrap(t, configPath)
require.NoError(t, err)
assert.Equal(t, time.Hour, bootstrap.GetAttestations().GetWorkflowRunExpirationWindow().AsDuration())
}

// loadBootstrap loads a configuration file the same way as main.
Expand Down
2 changes: 1 addition & 1 deletion app/controlplane/cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 26 additions & 40 deletions app/controlplane/internal/conf/controlplane/config/v1/conf.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,9 @@ message Attestations {
// or KMS. When unset, it defaults to true.
optional bool force_verification = 5;

// Age after which the progress events of the workflow runs are deleted. The
// runs and their attestations stay. When unset, the control plane defaults
// to 90 days.
// In YAML configuration, use seconds with an "s" suffix, for example "7776000s".
google.protobuf.Duration workflow_run_events_retention = 6 [(buf.validate.field).duration.gt = {}];
// Workflow run events are kept for the life of the run
reserved 6;
reserved "workflow_run_events_retention";
}

message OperationAuthorizationProvider {
Expand Down
73 changes: 0 additions & 73 deletions app/controlplane/pkg/biz/mocks/WorkflowRunEventRepo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 3 additions & 38 deletions app/controlplane/pkg/biz/workflowrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,37 +178,30 @@ type PromObservable interface {
type WorkflowRunExpirerUseCase struct {
wfRunRepo WorkflowRunRepo
PromObservable PromObservable
runEvents *WorkflowRunEventUseCase
logger *log.Helper
}

const (
defaultWorkflowRunExpirationWindow = time.Hour
defaultWorkflowRunExpirationCheckInterval = time.Minute
defaultWorkflowRunEventsRetention = 90 * 24 * time.Hour
// number of old run events deleted in each batch of a sweep
workflowRunEventsDeleteBatchSize = 1000
)

type WorkflowRunExpirerOpts struct {
// Maximum time threshold for what a workflowRun will be considered expired. Defaults to 1 hour.
ExpirationWindow time.Duration
// Interval between expiration sweeps. Defaults to 1 minute.
CheckInterval time.Duration
// Age after which the progress events of the runs are deleted. Defaults to 90 days.
EventsRetention time.Duration
}

func NewWorkflowRunExpirerUseCase(wfrRepo WorkflowRunRepo, po PromObservable, runEvents *WorkflowRunEventUseCase, logger log.Logger) *WorkflowRunExpirerUseCase {
func NewWorkflowRunExpirerUseCase(wfrRepo WorkflowRunRepo, po PromObservable, logger log.Logger) *WorkflowRunExpirerUseCase {
logger = log.With(logger, "component", "biz.WorkflowRunExpirer")
return &WorkflowRunExpirerUseCase{wfRunRepo: wfrRepo, PromObservable: po, runEvents: runEvents, logger: log.NewHelper(logger)}
return &WorkflowRunExpirerUseCase{wfRunRepo: wfrRepo, PromObservable: po, logger: log.NewHelper(logger)}
}

func resolveWorkflowRunExpirerOpts(opts *WorkflowRunExpirerOpts) WorkflowRunExpirerOpts {
resolved := WorkflowRunExpirerOpts{
ExpirationWindow: defaultWorkflowRunExpirationWindow,
CheckInterval: defaultWorkflowRunExpirationCheckInterval,
EventsRetention: defaultWorkflowRunEventsRetention,
}
if opts == nil {
return resolved
Expand All @@ -219,9 +212,6 @@ func resolveWorkflowRunExpirerOpts(opts *WorkflowRunExpirerOpts) WorkflowRunExpi
if opts.CheckInterval > 0 {
resolved.CheckInterval = opts.CheckInterval
}
if opts.EventsRetention > 0 {
resolved.EventsRetention = opts.EventsRetention
}

return resolved
}
Expand All @@ -242,38 +232,13 @@ func (uc *WorkflowRunExpirerUseCase) Run(ctx context.Context, opts *WorkflowRunE
if err := uc.ExpirationSweep(ctx, threshold); err != nil {
uc.logger.Error(err)
}

if err := uc.EventsRetentionSweep(ctx, time.Now().Add(-resolvedOpts.EventsRetention)); err != nil {
uc.logger.Error(err)
}
}

timer.Reset(resolvedOpts.CheckInterval)
}
}()

uc.logger.Infof("periodic check enabled. interval=%s, expirationWindow=%s, eventsRetention=%s", resolvedOpts.CheckInterval, resolvedOpts.ExpirationWindow, resolvedOpts.EventsRetention)
}

// EventsRetentionSweep deletes the progress events created before olderThan. The runs stay.
func (uc *WorkflowRunExpirerUseCase) EventsRetentionSweep(ctx context.Context, olderThan time.Time) error {
ctx, span := otelx.Start(ctx, workflowRunTracer, "WorkflowRunExpirerUseCase.EventsRetentionSweep")
defer span.End()

if uc.runEvents == nil {
return nil
}

n, err := uc.runEvents.DeleteOlderThan(ctx, olderThan, workflowRunEventsDeleteBatchSize)
if err != nil {
return err
}

if n > 0 {
uc.logger.Debugf("deleted %d workflow run events older than %s", n, olderThan.Format(time.RFC822))
}

return nil
uc.logger.Infof("periodic check enabled. interval=%s, expirationWindow=%s", resolvedOpts.CheckInterval, resolvedOpts.ExpirationWindow)
}

// ExpirationSweep looks for runs older than the provider time and marks them as expired
Expand Down
Loading
Loading