Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Fix trace query with int values and check resource tags during evalua…
Browse files Browse the repository at this point in the history
…tion.

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>

This commit fixes 2 issues in trace querying. They are:
1. Query returns no result when queried with a numeric value tag like `http.status_code=200`
2. Query returns no result when queried with a tag that is from Process table in Jaeger UI
  • Loading branch information
Harkishen-Singh committed Jun 3, 2022
1 parent 56bb291 commit 823ab4a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ We use the following categories for changes:
- Add `readinessProbe` in helm chart [#1266]

### Fixed
- Fix trace querying by status code tag [#1384]
- Trace query returns empty result when queried with
- Tags from process table in Jaeger UI [#1385]
- Tags that have a numeric value, like `http.status_code=200` [#1385]
- Tags that involve status code [#1384]

## [0.11.0] - 2022-05-11

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require (
github.com/thanos-io/thanos v0.25.2
go.opentelemetry.io/collector/model v0.49.0
go.opentelemetry.io/collector/pdata v0.49.0
go.opentelemetry.io/collector/semconv v0.52.0 // indirect
go.opentelemetry.io/collector/semconv v0.52.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.32.0
go.opentelemetry.io/otel v1.7.0
go.opentelemetry.io/otel/exporters/jaeger v1.6.3
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2076,10 +2076,6 @@ go.opentelemetry.io/collector/pdata v0.49.0 h1:aYj5rOlRC0x7lGXbc185LMsMMoY/pjOTX
go.opentelemetry.io/collector/pdata v0.49.0/go.mod h1:YwmKuiFhNgtmhRdpi8Q8FAWPa0AwJTCSlssSsAtuRcY=
go.opentelemetry.io/collector/semconv v0.52.0 h1:ogYkQ6WL01xQ4GGSwWQejNTQwy/Pwcd6jCKFLSd7svA=
go.opentelemetry.io/collector/semconv v0.52.0/go.mod h1:SxK0rUnUP7YeDakexzbE/vhimTOHwE6m/4aKKd9e27Q=
go.opentelemetry.io/contrib v0.20.0 h1:ubFQUn0VCZ0gPwIoJfBJVpeBlyRMxu8Mm/huKWYd9p0=
go.opentelemetry.io/contrib v0.20.0/go.mod h1:G/EtFaa6qaN7+LxqfIAT3GiZa7Wv5DTBUzl5H4LY0Kc=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0/go.mod h1:oVGt1LRbBOBq1A5BQLlUg9UaU/54aiHw8cgjV3aWZ/E=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.28.0/go.mod h1:vEhqr0m4eTc+DWxfsXoXue2GBgV2uUwVznkGIHW/e5w=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.31.0/go.mod h1:SY9qHHUES6W3oZnO1H2W8NvsSovIoXRg/A1AH9px8+I=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.31.0/go.mod h1:PFmBsWbldL1kiWZk9+0LBZz2brhByaGsvp6pRICMlPE=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.32.0 h1:mac9BKRqwaX6zxHPDe3pvmWpwuuIM0vuXv2juCnQevE=
Expand Down
21 changes: 19 additions & 2 deletions pkg/jaeger/query/trace_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"github.com/grafana/regexp"
"github.com/jackc/pgtype"
"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/storage/spanstore"
Expand Down Expand Up @@ -117,6 +118,8 @@ const (
TagW3CTraceState = "w3c.tracestate"
)

var digitCheck = regexp.MustCompile(`^[0-9]+$`)

type Builder struct {
cfg *Config
}
Expand Down Expand Up @@ -237,8 +240,22 @@ func (b *Builder) buildTraceIDSubquery(q *spanstore.TraceQueryParameters) (strin
clauses = append(clauses, qual)
default:
//TODO make sure this is optimized correctly
params = append(params, k, "\""+v+"\"")
qual := fmt.Sprintf(`_ps_trace.tag_map_denormalize(s.span_tags)->$%d = $%d`, len(params)-1, len(params))
val := "\"" + v + "\""
if digitCheck.MatchString(v) {
// Do not add double quotes if value is numeric.
// This allows to query via tags that are like `http.status_code=200`
//
// Note: We can remove this block once the `->` operator becomes
// generic and respects integers, booleans, etc.
val = v
}
params = append(params, k, val)
// Note: We do not need to check resource tags in above cases, since they
// come from Jaeger conversion that are specific to span_tags.
qual := fmt.Sprintf(
`(_ps_trace.tag_map_denormalize(s.span_tags)->$%[1]d = $%[2]d OR _ps_trace.tag_map_denormalize(s.resource_tags)->$%[1]d = $%[2]d)`,
len(params)-1, len(params),
len(params)-1, len(params))
clauses = append(clauses, qual)
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/tests/end_to_end_tests/dataset_traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (
"span-attr": pcommon.NewValueString("span-attr-val"),
"host.name": pcommon.NewValueString("hostname1"),
"opencensus.exporterversion": pcommon.NewValueString("Jaeger-1.0.0"),
"http.status_code": pcommon.NewValueInt(200),
},
)
spanEventAttributes = pdata.NewAttributeMapFromMap(map[string]pcommon.Value{"span-event-attr": pcommon.NewValueString("span-event-attr-val")})
Expand Down
9 changes: 5 additions & 4 deletions pkg/tests/end_to_end_tests/trace_query_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,11 @@ type httpClient struct {
}

const (
servicesEndpoint = "%s/api/services"
operationsEndpoint = "%s/api/services/%s/operations"
singleTraceEndpoint = "%s/api/traces/%s"
fetchTracesEndpoint = "%s/api/traces?start=%d&end=%d&service=%s&lookback=custom&limit=20&maxDuration&minDuration"
servicesEndpoint = "%s/api/services"
operationsEndpoint = "%s/api/services/%s/operations"
singleTraceEndpoint = "%s/api/traces/%s"
fetchTracesEndpoint = "%s/api/traces?start=%d&end=%d&service=%s&lookback=custom&limit=20&maxDuration&minDuration"
fetchTracesEndpointWithTag = "%s/api/traces?start=%d&end=%d&service=%s&lookback=custom&limit=20&maxDuration&minDuration"
)

func getServices(t testing.TB, c httpClient) []string {
Expand Down

0 comments on commit 823ab4a

Please sign in to comment.