Skip to content

Commit

Permalink
add scoped intrinsics support :
Browse files Browse the repository at this point in the history
  • Loading branch information
ie-pham committed Apr 30, 2024
1 parent d94e1f2 commit 8d82668
Show file tree
Hide file tree
Showing 9 changed files with 699 additions and 536 deletions.
2 changes: 1 addition & 1 deletion pkg/traceql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ func (Attribute) referencesSpan() bool {
func NewScopedAttribute(scope AttributeScope, parent bool, att string) Attribute {
intrinsic := IntrinsicNone
// if we are explicitly passed a resource or span scopes then we shouldn't parse for intrinsic
if scope != AttributeScopeResource && scope != AttributeScopeSpan {
if scope == AttributeScopeNone && !parent {
intrinsic = intrinsicFromString(att)
}

Expand Down
14 changes: 10 additions & 4 deletions pkg/traceql/ast_stringer.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,19 @@ func (a Attribute) String() string {
}

scope := ""
if len(scopes) > 0 {
scope = strings.Join(scopes, ".") + "."
// if one scope then just print scope
// if more than one scope it should be parent+scope which will then be joined by "."
if len(scopes) > 0 {
scope = strings.Join(scopes, ".")
}

// Top-level attributes get a "." but top-level intrinsics don't
if scope == "" && a.Intrinsic == IntrinsicNone && len(att) > 0 {
// add . or : if not intrinsinc

switch a.Intrinsic {
case IntrinsicNone:
scope += "."
default:
scope = ""
}

return scope + att
Expand Down
2 changes: 2 additions & 0 deletions pkg/traceql/enum_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Intrinsic int

const (
IntrinsicNone Intrinsic = iota
IntrinsicScoped
IntrinsicDuration
IntrinsicName
IntrinsicStatus
Expand Down Expand Up @@ -185,3 +186,4 @@ func intrinsicFromString(s string) Intrinsic {

return IntrinsicNone
}

22 changes: 19 additions & 3 deletions pkg/traceql/expr.y
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
intrinsicField Attribute
attributeField Attribute
attribute Attribute
scopedIntrinsicField Attribute

binOp Operator
staticInt int
Expand Down Expand Up @@ -75,6 +76,7 @@ import (
%type <static> static
%type <intrinsicField> intrinsicField
%type <attributeField> attributeField
%type <scopedIntrinsicField> scopedIntrinsicField
%type <attribute> attribute

%type <numericList> numericList
Expand All @@ -91,7 +93,7 @@ import (
NIL TRUE FALSE STATUS_ERROR STATUS_OK STATUS_UNSET
KIND_UNSPECIFIED KIND_INTERNAL KIND_SERVER KIND_CLIENT KIND_PRODUCER KIND_CONSUMER
IDURATION CHILDCOUNT NAME STATUS STATUS_MESSAGE PARENT KIND ROOTNAME ROOTSERVICENAME TRACEDURATION NESTEDSETLEFT NESTEDSETRIGHT NESTEDSETPARENT
PARENT_DOT RESOURCE_DOT SPAN_DOT
PARENT_DOT RESOURCE_DOT SPAN_DOT TRACE_COLON SPAN_COLON
COUNT AVG MAX MIN SUM
BY COALESCE SELECT
END_ATTRIBUTE
Expand Down Expand Up @@ -167,8 +169,9 @@ selectOperation:
;

attribute:
intrinsicField { $$ = $1 }
| attributeField { $$ = $1 }
intrinsicField { $$ = $1 }
| attributeField { $$ = $1 }
| scopedIntrinsicField { $$ = $1 }
;

attributeList:
Expand Down Expand Up @@ -328,6 +331,7 @@ fieldExpression:
| static { $$ = $1 }
| intrinsicField { $$ = $1 }
| attributeField { $$ = $1 }
| scopedIntrinsicField { $$ = $1 }
;

// **********************
Expand Down Expand Up @@ -368,6 +372,18 @@ intrinsicField:
| NESTEDSETPARENT { $$ = NewIntrinsic(IntrinsicNestedSetParent) }
;

scopedIntrinsicField:
// trace:
TRACE_COLON IDURATION { $$ = NewIntrinsic(IntrinsicTraceDuration) }
| TRACE_COLON ROOTNAME { $$ = NewIntrinsic(IntrinsicTraceRootSpan) }
| TRACE_COLON ROOTSERVICENAME { $$ = NewIntrinsic(IntrinsicTraceRootService) }
// span:
| SPAN_COLON IDURATION { $$ = NewIntrinsic(IntrinsicDuration) }
| SPAN_COLON NAME { $$ = NewIntrinsic(IntrinsicName) }
| SPAN_COLON KIND { $$ = NewIntrinsic(IntrinsicKind) }
| SPAN_COLON STATUS { $$ = NewIntrinsic(IntrinsicStatus) }
| SPAN_COLON STATUS_MESSAGE { $$ = NewIntrinsic(IntrinsicStatusMessage) }

attributeField:
DOT IDENTIFIER END_ATTRIBUTE { $$ = NewAttribute($2) }
| RESOURCE_DOT IDENTIFIER END_ATTRIBUTE { $$ = NewScopedAttribute(AttributeScopeResource, false, $2) }
Expand Down
Loading

0 comments on commit 8d82668

Please sign in to comment.