Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hotrod/observer_test] Switch to OpenTelemetry #4635

Merged
merged 9 commits into from
Aug 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,15 @@ func TestTags(t *testing.T) {
key string
variant string
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
value interface{}
attr attribute.KeyValue
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
metrics []u.ExpectedMetric
}

testCases := []tagTestCase{
{key: "something", value: 42, metrics: []u.ExpectedMetric{
{key: "something", value: 42, attr: attribute.Key("something").String(fmt.Sprint(42)), metrics: []u.ExpectedMetric{
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
{Name: "requests", Value: 1, Tags: tags("error", "false")},
}},
{key: "error", value: true, metrics: []u.ExpectedMetric{
{key: "error", value: true, attr: attribute.Key("error").String(fmt.Sprint(true)), metrics: []u.ExpectedMetric{
{Name: "requests", Value: 1, Tags: tags("error", "true")},
}},
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
}
Expand All @@ -128,6 +129,7 @@ func TestTags(t *testing.T) {
testCases = append(testCases, tagTestCase{
key: "http.status_code",
value: v.value,
attr: attribute.Key("http.status_code").String(fmt.Sprint(v.value)),
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
variant: v.variant,
metrics: []u.ExpectedMetric{
{Name: "http_requests", Value: 1, Tags: tags("status_code", fmt.Sprintf("%dxx", i/100))},
Expand All @@ -143,18 +145,7 @@ func TestTags(t *testing.T) {
t.Run(fmt.Sprintf("%s-%v-%s", testCase.key, testCase.value, testCase.variant), func(t *testing.T) {
withTestTracer(func(testTracer *testTracer) {
_, span := testTracer.tracer.Start(context.Background(), "span", trace.WithSpanKind(trace.SpanKindServer))
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
switch v := testCase.value.(type) {
case int:
span.SetAttributes(attribute.Key(testCase.key).String(fmt.Sprint(v)))
case bool:
span.SetAttributes(attribute.Key(testCase.key).String(fmt.Sprint(v)))
case int64:
span.SetAttributes(attribute.Key(testCase.key).String(fmt.Sprint(v)))
case uint16:
span.SetAttributes(attribute.Key(testCase.key).String(fmt.Sprint(v)))
default:
span.SetAttributes(attribute.Key(testCase.key).String(v.(string)))
}
span.SetAttributes(testCase.attr)
span.End()
testTracer.metrics.AssertCounterMetrics(t, testCase.metrics...)
})
Expand Down