Skip to content

Commit

Permalink
Perform number matching for kind and status
Browse files Browse the repository at this point in the history
Signed-off-by: Zach Leslie <[email protected]>
  • Loading branch information
zalegrala committed May 2, 2023
1 parent de30000 commit 79151bb
Show file tree
Hide file tree
Showing 2 changed files with 292 additions and 78 deletions.
38 changes: 34 additions & 4 deletions pkg/spanfilter/spanfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ func policyMatchIntrinsicAttrs(policy *config.PolicyMatch, span *v1_trace.Span)
matches := 0

var attr traceql.Attribute
var spanKind, policyKind v1_trace.Span_SpanKind
var spanStatusCode, policyStatusCode v1_trace.Status_StatusCode

for _, pa := range policy.Attributes {
attr = traceql.MustParseIdentifier(pa.Key)
switch attr.Intrinsic {
Expand All @@ -113,13 +116,32 @@ func policyMatchIntrinsicAttrs(policy *config.PolicyMatch, span *v1_trace.Span)
}
matches++
case traceql.IntrinsicStatus:
if !stringMatch(policy.MatchType, span.GetStatus().GetCode().String(), pa.Value.(string)) {
return false
switch pa.Value.(type) {
case v1_trace.Status_StatusCode:
spanStatusCode = span.GetStatus().GetCode()
policyStatusCode = pa.Value.(v1_trace.Status_StatusCode)
if policy.MatchType == config.Strict && spanStatusCode != policyStatusCode {
return false
}
default:
if !stringMatch(policy.MatchType, span.GetStatus().GetCode().String(), pa.Value.(string)) {
return false
}
}
matches++
case traceql.IntrinsicKind:
if !stringMatch(policy.MatchType, span.GetKind().String(), pa.Value.(string)) {
return false
switch pa.Value.(type) {
case v1_trace.Span_SpanKind:
spanKind = span.GetKind()
policyKind = pa.Value.(v1_trace.Span_SpanKind)
if policy.MatchType == config.Strict && spanKind != policyKind {
return false
}
default:
if !stringMatch(policy.MatchType, span.GetKind().String(), pa.Value.(string)) {
return false
}

}
matches++
}
Expand Down Expand Up @@ -219,6 +241,14 @@ func getSplitPolicy(policy *config.PolicyMatch) *splitPolicy {
}

if attr.Intrinsic > 0 {
if policy.MatchType == config.Strict {
switch attr.Intrinsic {
case traceql.IntrinsicStatus:
attribute.Value = v1_trace.Status_StatusCode(v1_trace.Status_StatusCode_value[pa.Value.(string)])
case traceql.IntrinsicKind:
attribute.Value = v1_trace.Span_SpanKind(v1_trace.Span_SpanKind_value[pa.Value.(string)])
}
}
intrinsicPolicy.Attributes = append(intrinsicPolicy.Attributes, attribute)
} else {
switch attr.Scope {
Expand Down
Loading

0 comments on commit 79151bb

Please sign in to comment.