SQL Expressions: Rework backend errors and error instrumentation (#109633)
* Capture error_type label on metrics/traces * Make error messages more helpful to user * Use errutil, categorized errors, and tie them to error_type (category in code) * Misc trace fixes * Add metric to track SQL input conversion
This commit is contained in:
+30
-6
@@ -32,8 +32,9 @@ var (
|
||||
|
||||
// baseNode includes common properties used across DPNodes.
|
||||
type baseNode struct {
|
||||
id int64
|
||||
refID string
|
||||
id int64
|
||||
refID string
|
||||
isInputTo map[string]struct{}
|
||||
}
|
||||
|
||||
type rawNode struct {
|
||||
@@ -91,6 +92,17 @@ func (b *baseNode) RefID() string {
|
||||
return b.refID
|
||||
}
|
||||
|
||||
func (b *baseNode) SetInputTo(refID string) {
|
||||
if b.isInputTo == nil {
|
||||
b.isInputTo = make(map[string]struct{})
|
||||
}
|
||||
b.isInputTo[refID] = struct{}{}
|
||||
}
|
||||
|
||||
func (b *baseNode) IsInputTo() map[string]struct{} {
|
||||
return b.isInputTo
|
||||
}
|
||||
|
||||
// NodeType returns the data pipeline node type.
|
||||
func (gn *CMDNode) NodeType() NodeType {
|
||||
return TypeCMDNode
|
||||
@@ -367,7 +379,7 @@ func executeDSNodesGrouped(ctx context.Context, now time.Time, vars mathexp.Vars
|
||||
}
|
||||
|
||||
var result mathexp.Results
|
||||
responseType, result, err := s.converter.Convert(ctx, dn.datasource.Type, dataFrames, dn.isInputToSQLExpr)
|
||||
responseType, result, err := s.converter.Convert(ctx, dn.datasource.Type, dataFrames)
|
||||
if err != nil {
|
||||
result.Error = makeConversionError(dn.RefID(), err)
|
||||
}
|
||||
@@ -457,10 +469,22 @@ func (dn *DSNode) Execute(ctx context.Context, now time.Time, _ mathexp.Vars, s
|
||||
|
||||
var result mathexp.Results
|
||||
|
||||
responseType, result, err = s.converter.Convert(ctx, dn.datasource.Type, dataFrames, dn.isInputToSQLExpr)
|
||||
if dn.isInputToSQLExpr {
|
||||
var converted bool
|
||||
dataType := categorizeFrameInputType(dataFrames)
|
||||
|
||||
if err != nil {
|
||||
err = makeConversionError(dn.refID, err)
|
||||
result, converted = handleSqlInput(ctx, s.tracer, dn.RefID(), dn.IsInputTo(), dn.datasource.Type, dataFrames)
|
||||
status := "ok"
|
||||
if result.Error != nil {
|
||||
status = "error"
|
||||
}
|
||||
s.metrics.SqlCommandInputCount.WithLabelValues(status, fmt.Sprintf("%t", converted), dn.datasource.Type, dataType).Inc()
|
||||
} else {
|
||||
responseType, result, err = s.converter.Convert(ctx, dn.datasource.Type, dataFrames)
|
||||
if err != nil {
|
||||
err = makeConversionError(dn.refID, err)
|
||||
}
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user