Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zjanc committed Feb 17, 2023
1 parent c3a8230 commit 0ed2fe1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
29 changes: 27 additions & 2 deletions exporter/loadbalancingexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ loadbalancing:
resolver:
static:
hostnames:
- endpoint-1 # assumes 4317 as the default port
- endpoint-2:55678
- endpoint-1 # assumes 4317 as the default port
- endpoint-2:55678
loadbalancing/2:
protocol:
otlp:
Expand All @@ -27,3 +27,28 @@ loadbalancing/3:
dns:
hostname: service-1
port: 55690
loadbalancing/4:
protocol:
otlp:
resolver:
dns:
hostname: service-1
port: 55690
routing_key: traceID
loadbalancing/5:
protocol:
otlp:
resolver:
dns:
hostname: service-1
port: 55690
routing_key: service
loadbalancing/6:
protocol:
otlp:
resolver:
dns:
hostname: service-1
port: 55690
routing_key: resourceAttr
resource_attr_key: "resource.attribute"
36 changes: 21 additions & 15 deletions exporter/loadbalancingexporter/trace_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,26 +203,28 @@ func TestConsumeTracesServiceBased(t *testing.T) {
func TestServiceBasedRoutingForSameTraceId(t *testing.T) {
b := pcommon.TraceID([16]byte{1, 2, 3, 4})
for _, tt := range []struct {
desc string
batch ptrace.Traces
routingKey routingKey
res map[string][]int
desc string
batch ptrace.Traces
rf routingFunction
res map[string][]int
}{
{
"same trace id and different services - service based routing",
twoServicesWithSameTraceID(),
svcRouting,
func(t ptrace.Traces) (map[string][]int, error) {
return routeByResourceAttr(t, "service.name")
},
map[string][]int{"ad-service-1": {0}, "get-recommendations-7": {1}},
},
{
"same trace id and different services - trace id routing",
twoServicesWithSameTraceID(),
traceIDRouting,
routeByTraceId,
map[string][]int{string(b[:]): {0, 1}},
},
} {
t.Run(tt.desc, func(t *testing.T) {
res, err := routingIdentifiersFromTraces(tt.batch, tt.routingKey, "")
res, err := tt.rf(tt.batch)
assert.Equal(t, err, nil)
assert.Equal(t, res, tt.res)
})
Expand Down Expand Up @@ -359,15 +361,16 @@ func TestBatchWithTwoTraces(t *testing.T) {

func TestNoTracesInBatch(t *testing.T) {
for _, tt := range []struct {
desc string
batch ptrace.Traces
routingKey routingKey
err error
desc string
batch ptrace.Traces
rf routingFunction
err error
}{
// Trace ID routing
{
"no resource spans",
ptrace.NewTraces(),
traceIDRouting,
routeByTraceId,
errors.New("empty resource spans"),
},
{
Expand All @@ -377,22 +380,25 @@ func TestNoTracesInBatch(t *testing.T) {
batch.ResourceSpans().AppendEmpty()
return batch
}(),
traceIDRouting,
routeByTraceId,
errors.New("empty scope spans"),
},
// Service / Resource Attribute routing
{
"no spans",
func() ptrace.Traces {
batch := ptrace.NewTraces()
batch.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty()
return batch
}(),
svcRouting,
func(t ptrace.Traces) (map[string][]int, error) {
return routeByResourceAttr(t, "service.name")
},
errors.New("empty spans"),
},
} {
t.Run(tt.desc, func(t *testing.T) {
res, err := routingIdentifiersFromTraces(tt.batch, tt.routingKey, "")
res, err := tt.rf(tt.batch)
assert.Equal(t, err, tt.err)
assert.Equal(t, res, map[string][]int(nil))
})
Expand Down

0 comments on commit 0ed2fe1

Please sign in to comment.