Skip to content

feat: unified tracing between coderd<->provisionerd #7370

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

Merged
merged 3 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
trace_metadata
  • Loading branch information
coadler committed May 3, 2023
commit e185a6c5a134418872a17b9b08d0920d95afa888
2 changes: 1 addition & 1 deletion coderd/database/dump.sql

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
@@ -1 +1 @@
ALTER TABLE provisioner_jobs DROP COLUMN metadata;
ALTER TABLE provisioner_jobs DROP COLUMN trace_metadata;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ALTER TABLE provisioner_jobs ADD COLUMN metadata jsonb;
ALTER TABLE provisioner_jobs ADD COLUMN trace_metadata jsonb;
2 changes: 1 addition & 1 deletion coderd/database/models.go

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

26 changes: 13 additions & 13 deletions coderd/database/queries.sql.go

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

2 changes: 1 addition & 1 deletion coderd/database/queries/provisionerjobs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ INSERT INTO
"type",
"input",
tags,
metadata
trace_metadata
)
VALUES
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING *;
Expand Down
16 changes: 8 additions & 8 deletions coderd/provisionerdserver/provisionerdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,20 @@ func (server *Server) AcquireJob(ctx context.Context, _ *proto.Empty) (*proto.Ac
return nil, failJob(fmt.Sprintf("get user: %s", err))
}

jobMetadata := map[string]string{}
if job.Metadata.Valid {
err := json.Unmarshal(job.Metadata.RawMessage, &jobMetadata)
jobTraceMetadata := map[string]string{}
if job.TraceMetadata.Valid {
err := json.Unmarshal(job.TraceMetadata.RawMessage, &jobTraceMetadata)
if err != nil {
return nil, failJob(fmt.Sprintf("unmarshal metadata: %s", err))
}
}

protoJob := &proto.AcquiredJob{
JobId: job.ID.String(),
CreatedAt: job.CreatedAt.UnixMilli(),
Provisioner: string(job.Provisioner),
UserName: user.Username,
Metadata: jobMetadata,
JobId: job.ID.String(),
CreatedAt: job.CreatedAt.UnixMilli(),
Provisioner: string(job.Provisioner),
UserName: user.Username,
TraceMetadata: jobTraceMetadata,
}

switch job.Type {
Expand Down
8 changes: 4 additions & 4 deletions coderd/templateversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ func (api *API) postTemplateVersionDryRun(rw http.ResponseWriter, r *http.Reques
Input: input,
// Copy tags from the previous run.
Tags: job.Tags,
Metadata: pqtype.NullRawMessage{
TraceMetadata: pqtype.NullRawMessage{
Valid: true,
RawMessage: metadataRaw,
},
Expand Down Expand Up @@ -1423,7 +1423,7 @@ func (api *API) postTemplateVersionsByOrganization(rw http.ResponseWriter, r *ht
if err != nil {
return xerrors.Errorf("marshal job input: %w", err)
}
metadataRaw, err := json.Marshal(tracing.MetadataFromContext(ctx))
traceMetadataRaw, err := json.Marshal(tracing.MetadataFromContext(ctx))
if err != nil {
return xerrors.Errorf("marshal job metadata: %w", err)
}
Expand All @@ -1440,9 +1440,9 @@ func (api *API) postTemplateVersionsByOrganization(rw http.ResponseWriter, r *ht
Type: database.ProvisionerJobTypeTemplateVersionImport,
Input: jobInput,
Tags: tags,
Metadata: pqtype.NullRawMessage{
TraceMetadata: pqtype.NullRawMessage{
Valid: true,
RawMessage: metadataRaw,
RawMessage: traceMetadataRaw,
},
})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions coderd/workspacebuilds.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ func (api *API) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) {
if err != nil {
return xerrors.Errorf("marshal provision job: %w", err)
}
metadataRaw, err := json.Marshal(tracing.MetadataFromContext(ctx))
traceMetadataRaw, err := json.Marshal(tracing.MetadataFromContext(ctx))
if err != nil {
return xerrors.Errorf("marshal metadata: %w", err)
}
Expand All @@ -624,9 +624,9 @@ func (api *API) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) {
FileID: templateVersionJob.FileID,
Input: input,
Tags: tags,
Metadata: pqtype.NullRawMessage{
TraceMetadata: pqtype.NullRawMessage{
Valid: true,
RawMessage: metadataRaw,
RawMessage: traceMetadataRaw,
},
})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
if err != nil {
return xerrors.Errorf("marshal provision job: %w", err)
}
metadataRaw, err := json.Marshal(tracing.MetadataFromContext(ctx))
traceMetadataRaw, err := json.Marshal(tracing.MetadataFromContext(ctx))
if err != nil {
return xerrors.Errorf("marshal metadata: %w", err)
}
Expand All @@ -532,9 +532,9 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
FileID: templateVersionJob.FileID,
Input: input,
Tags: tags,
Metadata: pqtype.NullRawMessage{
TraceMetadata: pqtype.NullRawMessage{
Valid: true,
RawMessage: metadataRaw,
RawMessage: traceMetadataRaw,
},
})
if err != nil {
Expand Down
Loading