-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sumologicexporter: refactor sender (#32643)
**Description:** Refactor sender in order to prepare for adding OTLP formats Reduces size of #32315 Reopens #32592 due to revert due to test issues **Link to tracking Issue:** #31479 **Testing:** Minimal changes to unit tests to ensure that everything works like before **Documentation:** N/A --------- Signed-off-by: Dominik Rosiek <drosiek@sumologic.com> Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
- Loading branch information
1 parent
3c64cea
commit 05e3e4b
Showing
16 changed files
with
516 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,88 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package sumologicexporter | ||
package sumologicexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sumologicexporter" | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
) | ||
|
||
func TestFieldsAsString(t *testing.T) { | ||
expected := "key1=value1, key2=value2, key3=value3" | ||
flds := fieldsFromMap(map[string]string{ | ||
"key1": "value1", | ||
"key3": "value3", | ||
"key2": "value2", | ||
}) | ||
func TestFields(t *testing.T) { | ||
testcases := []struct { | ||
name string | ||
fields map[string]string | ||
expected string | ||
}{ | ||
{ | ||
name: "string", | ||
fields: map[string]string{ | ||
"key1": "value1", | ||
"key3": "value3", | ||
"key2": "value2", | ||
}, | ||
expected: "key1=value1, key2=value2, key3=value3", | ||
}, | ||
{ | ||
name: "sanitization", | ||
fields: map[string]string{ | ||
"key1": "value,1", | ||
"key3": "value\n3", | ||
"key=,2": "valu,e=2", | ||
}, | ||
expected: "key1=value_1, key3=value_3, key:_2=valu_e:2", | ||
}, | ||
{ | ||
name: "empty element", | ||
fields: map[string]string{ | ||
"key1": "value1", | ||
"key3": "value3", | ||
"key2": "", | ||
}, | ||
expected: "key1=value1, key3=value3", | ||
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
flds := fieldsFromMap(tc.fields) | ||
|
||
assert.Equal(t, expected, flds.string()) | ||
assert.Equal(t, tc.expected, flds.string()) | ||
}) | ||
} | ||
} | ||
|
||
func TestFieldsSanitization(t *testing.T) { | ||
expected := "key1=value_1, key3=value_3, key:_2=valu_e:2" | ||
flds := fieldsFromMap(map[string]string{ | ||
"key1": "value,1", | ||
"key3": "value\n3", | ||
"key=,2": "valu,e=2", | ||
}) | ||
func BenchmarkFields(b *testing.B) { | ||
attrMap := pcommon.NewMap() | ||
flds := map[string]any{ | ||
"key1": "value1", | ||
"key3": "value3", | ||
"key2": "", | ||
"map": map[string]string{ | ||
"key1": "value1", | ||
"key3": "value3", | ||
"key2": "", | ||
}, | ||
} | ||
for k, v := range flds { | ||
switch v := v.(type) { | ||
case string: | ||
attrMap.PutStr(k, v) | ||
case map[string]string: | ||
m := pcommon.NewValueMap() | ||
mm := m.Map().AsRaw() | ||
for kk, vv := range v { | ||
mm[kk] = vv | ||
} | ||
m.CopyTo(attrMap.PutEmpty(k)) | ||
} | ||
} | ||
sut := newFields(attrMap) | ||
|
||
assert.Equal(t, expected, flds.string()) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_ = sut.string() | ||
} | ||
} |
Oops, something went wrong.