Skip to content

Commit d11b94c

Browse files
lahsivjargraphaelli
authored andcommitted
[connector/signaltometrics]Drop collector service name and namespace from metrics (open-telemetry#43150)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description `signaltometrics.service.*` fields were added to the metrics produced from signaltometrics component to ensure single-writer is obeyed ([ref](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/connector/signaltometricsconnector#single-writer)). However, we don't require all the fields to ensure this. Based on the description of `service.instance.id` it is alone enough to ensure single-writer ([ref](https://opentelemetry.io/docs/specs/semconv/registry/attributes/service/)). The other fields leak information about the service which is not desirable and also unnecessary for our purpose. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#43148 <!--Describe what testing was performed and which tests were added.--> #### Testing Updated in PR <!--Describe the documentation added.--> #### Documentation Updated <!--Please delete paragraphs that you did not use before submitting.--> --------- Co-authored-by: Gil Raphaelli <graphaelli@gmail.com>
1 parent d07a530 commit d11b94c

File tree

22 files changed

+31
-239
lines changed

22 files changed

+31
-239
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: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: signaltometricsconnector
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Drop `signaltometrics.service.{name, namespace}` resource attribute from produced metrics.
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: [43148]
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:
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]

connector/signaltometricsconnector/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,9 @@ principle. However, since `signaltometrics` component produces metrics from all
297297
types and also allows customizing the resource attributes, there is a possibility
298298
of violating the single-writer principle. To keep the single-writer principle intact,
299299
the component adds collector instance information as resource attributes. The following
300-
resource attributes are added to each produced metrics:
300+
resource attribute is added to each produced metric:
301301

302302
```yaml
303-
signaltometrics.service.name: <service_name_of_the_otel_collector>
304-
signaltometrics.service.namespace: <service_namespace_of_the_otel_collector>
305303
signaltometrics.service.instance.id: <service_instance_id_of_the_otel_collector>
306304
```
307305

connector/signaltometricsconnector/internal/model/collectorinstanceinfo.go

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,16 @@ var prefix = metadata.Type.String()
2020
type CollectorInstanceInfo struct {
2121
size int
2222
serviceInstanceID string
23-
serviceName string
24-
serviceNamespace string
2523
}
2624

2725
func NewCollectorInstanceInfo(
2826
set component.TelemetrySettings,
2927
) CollectorInstanceInfo {
3028
var info CollectorInstanceInfo
3129
for k, v := range set.Resource.Attributes().All() {
32-
switch k {
33-
case string(semconv.ServiceInstanceIDKey):
30+
if k == string(semconv.ServiceInstanceIDKey) {
3431
if str := v.Str(); str != "" {
35-
info.serviceInstanceID = str
36-
info.size++
37-
}
38-
case string(semconv.ServiceNameKey):
39-
if str := v.Str(); str != "" {
40-
info.serviceName = str
41-
info.size++
42-
}
43-
case string(semconv.ServiceNamespaceKey):
44-
if str := v.Str(); str != "" {
45-
info.serviceNamespace = str
32+
info.serviceInstanceID = v.Str()
4633
info.size++
4734
}
4835
}
@@ -61,12 +48,6 @@ func (info CollectorInstanceInfo) Copy(to pcommon.Map) {
6148
if info.serviceInstanceID != "" {
6249
to.PutStr(keyWithPrefix(string(semconv.ServiceInstanceIDKey)), info.serviceInstanceID)
6350
}
64-
if info.serviceName != "" {
65-
to.PutStr(keyWithPrefix(string(semconv.ServiceNameKey)), info.serviceName)
66-
}
67-
if info.serviceNamespace != "" {
68-
to.PutStr(keyWithPrefix(string(semconv.ServiceNamespaceKey)), info.serviceNamespace)
69-
}
7051
}
7152

7253
func keyWithPrefix(key string) string {

connector/signaltometricsconnector/internal/model/collectorinstanceinfo_test.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,6 @@ func TestCollectorInstanceInfo(t *testing.T) {
4242
return m
4343
}(),
4444
},
45-
{
46-
name: "with_all_values",
47-
input: func() component.TelemetrySettings {
48-
ts := componenttest.NewNopTelemetrySettings()
49-
ts.Resource.Attributes().PutStr(string(semconv.ServiceInstanceIDKey), "627cc493-f310-47de-96bd-71410b7dec09")
50-
ts.Resource.Attributes().PutStr(string(semconv.ServiceNameKey), "signaltometrics")
51-
ts.Resource.Attributes().PutStr(string(semconv.ServiceNamespaceKey), "test")
52-
return ts
53-
}(),
54-
expected: func() pcommon.Map {
55-
m := pcommon.NewMap()
56-
m.PutStr(
57-
"signaltometrics."+string(semconv.ServiceInstanceIDKey),
58-
"627cc493-f310-47de-96bd-71410b7dec09",
59-
)
60-
m.PutStr(
61-
"signaltometrics."+string(semconv.ServiceNameKey),
62-
"signaltometrics",
63-
)
64-
m.PutStr(
65-
"signaltometrics."+string(semconv.ServiceNamespaceKey),
66-
"test",
67-
)
68-
return m
69-
}(),
70-
},
7145
} {
7246
t.Run(tc.name, func(t *testing.T) {
7347
ci := NewCollectorInstanceInfo(tc.input)

connector/signaltometricsconnector/internal/model/model_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import (
1818

1919
const (
2020
testServiceInstanceID = "627cc493-f310-47de-96bd-71410b7dec09"
21-
testServiceName = "testsignaltometrics"
22-
testNamespace = "test"
2321
)
2422

2523
func TestFilterResourceAttributes(t *testing.T) {
@@ -45,8 +43,6 @@ func TestFilterResourceAttributes(t *testing.T) {
4543
"key.4": "val.4",
4644
// Collector instance info will be added
4745
"signaltometrics.service.instance.id": testServiceInstanceID,
48-
"signaltometrics.service.name": testServiceName,
49-
"signaltometrics.service.namespace": testNamespace,
5046
},
5147
},
5248
{
@@ -80,8 +76,6 @@ func TestFilterResourceAttributes(t *testing.T) {
8076
"key.302": "anything",
8177
// Collector instance info will be added
8278
"signaltometrics.service.instance.id": testServiceInstanceID,
83-
"signaltometrics.service.name": testServiceName,
84-
"signaltometrics.service.namespace": testNamespace,
8579
},
8680
},
8781
} {
@@ -175,8 +169,6 @@ func testCollectorInstanceInfo(t *testing.T) CollectorInstanceInfo {
175169

176170
set := componenttest.NewNopTelemetrySettings()
177171
set.Resource.Attributes().PutStr(string(semconv.ServiceInstanceIDKey), testServiceInstanceID)
178-
set.Resource.Attributes().PutStr(string(semconv.ServiceNameKey), testServiceName)
179-
set.Resource.Attributes().PutStr(string(semconv.ServiceNamespaceKey), testNamespace)
180172
return NewCollectorInstanceInfo(set)
181173
}
182174

connector/signaltometricsconnector/testdata/logs/exponential_histograms/output.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ resourceMetrics:
1010
- key: signaltometrics.service.instance.id
1111
value:
1212
stringValue: 627cc493-f310-47de-96bd-71410b7dec09
13-
- key: signaltometrics.service.name
14-
value:
15-
stringValue: signaltometrics
16-
- key: signaltometrics.service.namespace
17-
value:
18-
stringValue: test
1913
scopeMetrics:
2014
- metrics:
2115
- description: Logrecords as exponential histogram with log.duration from attributes
@@ -339,12 +333,6 @@ resourceMetrics:
339333
- key: signaltometrics.service.instance.id
340334
value:
341335
stringValue: 627cc493-f310-47de-96bd-71410b7dec09
342-
- key: signaltometrics.service.name
343-
value:
344-
stringValue: signaltometrics
345-
- key: signaltometrics.service.namespace
346-
value:
347-
stringValue: test
348336
scopeMetrics:
349337
- metrics:
350338
- description: Logrecords with resource attribute foo as exponential histogram with log.duration from attributes

connector/signaltometricsconnector/testdata/logs/gauge/output.yaml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ resourceMetrics:
1010
- key: signaltometrics.service.instance.id
1111
value:
1212
stringValue: 627cc493-f310-47de-96bd-71410b7dec09
13-
- key: signaltometrics.service.name
14-
value:
15-
stringValue: signaltometrics
16-
- key: signaltometrics.service.namespace
17-
value:
18-
stringValue: test
1913
scopeMetrics:
2014
- metrics:
2115
- description: Extract memory_mb from log records
@@ -54,12 +48,6 @@ resourceMetrics:
5448
- key: signaltometrics.service.instance.id
5549
value:
5650
stringValue: 627cc493-f310-47de-96bd-71410b7dec09
57-
- key: signaltometrics.service.name
58-
value:
59-
stringValue: signaltometrics
60-
- key: signaltometrics.service.namespace
61-
value:
62-
stringValue: test
6351
scopeMetrics:
6452
- metrics:
6553
- description: Extract memory_mb from log records with attribute foo
@@ -77,4 +65,4 @@ resourceMetrics:
7765
value:
7866
stringValue: notfoo
7967
scope:
80-
name: github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector
68+
name: github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector

connector/signaltometricsconnector/testdata/logs/histograms/output.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ resourceMetrics:
1010
- key: signaltometrics.service.instance.id
1111
value:
1212
stringValue: 627cc493-f310-47de-96bd-71410b7dec09
13-
- key: signaltometrics.service.name
14-
value:
15-
stringValue: signaltometrics
16-
- key: signaltometrics.service.namespace
17-
value:
18-
stringValue: test
1913
scopeMetrics:
2014
- metrics:
2115
- description: Logrecords as histogram with log.duration from attributes
@@ -139,12 +133,6 @@ resourceMetrics:
139133
- key: signaltometrics.service.instance.id
140134
value:
141135
stringValue: 627cc493-f310-47de-96bd-71410b7dec09
142-
- key: signaltometrics.service.name
143-
value:
144-
stringValue: signaltometrics
145-
- key: signaltometrics.service.namespace
146-
value:
147-
stringValue: test
148136
scopeMetrics:
149137
- metrics:
150138
- description: Logrecords with resource attribute foo as histogram with log.duration from attributes

connector/signaltometricsconnector/testdata/logs/metric_identity/output.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ resourceMetrics:
1010
- key: signaltometrics.service.instance.id
1111
value:
1212
stringValue: 627cc493-f310-47de-96bd-71410b7dec09
13-
- key: signaltometrics.service.name
14-
value:
15-
stringValue: signaltometrics
16-
- key: signaltometrics.service.namespace
17-
value:
18-
stringValue: test
1913
scopeMetrics:
2014
- metrics:
2115
- description: Logrecords as histogram with log.duration from attributes

connector/signaltometricsconnector/testdata/logs/sum/output.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ resourceMetrics:
1010
- key: signaltometrics.service.instance.id
1111
value:
1212
stringValue: 627cc493-f310-47de-96bd-71410b7dec09
13-
- key: signaltometrics.service.name
14-
value:
15-
stringValue: signaltometrics
16-
- key: signaltometrics.service.namespace
17-
value:
18-
stringValue: test
1913
scopeMetrics:
2014
- metrics:
2115
- description: Count total number of log records
@@ -69,12 +63,6 @@ resourceMetrics:
6963
- key: signaltometrics.service.instance.id
7064
value:
7165
stringValue: 627cc493-f310-47de-96bd-71410b7dec09
72-
- key: signaltometrics.service.name
73-
value:
74-
stringValue: signaltometrics
75-
- key: signaltometrics.service.namespace
76-
value:
77-
stringValue: test
7866
scopeMetrics:
7967
- metrics:
8068
- description: Count total number of log records with resource attribute foo

0 commit comments

Comments
 (0)