Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(queue): add new fields to job JSON #3115

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions server/executor/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/kubeshop/tracetest/server/test"
"github.com/kubeshop/tracetest/server/testsuite"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
)

const (
Expand Down Expand Up @@ -84,40 +85,51 @@ type Job struct {
DataStore datastore.DataStore
}

type jsonJob struct {
type JsonJob struct {
Headers *headers `json:"headers"`
TestSuiteID string `json:"test_suite_id"`
TestSuiteRunID int `json:"test_suite_run_id"`
TestID string `json:"test_id"`
TestVersion int `json:"test_version"`
RunID int `json:"run_id"`
TraceID string `json:"trace_id"`
PollingProfileID string `json:"polling_profile_id"`
DataStoreID string `json:"data_store_id"`
}

func (job Job) MarshalJSON() ([]byte, error) {
return json.Marshal(jsonJob{
return json.Marshal(JsonJob{
Headers: job.Headers,
TestSuiteID: job.TestSuite.ID.String(),
TestSuiteRunID: job.TestSuiteRun.ID,
TestID: job.Test.ID.String(),
TestVersion: job.Run.TestVersion,
RunID: job.Run.ID,
TraceID: job.Run.TraceID.String(),
PollingProfileID: job.PollingProfile.ID.String(),
DataStoreID: job.DataStore.ID.String(),
})
}

func (job *Job) UnmarshalJSON(data []byte) error {
var jj jsonJob
var jj JsonJob
err := json.Unmarshal(data, &jj)
if err != nil {
return err
}

traceID, err := trace.TraceIDFromHex(jj.TraceID)
if err != nil {
return err
}

job.Headers = jj.Headers
job.TestSuite.ID = id.ID(jj.TestSuiteID)
job.TestSuiteRun.ID = jj.TestSuiteRunID
job.Test.ID = id.ID(jj.TestID)
job.Run.ID = jj.RunID
job.Run.TestVersion = jj.TestVersion
job.Run.TraceID = traceID
job.PollingProfile.ID = id.ID(jj.PollingProfileID)
job.DataStore.ID = id.ID(jj.DataStoreID)

Expand Down Expand Up @@ -328,7 +340,7 @@ func (q Queue) Enqueue(ctx context.Context, job Job) {
Headers: job.Headers,

Test: test.Test{ID: job.Test.ID},
Run: test.Run{ID: job.Run.ID, TestVersion: version},
Run: test.Run{ID: job.Run.ID, TestVersion: version, TraceID: job.Run.TraceID},

TestSuite: testsuite.TestSuite{ID: job.TestSuite.ID},
TestSuiteRun: testsuite.TestSuiteRun{ID: job.TestSuiteRun.ID},
Expand Down