Skip to content

Commit 1ff71a9

Browse files
mahadzaryab1amol-verma-allen
authored andcommitted
[refactor] Refactor jptrace/attributes_tests.go for readability (jaegertracing#6786)
## Description of the changes - Addresses the leftover comments from jaegertracing#6785 ## How was this change tested? - CI ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com> Signed-off-by: amol-verma-allen <amol.verma@allen.in>
1 parent 226173c commit 1ff71a9

File tree

6 files changed

+24
-42
lines changed

6 files changed

+24
-42
lines changed

cmd/jaeger/internal/integration/trace_reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (r *traceReader) FindTraces(
121121
Query: &api_v3.TraceQueryParameters{
122122
ServiceName: query.ServiceName,
123123
OperationName: query.OperationName,
124-
Attributes: jptrace.AttributesToMap(query.Attributes),
124+
Attributes: jptrace.PcommonMapToPlainMap(query.Attributes),
125125
StartTimeMin: query.StartTimeMin,
126126
StartTimeMax: query.StartTimeMax,
127127
DurationMin: query.DurationMin,

cmd/query/app/apiv3/grpc_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (h *Handler) internalFindTraces(
7474
TraceQueryParams: tracestore.TraceQueryParams{
7575
ServiceName: query.GetServiceName(),
7676
OperationName: query.GetOperationName(),
77-
Attributes: jptrace.MapToAttributes(query.GetAttributes()),
77+
Attributes: jptrace.PlainMapToPcommonMap(query.GetAttributes()),
7878
SearchDepth: int(query.GetSearchDepth()),
7979
},
8080
RawTraces: query.GetRawTraces(),

internal/jptrace/attributes.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ const (
1818
FormatAttribute = "@jaeger@format"
1919
)
2020

21-
func AttributesToMap(attributes pcommon.Map) map[string]string {
22-
tags := make(map[string]string)
21+
func PcommonMapToPlainMap(attributes pcommon.Map) map[string]string {
22+
mapAttributes := make(map[string]string)
2323
attributes.Range(func(k string, v pcommon.Value) bool {
24-
tags[k] = v.AsString()
24+
mapAttributes[k] = v.AsString()
2525
return true
2626
})
27-
return tags
27+
return mapAttributes
2828
}
2929

30-
func MapToAttributes(tags map[string]string) pcommon.Map {
30+
func PlainMapToPcommonMap(attributesMap map[string]string) pcommon.Map {
3131
attributes := pcommon.NewMap()
32-
for k, v := range tags {
32+
for k, v := range attributesMap {
3333
attributes.PutStr(k, v)
3434
}
3535
return attributes

internal/jptrace/attributes_test.go

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"go.opentelemetry.io/collector/pdata/pcommon"
1111
)
1212

13-
func TestAttributesToMap(t *testing.T) {
13+
func TestPcommonMapToPlainMap(t *testing.T) {
1414
tests := []struct {
1515
name string
1616
attributes pcommon.Map
@@ -54,53 +54,35 @@ func TestAttributesToMap(t *testing.T) {
5454

5555
for _, test := range tests {
5656
t.Run(test.name, func(t *testing.T) {
57-
result := AttributesToMap(test.attributes)
57+
result := PcommonMapToPlainMap(test.attributes)
5858
require.Equal(t, test.expected, result)
5959
})
6060
}
6161
}
6262

63-
func TestMapToAttributes(t *testing.T) {
63+
func TestPlainMapToPcommonMap(t *testing.T) {
6464
tests := []struct {
65-
name string
66-
tags map[string]string
67-
requireFn func(t *testing.T, result pcommon.Map)
65+
name string
66+
expected map[string]string
6867
}{
6968
{
70-
name: "empty map",
71-
tags: map[string]string{},
72-
requireFn: func(t *testing.T, result pcommon.Map) {
73-
require.Equal(t, 0, result.Len(), "Expected map to be empty")
74-
},
69+
name: "empty map",
70+
expected: map[string]string{},
7571
},
7672
{
77-
name: "single tag",
78-
tags: map[string]string{"key1": "value1"},
79-
requireFn: func(t *testing.T, result pcommon.Map) {
80-
val, exists := result.Get("key1")
81-
require.True(t, exists)
82-
require.Equal(t, "value1", val.Str())
83-
},
73+
name: "single attribute",
74+
expected: map[string]string{"key1": "value1"},
8475
},
8576
{
86-
name: "multiple tags",
87-
tags: map[string]string{"key1": "value1", "key2": "value2"},
88-
requireFn: func(t *testing.T, result pcommon.Map) {
89-
val, exists := result.Get("key1")
90-
require.True(t, exists)
91-
require.Equal(t, "value1", val.Str())
92-
93-
val, exists = result.Get("key2")
94-
require.True(t, exists)
95-
require.Equal(t, "value2", val.Str())
96-
},
77+
name: "multiple attributes",
78+
expected: map[string]string{"key1": "value1", "key2": "value2"},
9779
},
9880
}
9981

10082
for _, test := range tests {
10183
t.Run(test.name, func(t *testing.T) {
102-
result := MapToAttributes(test.tags)
103-
test.requireFn(t, result)
84+
result := PlainMapToPcommonMap(test.expected)
85+
require.Equal(t, test.expected, PcommonMapToPlainMap(result))
10486
})
10587
}
10688
}

internal/storage/v2/api/tracestore/reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (t *TraceQueryParams) ToSpanStoreQueryParameters() *spanstore.TraceQueryPar
108108
return &spanstore.TraceQueryParameters{
109109
ServiceName: t.ServiceName,
110110
OperationName: t.OperationName,
111-
Tags: jptrace.AttributesToMap(t.Attributes),
111+
Tags: jptrace.PcommonMapToPlainMap(t.Attributes),
112112
StartTimeMin: t.StartTimeMin,
113113
StartTimeMax: t.StartTimeMax,
114114
DurationMin: t.DurationMin,

internal/storage/v2/v1adapter/spanreader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (sr *SpanReader) FindTraces(
7979
getTracesIter := sr.traceReader.FindTraces(ctx, tracestore.TraceQueryParams{
8080
ServiceName: query.ServiceName,
8181
OperationName: query.OperationName,
82-
Attributes: jptrace.MapToAttributes(query.Tags),
82+
Attributes: jptrace.PlainMapToPcommonMap(query.Tags),
8383
StartTimeMin: query.StartTimeMin,
8484
StartTimeMax: query.StartTimeMax,
8585
DurationMin: query.DurationMin,
@@ -96,7 +96,7 @@ func (sr *SpanReader) FindTraceIDs(
9696
traceIDsIter := sr.traceReader.FindTraceIDs(ctx, tracestore.TraceQueryParams{
9797
ServiceName: query.ServiceName,
9898
OperationName: query.OperationName,
99-
Attributes: jptrace.MapToAttributes(query.Tags),
99+
Attributes: jptrace.PlainMapToPcommonMap(query.Tags),
100100
StartTimeMin: query.StartTimeMin,
101101
StartTimeMax: query.StartTimeMax,
102102
DurationMin: query.DurationMin,

0 commit comments

Comments
 (0)