Skip to content

Commit

Permalink
sumologicexporter: do not replace . with _ for prometheus format (#…
Browse files Browse the repository at this point in the history
…32595)

**Description:**

Use new formatter for prometheus, which fixes metric name sanitization.
This also refactors the formatter itself, which is part of #31479 and
reduces size of #32315

**Link to tracking Issue:**

Applies SumoLogic/sumologic-otel-collector#211
and more, but this one is a bug fix

**Testing:**

Unit tests

**Documentation:**

N/A

---------

Signed-off-by: Dominik Rosiek <[email protected]>
  • Loading branch information
sumo-drosiek authored Apr 23, 2024
1 parent 1401157 commit 151dffb
Show file tree
Hide file tree
Showing 6 changed files with 307 additions and 157 deletions.
27 changes: 27 additions & 0 deletions .chloggen/drosiek-sumologicexporter-prom-formatter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: sumologicexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "do not replace `.` with `_` for prometheus format"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [31479]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
8 changes: 4 additions & 4 deletions exporter/sumologicexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func TestAllMetricsSuccess(t *testing.T) {
test := prepareSenderTest(t, []func(w http.ResponseWriter, req *http.Request){
func(_ http.ResponseWriter, req *http.Request) {
body := extractBody(t, req)
expected := `test_metric_data{test="test_value",test2="second_value"} 14500 1605534165000
expected := `test.metric.data{test="test_value",test2="second_value"} 14500 1605534165000
gauge_metric_name{foo="bar",remote_name="156920",url="http://example_url"} 124 1608124661166
gauge_metric_name{foo="bar",remote_name="156955",url="http://another_url"} 245 1608124662166`
assert.Equal(t, expected, body)
Expand All @@ -256,7 +256,7 @@ func TestAllMetricsFailed(t *testing.T) {
w.WriteHeader(500)

body := extractBody(t, req)
expected := `test_metric_data{test="test_value",test2="second_value"} 14500 1605534165000
expected := `test.metric.data{test="test_value",test2="second_value"} 14500 1605534165000
gauge_metric_name{foo="bar",remote_name="156920",url="http://example_url"} 124 1608124661166
gauge_metric_name{foo="bar",remote_name="156955",url="http://another_url"} 245 1608124662166`
assert.Equal(t, expected, body)
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestMetricsPartiallyFailed(t *testing.T) {
w.WriteHeader(500)

body := extractBody(t, req)
expected := `test_metric_data{test="test_value",test2="second_value"} 14500 1605534165000`
expected := `test.metric.data{test="test_value",test2="second_value"} 14500 1605534165000`
assert.Equal(t, expected, body)
assert.Equal(t, "application/vnd.sumologic.prometheus", req.Header.Get("Content-Type"))
},
Expand Down Expand Up @@ -343,7 +343,7 @@ func TestMetricsDifferentMetadata(t *testing.T) {
w.WriteHeader(500)

body := extractBody(t, req)
expected := `test_metric_data{test="test_value",test2="second_value",key1="value1"} 14500 1605534165000`
expected := `test.metric.data{test="test_value",test2="second_value",key1="value1"} 14500 1605534165000`
assert.Equal(t, expected, body)
assert.Equal(t, "application/vnd.sumologic.prometheus", req.Header.Get("Content-Type"))
},
Expand Down
Loading

0 comments on commit 151dffb

Please sign in to comment.