Skip to content

Commit df6e775

Browse files
authored
[exporter/alibabacloudlogserviceexporter] Unexport KeyValues,KeyValue structs (open-telemetry#40702)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description these structs are not part of config and cannot be exported: KeyValues,KeyValue <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#40644 <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> Signed-off-by: Jared Tan <[email protected]>
1 parent 34da944 commit df6e775

File tree

3 files changed

+51
-24
lines changed

3 files changed

+51
-24
lines changed

.chloggen/unexport_keyvalues.yaml

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: alibabacloudlogserviceexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Unexport KeyValues,KeyValue structs
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: [40644]
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: [api]

exporter/alibabacloudlogserviceexporter/metricsdata_to_logservice.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@ const (
2626
summaryLabelKey = "quantile"
2727
)
2828

29-
type KeyValue struct {
29+
type keyValue struct {
3030
Key string
3131
Value string
3232
}
3333

34-
type KeyValues struct {
35-
keyValues []KeyValue
34+
type keyValues struct {
35+
keyValues []keyValue
3636
}
3737

38-
func (kv *KeyValues) Len() int { return len(kv.keyValues) }
39-
func (kv *KeyValues) Swap(i, j int) {
38+
func (kv *keyValues) Len() int { return len(kv.keyValues) }
39+
func (kv *keyValues) Swap(i, j int) {
4040
kv.keyValues[i], kv.keyValues[j] = kv.keyValues[j], kv.keyValues[i]
4141
}
42-
func (kv *KeyValues) Less(i, j int) bool { return kv.keyValues[i].Key < kv.keyValues[j].Key }
42+
func (kv *keyValues) Less(i, j int) bool { return kv.keyValues[i].Key < kv.keyValues[j].Key }
4343

44-
func (kv *KeyValues) Sort() {
44+
func (kv *keyValues) Sort() {
4545
sort.Sort(kv)
4646
}
4747

48-
func (kv *KeyValues) Replace(key, value string) {
48+
func (kv *keyValues) Replace(key, value string) {
4949
key = sanitize(key)
5050
findIndex := sort.Search(len(kv.keyValues), func(index int) bool {
5151
return kv.keyValues[index].Key >= key
@@ -55,28 +55,28 @@ func (kv *KeyValues) Replace(key, value string) {
5555
}
5656
}
5757

58-
func (kv *KeyValues) Append(key, value string) {
58+
func (kv *keyValues) Append(key, value string) {
5959
key = sanitize(key)
60-
kv.keyValues = append(kv.keyValues, KeyValue{
60+
kv.keyValues = append(kv.keyValues, keyValue{
6161
key,
6262
value,
6363
})
6464
}
6565

66-
func (kv *KeyValues) Clone() KeyValues {
67-
var newKeyValues KeyValues
68-
newKeyValues.keyValues = make([]KeyValue, len(kv.keyValues))
66+
func (kv *keyValues) Clone() keyValues {
67+
var newKeyValues keyValues
68+
newKeyValues.keyValues = make([]keyValue, len(kv.keyValues))
6969
copy(newKeyValues.keyValues, kv.keyValues)
7070
return newKeyValues
7171
}
7272

73-
func (kv *KeyValues) String() string {
73+
func (kv *keyValues) String() string {
7474
var builder strings.Builder
7575
kv.labelToStringBuilder(&builder)
7676
return builder.String()
7777
}
7878

79-
func (kv *KeyValues) labelToStringBuilder(sb *strings.Builder) {
79+
func (kv *keyValues) labelToStringBuilder(sb *strings.Builder) {
8080
for index, label := range kv.keyValues {
8181
sb.WriteString(label.Key)
8282
sb.WriteString("#$#")
@@ -111,7 +111,7 @@ func formatMetricName(name string) string {
111111

112112
func newMetricLogFromRaw(
113113
name string,
114-
labels KeyValues,
114+
labels keyValues,
115115
nsec int64,
116116
value float64,
117117
) *sls.Log {
@@ -139,14 +139,14 @@ func newMetricLogFromRaw(
139139
}
140140
}
141141

142-
func resourceToMetricLabels(labels *KeyValues, resource pcommon.Resource) {
142+
func resourceToMetricLabels(labels *keyValues, resource pcommon.Resource) {
143143
attrs := resource.Attributes()
144144
for k, v := range attrs.All() {
145145
labels.Append(k, v.AsString())
146146
}
147147
}
148148

149-
func numberMetricsToLogs(name string, data pmetric.NumberDataPointSlice, defaultLabels KeyValues) (logs []*sls.Log) {
149+
func numberMetricsToLogs(name string, data pmetric.NumberDataPointSlice, defaultLabels keyValues) (logs []*sls.Log) {
150150
for i := 0; i < data.Len(); i++ {
151151
dataPoint := data.At(i)
152152
attributeMap := dataPoint.Attributes()
@@ -176,7 +176,7 @@ func numberMetricsToLogs(name string, data pmetric.NumberDataPointSlice, default
176176
return logs
177177
}
178178

179-
func doubleHistogramMetricsToLogs(name string, data pmetric.HistogramDataPointSlice, defaultLabels KeyValues) (logs []*sls.Log) {
179+
func doubleHistogramMetricsToLogs(name string, data pmetric.HistogramDataPointSlice, defaultLabels keyValues) (logs []*sls.Log) {
180180
for i := 0; i < data.Len(); i++ {
181181
dataPoint := data.At(i)
182182
attributeMap := dataPoint.Attributes()
@@ -222,7 +222,7 @@ func doubleHistogramMetricsToLogs(name string, data pmetric.HistogramDataPointSl
222222
return logs
223223
}
224224

225-
func doubleSummaryMetricsToLogs(name string, data pmetric.SummaryDataPointSlice, defaultLabels KeyValues) (logs []*sls.Log) {
225+
func doubleSummaryMetricsToLogs(name string, data pmetric.SummaryDataPointSlice, defaultLabels keyValues) (logs []*sls.Log) {
226226
for i := 0; i < data.Len(); i++ {
227227
dataPoint := data.At(i)
228228
attributeMap := dataPoint.Attributes()
@@ -257,7 +257,7 @@ func doubleSummaryMetricsToLogs(name string, data pmetric.SummaryDataPointSlice,
257257
return logs
258258
}
259259

260-
func metricDataToLogServiceData(md pmetric.Metric, defaultLabels KeyValues) (logs []*sls.Log) {
260+
func metricDataToLogServiceData(md pmetric.Metric, defaultLabels keyValues) (logs []*sls.Log) {
261261
//exhaustive:enforce
262262
switch md.Type() {
263263
case pmetric.MetricTypeEmpty, pmetric.MetricTypeExponentialHistogram:
@@ -281,7 +281,7 @@ func metricsDataToLogServiceData(
281281
resMetrics := md.ResourceMetrics()
282282
for i := 0; i < resMetrics.Len(); i++ {
283283
resMetricSlice := resMetrics.At(i)
284-
var defaultLabels KeyValues
284+
var defaultLabels keyValues
285285
resourceToMetricLabels(&defaultLabels, resMetricSlice.Resource())
286286
insMetricSlice := resMetricSlice.ScopeMetrics()
287287
for j := 0; j < insMetricSlice.Len(); j++ {

exporter/alibabacloudlogserviceexporter/metricsdata_to_logservice_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ func TestMetricCornerCases(t *testing.T) {
132132
assert.Equal(t, 1, min(1, 2))
133133
assert.Equal(t, 1, min(2, 1))
134134
assert.Equal(t, 1, min(1, 1))
135-
var label KeyValues
135+
var label keyValues
136136
label.Append("a", "b")
137137
assert.Equal(t, "a#$#b", label.String())
138138
}
139139

140140
func TestMetricLabelSanitize(t *testing.T) {
141-
var label KeyValues
141+
var label keyValues
142142
label.Append("_test", "key_test")
143143
label.Append("0test", "key_0test")
144144
label.Append("test_normal", "test_normal")

0 commit comments

Comments
 (0)