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
5 changes: 5 additions & 0 deletions apps/workspace-engine/oapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,10 @@
},
"type": "array"
},
"id": {
"format": "uuid",
"type": "string"
},
"releaseTarget": {
"$ref": "#/components/schemas/ReleaseTarget"
},
Expand All @@ -1641,6 +1645,7 @@
}
},
"required": [
"id",
"version",
"variables",
"encryptedVariables",
Expand Down
3 changes: 2 additions & 1 deletion apps/workspace-engine/oapi/spec/schemas/entities.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ local openapi = import '../lib/openapi.libsonnet';

Release: {
type: 'object',
required: ['version', 'variables', 'encryptedVariables', 'releaseTarget', 'createdAt'],
required: ['id', 'version', 'variables', 'encryptedVariables', 'releaseTarget', 'createdAt'],
properties: {
id: { type: 'string', format: 'uuid' },
version: openapi.schemaRef('DeploymentVersion'),
variables: {
type: 'object',
Expand Down
1 change: 1 addition & 0 deletions apps/workspace-engine/pkg/oapi/oapi.gen.go

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

4 changes: 2 additions & 2 deletions apps/workspace-engine/pkg/oapi/oapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/google/uuid"
)

func (r *Release) ID() string {
func (r *Release) ContentHash() string {
// Collect relevant fields for deterministic ID
var sb strings.Builder
sb.WriteString(r.Version.Id)
Expand Down Expand Up @@ -44,7 +44,7 @@ func (r *Release) ID() string {
}

func (r *Release) UUID() uuid.UUID {
return uuid.NewSHA1(uuid.NameSpaceOID, []byte(r.ID()))
return uuid.NewSHA1(uuid.NameSpaceOID, []byte(r.ContentHash()))
}

func toString(v any) string {
Expand Down
2 changes: 1 addition & 1 deletion apps/workspace-engine/pkg/oapi/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *System) CompactionKey() (string, string) {
}

func (r *Release) CompactionKey() (string, string) {
return "release", r.ID()
return "release", r.ContentHash()
}

func (j *Job) CompactionKey() (string, string) {
Expand Down
2 changes: 1 addition & 1 deletion apps/workspace-engine/pkg/persistence/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ func TestPersistence_ComplexWorkspaceWithComputedValues(t *testing.T) {
require.True(t, ok, "JobAgent should be restored")
assert.Equal(t, "k8s-agent", restoredJobAgent.Name)

restoredRelease, ok := newStore.Repo().Releases().Get(release.ID())
restoredRelease, ok := newStore.Repo().Releases().Get(release.ContentHash())
require.True(t, ok, "Release should be restored")
assert.Equal(t, "v1.2.3", restoredRelease.Version.Tag)

Expand Down
6 changes: 3 additions & 3 deletions apps/workspace-engine/pkg/workspace/jobs/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ func (f *Factory) CreateJobForRelease(ctx context.Context, release *oapi.Release

if action != nil {
action.AddStep("Create job", trace.StepResultPass,
fmt.Sprintf("Job created successfully with ID %s for release %s", jobId, release.ID())).
fmt.Sprintf("Job created successfully with ID %s for release %s", jobId, release.ContentHash())).
AddMetadata("job_id", jobId).
AddMetadata("job_status", string(oapi.JobStatusPending)).
AddMetadata("job_agent_id", jobAgent.Id).
AddMetadata("release_id", release.ID()).
AddMetadata("release_id", release.ContentHash()).
AddMetadata("version_tag", release.Version.Tag)
}

Expand All @@ -184,7 +184,7 @@ func (f *Factory) CreateJobForRelease(ctx context.Context, release *oapi.Release

return &oapi.Job{
Id: jobId,
ReleaseId: release.ID(),
ReleaseId: release.ContentHash(),
JobAgentId: jobAgent.Id,
JobAgentConfig: jobAgent.Config,
Status: oapi.JobStatusPending,
Expand Down
2 changes: 1 addition & 1 deletion apps/workspace-engine/pkg/workspace/jobs/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestFactory_CreateJobForRelease_SetsCorrectJobFields(t *testing.T) {
require.NoError(t, err)

// Verify release ID is correct
require.Equal(t, release.ID(), job.ReleaseId)
require.Equal(t, release.ContentHash(), job.ReleaseId)

// Verify job agent ID is correct
require.Equal(t, jobAgentId, job.JobAgentId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (o *Orchestrator) OnJobStatusChange(
return nil // No release found
}

span.SetAttributes(attribute.String("release.id", release.ID()))
span.SetAttributes(attribute.String("release.id", release.ContentHash()))

policies, err := o.store.ReleaseTargets.GetPolicies(ctx, &release.ReleaseTarget)
if err != nil {
Expand Down Expand Up @@ -97,7 +97,7 @@ func (o *Orchestrator) OnJobStatusChange(
log.Error("Policy action failed",
"action", action.Name(),
"job_id", job.Id,
"release_id", release.ID(),
"release_id", release.ContentHash(),
"error", err)
// Continue with other actions
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestOrchestrator_OnJobStatusChange_TriggerJobSuccess(t *testing.T) {
// Create job
job := &oapi.Job{
Id: uuid.New().String(),
ReleaseId: release.ID(),
ReleaseId: release.ContentHash(),
Status: oapi.JobStatusSuccessful,
CreatedAt: time.Now(),
}
Expand All @@ -172,7 +172,7 @@ func TestOrchestrator_OnJobStatusChange_TriggerJobSuccess(t *testing.T) {
assert.True(t, mockAct.executeCalled)
assert.Equal(t, action.TriggerJobSuccess, mockAct.lastTrigger)
assert.Equal(t, job.Id, mockAct.lastContext.Job.Id)
assert.Equal(t, release.ID(), mockAct.lastContext.Release.ID())
assert.Equal(t, release.ContentHash(), mockAct.lastContext.Release.ContentHash())
}

func TestOrchestrator_OnJobStatusChange_TriggerJobStarted(t *testing.T) {
Expand All @@ -190,7 +190,7 @@ func TestOrchestrator_OnJobStatusChange_TriggerJobStarted(t *testing.T) {

job := &oapi.Job{
Id: uuid.New().String(),
ReleaseId: release.ID(),
ReleaseId: release.ContentHash(),
Status: oapi.JobStatusInProgress,
CreatedAt: time.Now(),
}
Expand All @@ -217,7 +217,7 @@ func TestOrchestrator_OnJobStatusChange_TriggerJobFailure(t *testing.T) {

job := &oapi.Job{
Id: uuid.New().String(),
ReleaseId: release.ID(),
ReleaseId: release.ContentHash(),
Status: oapi.JobStatusFailure,
CreatedAt: time.Now(),
}
Expand All @@ -244,7 +244,7 @@ func TestOrchestrator_OnJobStatusChange_NoTrigger(t *testing.T) {

job := &oapi.Job{
Id: uuid.New().String(),
ReleaseId: release.ID(),
ReleaseId: release.ContentHash(),
Status: oapi.JobStatusInProgress,
CreatedAt: time.Now(),
}
Expand Down Expand Up @@ -272,7 +272,7 @@ func TestOrchestrator_OnJobStatusChange_ShouldNotExecute(t *testing.T) {

job := &oapi.Job{
Id: uuid.New().String(),
ReleaseId: release.ID(),
ReleaseId: release.ContentHash(),
Status: oapi.JobStatusSuccessful,
CreatedAt: time.Now(),
}
Expand Down Expand Up @@ -301,7 +301,7 @@ func TestOrchestrator_OnJobStatusChange_MultipleActions(t *testing.T) {

job := &oapi.Job{
Id: uuid.New().String(),
ReleaseId: release.ID(),
ReleaseId: release.ContentHash(),
Status: oapi.JobStatusSuccessful,
CreatedAt: time.Now(),
}
Expand Down Expand Up @@ -357,7 +357,7 @@ func TestOrchestrator_OnJobStatusChange_ActionError(t *testing.T) {

job := &oapi.Job{
Id: uuid.New().String(),
ReleaseId: release.ID(),
ReleaseId: release.ContentHash(),
Status: oapi.JobStatusSuccessful,
CreatedAt: time.Now(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (h *RollbackHooks) OnVerificationComplete(ctx context.Context, verification
}

span.SetAttributes(
attribute.String("release.id", release.ID()),
attribute.String("release.id", release.ContentHash()),
attribute.String("release_target.key", release.ReleaseTarget.Key()),
)

Expand All @@ -99,14 +99,14 @@ func (h *RollbackHooks) OnVerificationComplete(ctx context.Context, verification
}

// Don't rollback to the same release
if currentRelease.ID() == release.ID() {
if currentRelease.ContentHash() == release.ContentHash() {
span.AddEvent("Current release is the same as failed release, no rollback needed")
span.SetStatus(codes.Ok, "already on current release")
return nil
}

span.SetAttributes(
attribute.String("rollback_to_release.id", currentRelease.ID()),
attribute.String("rollback_to_release.id", currentRelease.ContentHash()),
attribute.String("rollback_to_version.id", currentRelease.Version.Id),
attribute.String("rollback_to_version.tag", currentRelease.Version.Tag),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (r *RollbackAction) Execute(

span.SetAttributes(
attribute.String("trigger", string(trigger)),
attribute.String("release.id", actx.Release.ID()),
attribute.String("release.id", actx.Release.ContentHash()),
attribute.String("job.id", actx.Job.Id),
attribute.String("job.status", string(actx.Job.Status)),
)
Expand All @@ -63,14 +63,14 @@ func (r *RollbackAction) Execute(
return nil
}

if currentRelease.ID() == actx.Release.ID() {
if currentRelease.ContentHash() == actx.Release.ContentHash() {
span.AddEvent("Current release is the same as failed release, no rollback needed")
span.SetStatus(codes.Ok, "already on current release")
return nil
}

span.SetAttributes(
attribute.String("rollback_to_release.id", currentRelease.ID()),
attribute.String("rollback_to_release.id", currentRelease.ContentHash()),
attribute.String("rollback_to_version.id", currentRelease.Version.Id),
attribute.String("rollback_to_version.tag", currentRelease.Version.Tag),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (v *VerificationAction) Execute(

span.SetAttributes(
attribute.String("trigger", string(trigger)),
attribute.String("release.id", actx.Release.ID()),
attribute.String("release.id", actx.Release.ContentHash()),
attribute.String("job.id", actx.Job.Id))

// Extract all verification metrics from matching policies
Expand All @@ -62,15 +62,15 @@ func (v *VerificationAction) Execute(
span.SetStatus(codes.Error, "failed to create verification")
log.Error("Failed to create verification",
"error", err,
"release_id", actx.Release.ID(),
"release_id", actx.Release.ContentHash(),
"job_id", actx.Job.Id,
"trigger", trigger)
return err
}

span.SetStatus(codes.Ok, "verification created")
log.Info("Created verification from policy action",
"release_id", actx.Release.ID(),
"release_id", actx.Release.ContentHash(),
"job_id", actx.Job.Id,
"trigger", trigger,
"metric_count", len(metrics))
Expand Down
Loading
Loading