Skip to content

Commit

Permalink
Improvements to matching (#42)
Browse files Browse the repository at this point in the history
* Add extra logging, allow for custom response codes

* Prefix test runs

* Don't verify value types, all things get converted to strings

* Allow duplicate spans for retries
  • Loading branch information
grcevski authored Jun 21, 2024
1 parent 14a51d8 commit 787c42e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
15 changes: 9 additions & 6 deletions testhelpers/tempo/responses/response_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
"regexp"
"strings"

"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
)

func MatchTraceAttribute(attributes pcommon.Map, attrType pcommon.ValueType, key, value string) error {
att, found := attributes.Get(key)
if !found {
return fmt.Errorf("couldn't find attribute %s", key)
}
valueType := att.Type()
if valueType != attrType {
return fmt.Errorf("value type for key %s is %s which doesn't match the expect type %s", key, valueType, attrType)
}

// We convert to strings anyway, if this check is here you can't match Int values in traces
// valueType := att.Type()
// if valueType != attrType {
// return fmt.Errorf("value type for key %s is %s which doesn't match the expect type %s", key, valueType, attrType)
// }

if value != "" && !matcherMaybeRegex(value)(att.AsString()) {
return fmt.Errorf("value for key %s is %s which doesn't match the expect value %s", key, att.AsString(), value)
Expand Down
1 change: 1 addition & 0 deletions yaml/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ExpectedMetrics struct {
type ExpectedSpan struct {
Name string `yaml:"name"`
Attributes map[string]string `yaml:"attributes"`
AllowDups bool `yaml:"allow-duplicates"`
}

type ExpectedLogs struct {
Expand Down
6 changes: 5 additions & 1 deletion yaml/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ func assertTrace(r *runner, tr responses.Trace, wantSpans []ExpectedSpan) {

for _, wantSpan := range wantSpans {
spans, atts := responses.FindSpansWithAttributes(td, wantSpan.Name)
g.Expect(spans).To(HaveLen(1), "we should find a single span with the name %s", wantSpan.Name)
if wantSpan.AllowDups {
g.Expect(len(spans)).Should(BeNumerically(">", 0), "we should find at least one span with the name %s", wantSpan.Name)
} else {
g.Expect(spans).To(HaveLen(1), "we should find a single span with the name %s", wantSpan.Name)
}

for k, v := range wantSpan.Attributes {
for k, v := range spans[0].Attributes().AsRaw() {
Expand Down

0 comments on commit 787c42e

Please sign in to comment.