From 787c42ec3b9db73d7eacb01fb7ba6a58d46f48f3 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski <6207777+grcevski@users.noreply.github.com> Date: Fri, 21 Jun 2024 11:56:55 -0400 Subject: [PATCH] Improvements to matching (#42) * 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 --- testhelpers/tempo/responses/response_helpers.go | 15 +++++++++------ yaml/model.go | 1 + yaml/traces.go | 6 +++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/testhelpers/tempo/responses/response_helpers.go b/testhelpers/tempo/responses/response_helpers.go index 92f20ea..b127c28 100644 --- a/testhelpers/tempo/responses/response_helpers.go +++ b/testhelpers/tempo/responses/response_helpers.go @@ -5,10 +5,11 @@ 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 { @@ -16,10 +17,12 @@ func MatchTraceAttribute(attributes pcommon.Map, attrType pcommon.ValueType, 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) diff --git a/yaml/model.go b/yaml/model.go index 0b09bd4..70bf8f6 100644 --- a/yaml/model.go +++ b/yaml/model.go @@ -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 { diff --git a/yaml/traces.go b/yaml/traces.go index 0465cb4..1fd4281 100644 --- a/yaml/traces.go +++ b/yaml/traces.go @@ -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() {