Skip to content

Commit ffe824b

Browse files
jpkrohlingjmsnll
authored andcommitted
[exporter/loki] Don't auto-promote tenant attribute (open-telemetry#27446)
Fixes open-telemetry#21045 Signed-off-by: Juraci Paixão Kröhling <[email protected]> --------- Signed-off-by: Juraci Paixão Kröhling <[email protected]>
1 parent 58ff519 commit ffe824b

File tree

4 files changed

+47
-32
lines changed

4 files changed

+47
-32
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: lokiexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: The tenant attribute is now not automatically promoted to a label.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [21045]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: To add tenant attributes (resource/record) to labels, use the label hints explicitly.
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

exporter/lokiexporter/exporter_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ func TestLogsToLokiRequestWithGroupingByTenant(t *testing.T) {
160160
label string
161161
}{
162162
"1": {
163-
label: `{exporter="OTLP", tenant_id="1"}`,
164-
line: `{"attributes":{"http.status":200}}`,
163+
label: `{exporter="OTLP"}`,
164+
line: `{"attributes":{"http.status":200,"tenant.id":"1"}}`,
165165
},
166166
"2": {
167-
label: `{exporter="OTLP", tenant_id="2"}`,
168-
line: `{"attributes":{"http.status":200}}`,
167+
label: `{exporter="OTLP"}`,
168+
line: `{"attributes":{"http.status":200,"tenant.id":"2"}}`,
169169
},
170170
},
171171
},
@@ -224,12 +224,12 @@ func TestLogsToLokiRequestWithGroupingByTenant(t *testing.T) {
224224
label string
225225
}{
226226
"1": {
227-
label: `{exporter="OTLP", tenant_id="1"}`,
228-
line: `{"attributes":{"http.status":200}}`,
227+
label: `{exporter="OTLP"}`,
228+
line: `{"attributes":{"http.status":200,"tenant.id":"11"},"resources":{"tenant.id":"1"}}`,
229229
},
230230
"2": {
231-
label: `{exporter="OTLP", tenant_id="2"}`,
232-
line: `{"attributes":{"http.status":200}}`,
231+
label: `{exporter="OTLP"}`,
232+
line: `{"attributes":{"http.status":200,"tenant.id":"22"},"resources":{"tenant.id":"2"}}`,
233233
},
234234
},
235235
},

pkg/translator/loki/convert.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,6 @@ func convertAttributesAndMerge(logAttrs pcommon.Map, resAttrs pcommon.Map, defau
5555
out = out.Merge(labels)
5656
}
5757

58-
// get tenant hint from resource attributes, fallback to record attributes
59-
// if it is not found
60-
if resourcesToLabel, found := resAttrs.Get(hintTenant); !found {
61-
if attributesToLabel, found := logAttrs.Get(hintTenant); found {
62-
labels := convertAttributesToLabels(logAttrs, attributesToLabel)
63-
out = out.Merge(labels)
64-
}
65-
} else {
66-
labels := convertAttributesToLabels(resAttrs, resourcesToLabel)
67-
out = out.Merge(labels)
68-
}
69-
7058
return out
7159
}
7260

pkg/translator/loki/logs_to_loki_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ func TestLogsToLokiRequestWithGroupingByTenant(t *testing.T) {
4848
PushRequest: &push.PushRequest{
4949
Streams: []push.Stream{
5050
{
51-
Labels: `{exporter="OTLP", tenant_id="1"}`,
51+
Labels: `{exporter="OTLP"}`,
5252
Entries: []push.Entry{
5353
{
54-
Line: `{"attributes":{"http.status":200}}`,
54+
Line: `{"attributes":{"http.status":200,"tenant.id":"1"}}`,
5555
},
5656
}},
5757
},
@@ -61,10 +61,10 @@ func TestLogsToLokiRequestWithGroupingByTenant(t *testing.T) {
6161
PushRequest: &push.PushRequest{
6262
Streams: []push.Stream{
6363
{
64-
Labels: `{exporter="OTLP", tenant_id="2"}`,
64+
Labels: `{exporter="OTLP"}`,
6565
Entries: []push.Entry{
6666
{
67-
Line: `{"attributes":{"http.status":200}}`,
67+
Line: `{"attributes":{"http.status":200,"tenant.id":"2"}}`,
6868
},
6969
},
7070
},
@@ -100,10 +100,10 @@ func TestLogsToLokiRequestWithGroupingByTenant(t *testing.T) {
100100
PushRequest: &push.PushRequest{
101101
Streams: []push.Stream{
102102
{
103-
Labels: `{exporter="OTLP", tenant_id="11"}`,
103+
Labels: `{exporter="OTLP"}`,
104104
Entries: []push.Entry{
105105
{
106-
Line: `{"attributes":{"http.status":200}}`,
106+
Line: `{"attributes":{"http.status":200},"resources":{"tenant.id":"11"}}`,
107107
},
108108
}},
109109
},
@@ -113,10 +113,10 @@ func TestLogsToLokiRequestWithGroupingByTenant(t *testing.T) {
113113
PushRequest: &push.PushRequest{
114114
Streams: []push.Stream{
115115
{
116-
Labels: `{exporter="OTLP", tenant_id="12"}`,
116+
Labels: `{exporter="OTLP"}`,
117117
Entries: []push.Entry{
118118
{
119-
Line: `{"attributes":{"http.status":200}}`,
119+
Line: `{"attributes":{"http.status":200},"resources":{"tenant.id":"12"}}`,
120120
},
121121
},
122122
},
@@ -186,10 +186,10 @@ func TestLogsToLokiRequestWithGroupingByTenant(t *testing.T) {
186186
PushRequest: &push.PushRequest{
187187
Streams: []push.Stream{
188188
{
189-
Labels: `{exporter="OTLP", tenant_id="21"}`,
189+
Labels: `{exporter="OTLP"}`,
190190
Entries: []push.Entry{
191191
{
192-
Line: `{"attributes":{"http.status":200}}`,
192+
Line: `{"attributes":{"http.status":200,"tenant.id":"31"},"resources":{"tenant.id":"21"}}`,
193193
},
194194
}},
195195
},
@@ -199,10 +199,10 @@ func TestLogsToLokiRequestWithGroupingByTenant(t *testing.T) {
199199
PushRequest: &push.PushRequest{
200200
Streams: []push.Stream{
201201
{
202-
Labels: `{exporter="OTLP", tenant_id="22"}`,
202+
Labels: `{exporter="OTLP"}`,
203203
Entries: []push.Entry{
204204
{
205-
Line: `{"attributes":{"http.status":200}}`,
205+
Line: `{"attributes":{"http.status":200,"tenant.id":"32"},"resources":{"tenant.id":"22"}}`,
206206
},
207207
},
208208
},

0 commit comments

Comments
 (0)