Skip to content

Commit 4af33f2

Browse files
author
Dominik Rosiek
committed
feat(sumologicexporter): allows . and / for prometheus key
Signed-off-by: Dominik Rosiek <[email protected]>
1 parent 2a5baaa commit 4af33f2

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

pkg/exporter/sumologicexporter/exporter_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ func TestAllMetricsSuccess(t *testing.T) {
509509
test := prepareExporterTest(t, createTestConfig(), []func(w http.ResponseWriter, req *http.Request){
510510
func(w http.ResponseWriter, req *http.Request) {
511511
body := extractBody(t, req)
512-
expected := `test_metric_data{test="test_value",test2="second_value"} 14500 1605534165000
512+
expected := `test.metric.data{test="test_value",test2="second_value"} 14500 1605534165000
513513
gauge_metric_name{foo="bar",remote_name="156920",url="http://example_url"} 124 1608124661166
514514
gauge_metric_name{foo="bar",remote_name="156955",url="http://another_url"} 245 1608124662166`
515515
assert.Equal(t, expected, body)
@@ -559,7 +559,7 @@ func TestAllMetricsFailed(t *testing.T) {
559559
w.WriteHeader(500)
560560

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

589589
body := extractBody(t, req)
590-
expected := `test_metric_data{test="test_value",test2="second_value"} 14500 1605534165000`
590+
expected := `test.metric.data{test="test_value",test2="second_value"} 14500 1605534165000`
591591
assert.Equal(t, expected, body)
592592
assert.Equal(t, "application/vnd.sumologic.prometheus", req.Header.Get("Content-Type"))
593593
},
@@ -643,7 +643,7 @@ func TestMetricsDifferentMetadata(t *testing.T) {
643643
w.WriteHeader(500)
644644

645645
body := extractBody(t, req)
646-
expected := `test_metric_data{test="test_value",test2="second_value",key1="value1"} 14500 1605534165000`
646+
expected := `test.metric.data{test="test_value",test2="second_value",key1="value1"} 14500 1605534165000`
647647
assert.Equal(t, expected, body)
648648
assert.Equal(t, "application/vnd.sumologic.prometheus", req.Header.Get("Content-Type"))
649649
},
@@ -826,7 +826,7 @@ func TestMetricsPrometheusFormatMetadataFilter(t *testing.T) {
826826
test := prepareExporterTest(t, createTestConfig(), []func(w http.ResponseWriter, req *http.Request){
827827
func(w http.ResponseWriter, req *http.Request) {
828828
body := extractBody(t, req)
829-
expected := `test_metric_data{test="test_value",test2="second_value",key1="value1",key2="value2"} 14500 1605534165000`
829+
expected := `test.metric.data{test="test_value",test2="second_value",key1="value1",key2="value2"} 14500 1605534165000`
830830
assert.Equal(t, expected, body)
831831
assert.Equal(t, "application/vnd.sumologic.prometheus", req.Header.Get("Content-Type"))
832832
},
@@ -881,7 +881,7 @@ func TestPushMetrics_AttributeTranslation(t *testing.T) {
881881
"X-Sumo-Category": "harry-potter",
882882
"X-Sumo-Host": "undefined",
883883
},
884-
expectedBody: `test_metric_data{test="test_value",test2="second_value",host="harry-potter",InstanceType="wizard"} 14500 1605534165000`,
884+
expectedBody: `test.metric.data{test="test_value",test2="second_value",host="harry-potter",InstanceType="wizard"} 14500 1605534165000`,
885885
},
886886
{
887887
name: "enabled_with_ot_host_name_template_set_in_source_host",
@@ -899,7 +899,7 @@ func TestPushMetrics_AttributeTranslation(t *testing.T) {
899899
"X-Sumo-Category": "harry-potter",
900900
"X-Sumo-Host": "harry-potter",
901901
},
902-
expectedBody: `test_metric_data{test="test_value",test2="second_value",host="harry-potter",InstanceType="wizard"} 14500 1605534165000`,
902+
expectedBody: `test.metric.data{test="test_value",test2="second_value",host="harry-potter",InstanceType="wizard"} 14500 1605534165000`,
903903
},
904904
{
905905
name: "enabled_with_proper_host_template_set_in_source_host_but_not_specified_in_metadata_attributes",
@@ -918,7 +918,7 @@ func TestPushMetrics_AttributeTranslation(t *testing.T) {
918918
"X-Sumo-Category": "undefined",
919919
"X-Sumo-Host": "undefined",
920920
},
921-
expectedBody: `test_metric_data{test="test_value",test2="second_value",host="harry-potter",InstanceType="wizard"} 14500 1605534165000`,
921+
expectedBody: `test.metric.data{test="test_value",test2="second_value",host="harry-potter",InstanceType="wizard"} 14500 1605534165000`,
922922
},
923923
{
924924
name: "disabled",
@@ -935,7 +935,7 @@ func TestPushMetrics_AttributeTranslation(t *testing.T) {
935935
"X-Sumo-Category": "harry-potter",
936936
"X-Sumo-Host": "undefined",
937937
},
938-
expectedBody: `test_metric_data{test="test_value",test2="second_value",host_name="harry-potter",host_type="wizard"} 14500 1605534165000`,
938+
expectedBody: `test.metric.data{test="test_value",test2="second_value",host.name="harry-potter",host.type="wizard"} 14500 1605534165000`,
939939
},
940940
{
941941
name: "disabled_with_ot_host_name_template_set_in_source_host",
@@ -952,7 +952,7 @@ func TestPushMetrics_AttributeTranslation(t *testing.T) {
952952
"X-Sumo-Category": "harry-potter",
953953
"X-Sumo-Host": "harry-potter",
954954
},
955-
expectedBody: `test_metric_data{test="test_value",test2="second_value",host_name="harry-potter",host_type="wizard"} 14500 1605534165000`,
955+
expectedBody: `test.metric.data{test="test_value",test2="second_value",host.name="harry-potter",host.type="wizard"} 14500 1605534165000`,
956956
},
957957
}
958958

pkg/exporter/sumologicexporter/prometheus_formatter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const (
4242
)
4343

4444
func newPrometheusFormatter() (prometheusFormatter, error) {
45-
sanitNameRegex, err := regexp.Compile(`[^0-9a-zA-Z]`)
45+
sanitNameRegex, err := regexp.Compile(`[^0-9a-zA-Z\./_:]`)
4646
if err != nil {
4747
return prometheusFormatter{}, err
4848
}
@@ -84,7 +84,7 @@ func (f *prometheusFormatter) tags2String(attr pdata.AttributeMap, labels pdata.
8484
}
8585

8686
// sanitizeKey returns sanitized key string by replacing
87-
// all non-alphanumeric chars with `_`
87+
// all non-allowed chars with `_`
8888
func (f *prometheusFormatter) sanitizeKey(s string) string {
8989
return f.sanitNameRegex.ReplaceAllString(s, "_")
9090
}

pkg/exporter/sumologicexporter/prometheus_formatter_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ func TestSanitizeKey(t *testing.T) {
2626
f, err := newPrometheusFormatter()
2727
require.NoError(t, err)
2828

29-
key := "&^*123-abc-ABC!?"
30-
expected := "___123_abc_ABC__"
29+
key := "&^*123-abc-ABC!./?_:"
30+
expected := "___123_abc_ABC_./__:"
3131
assert.Equal(t, expected, f.sanitizeKey(key))
3232
}
3333

3434
func TestSanitizeValue(t *testing.T) {
3535
f, err := newPrometheusFormatter()
3636
require.NoError(t, err)
3737

38-
value := `&^*123-abc-ABC!?"\\n`
39-
expected := `&^*123-abc-ABC!?\"\\\n`
38+
value := `&^*123-abc-ABC!?./"\\n`
39+
expected := `&^*123-abc-ABC!?./\"\\\n`
4040
assert.Equal(t, expected, f.sanitizeValue(value))
4141
}
4242

pkg/exporter/sumologicexporter/sender_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ func TestSendMetrics(t *testing.T) {
780780
test := prepareSenderTest(t, []func(w http.ResponseWriter, req *http.Request){
781781
func(w http.ResponseWriter, req *http.Request) {
782782
body := extractBody(t, req)
783-
expected := `test_metric_data{test="test_value",test2="second_value"} 14500 1605534165000
783+
expected := `test.metric.data{test="test_value",test2="second_value"} 14500 1605534165000
784784
gauge_metric_name{foo="bar",remote_name="156920",url="http://example_url"} 124 1608124661166
785785
gauge_metric_name{foo="bar",remote_name="156955",url="http://another_url"} 245 1608124662166`
786786
assert.Equal(t, expected, body)
@@ -806,7 +806,7 @@ func TestSendMetricsSplit(t *testing.T) {
806806
test := prepareSenderTest(t, []func(w http.ResponseWriter, req *http.Request){
807807
func(w http.ResponseWriter, req *http.Request) {
808808
body := extractBody(t, req)
809-
expected := `test_metric_data{test="test_value",test2="second_value"} 14500 1605534165000`
809+
expected := `test.metric.data{test="test_value",test2="second_value"} 14500 1605534165000`
810810
assert.Equal(t, expected, body)
811811
},
812812
func(w http.ResponseWriter, req *http.Request) {
@@ -833,7 +833,7 @@ func TestSendMetricsSplitFailedOne(t *testing.T) {
833833
w.WriteHeader(500)
834834

835835
body := extractBody(t, req)
836-
expected := `test_metric_data{test="test_value",test2="second_value"} 14500 1605534165000`
836+
expected := `test.metric.data{test="test_value",test2="second_value"} 14500 1605534165000`
837837
assert.Equal(t, expected, body)
838838
},
839839
func(w http.ResponseWriter, req *http.Request) {
@@ -861,7 +861,7 @@ func TestSendMetricsSplitFailedAll(t *testing.T) {
861861
w.WriteHeader(500)
862862

863863
body := extractBody(t, req)
864-
expected := `test_metric_data{test="test_value",test2="second_value"} 14500 1605534165000`
864+
expected := `test.metric.data{test="test_value",test2="second_value"} 14500 1605534165000`
865865
assert.Equal(t, expected, body)
866866
},
867867
func(w http.ResponseWriter, req *http.Request) {

0 commit comments

Comments
 (0)