Skip to content

Commit

Permalink
stmtdiagnostics: remove unused JSON trace datum
Browse files Browse the repository at this point in the history
In 2d05a54 we stopped writing JSON
trace datums to the system table, but some remnants of that work still
remained. This commit cleans that up.

Release note: None
  • Loading branch information
yuzefovich committed May 22, 2021
1 parent 040a7af commit ee801b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
33 changes: 11 additions & 22 deletions pkg/sql/explain_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,20 @@ func setExplainBundleResult(
return nil
}

// traceToJSON converts a trace to a JSON datum suitable for the
// system.statement_diagnostics.trace column. In case of error, the returned
// datum is DNull. Also returns the string representation of the trace.
// traceToJSON returns the string representation of the trace in JSON format.
//
// traceToJSON assumes that the first span in the recording contains all the
// other spans.
func traceToJSON(trace tracing.Recording) (tree.Datum, string, error) {
func traceToJSON(trace tracing.Recording) (string, error) {
root := normalizeSpan(trace[0], trace)
marshaller := jsonpb.Marshaler{
Indent: "\t",
}
str, err := marshaller.MarshalToString(&root)
if err != nil {
return tree.DNull, "", err
}
d, err := tree.ParseDJSON(str)
if err != nil {
return tree.DNull, "", err
return "", err
}
return d, str, nil
return str, nil
}

func normalizeSpan(s tracingpb.RecordedSpan, trace tracing.Recording) tracingpb.NormalizedSpan {
Expand All @@ -132,9 +126,6 @@ type diagnosticsBundle struct {
// Zip file binary data.
zip []byte

// Tracing data, as DJson (or DNull if it is not available).
traceJSON tree.Datum

// Stores any error in the collection, building, or insertion of the bundle.
collectionErr error

Expand Down Expand Up @@ -164,14 +155,14 @@ func buildStatementBundle(
b.addExecPlan(planString)
b.addDistSQLDiagrams()
b.addExplainVec()
traceJSON := b.addTrace()
b.addTrace()
b.addEnv(ctx)

buf, err := b.finalize()
if err != nil {
return diagnosticsBundle{collectionErr: err}
}
return diagnosticsBundle{traceJSON: traceJSON, zip: buf.Bytes()}
return diagnosticsBundle{zip: buf.Bytes()}
}

// insert the bundle in statement diagnostics. Sets bundle.diagID and (in error
Expand All @@ -192,7 +183,6 @@ func (bundle *diagnosticsBundle) insert(
diagRequestID,
fingerprint,
tree.AsString(ast),
bundle.traceJSON,
bundle.zip,
bundle.collectionErr,
)
Expand Down Expand Up @@ -328,10 +318,11 @@ func (b *stmtBundleBuilder) addExplainVec() {
}
}

// addTrace adds two files to the bundle: one is a json representation of the
// trace, the other one is a human-readable representation.
func (b *stmtBundleBuilder) addTrace() tree.Datum {
traceJSON, traceJSONStr, err := traceToJSON(b.trace)
// addTrace adds three files to the bundle: two are a json representation of the
// trace (the default and the jaeger formats), the third one is a human-readable
// representation.
func (b *stmtBundleBuilder) addTrace() {
traceJSONStr, err := traceToJSON(b.trace)
if err != nil {
b.z.AddFile("trace.json", err.Error())
} else {
Expand All @@ -358,8 +349,6 @@ func (b *stmtBundleBuilder) addTrace() tree.Datum {
} else {
b.z.AddFile("trace-jaeger.json", jaegerJSON)
}

return traceJSON
}

func (b *stmtBundleBuilder) addEnv(ctx context.Context) {
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/stmtdiagnostics/statement_diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ func (r *Registry) InsertStatementDiagnostics(
requestID RequestID,
stmtFingerprint string,
stmt string,
traceJSON tree.Datum,
bundle []byte,
collectionErr error,
) (CollectedInstanceID, error) {
Expand Down

0 comments on commit ee801b2

Please sign in to comment.