Skip to content

Commit

Permalink
feat(sumologicexporter): allows . and / for prometheus key
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Rosiek <drosiek@sumologic.com>
  • Loading branch information
Dominik Rosiek committed Sep 13, 2021
1 parent 2a5baaa commit aeecd6b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/exporter/sumologicexporter/prometheus_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (
)

func newPrometheusFormatter() (prometheusFormatter, error) {
sanitNameRegex, err := regexp.Compile(`[^0-9a-zA-Z]`)
sanitNameRegex, err := regexp.Compile(`[^0-9a-zA-Z\./]`)
if err != nil {
return prometheusFormatter{}, err
}
Expand Down Expand Up @@ -84,7 +84,7 @@ func (f *prometheusFormatter) tags2String(attr pdata.AttributeMap, labels pdata.
}

// sanitizeKey returns sanitized key string by replacing
// all non-alphanumeric chars with `_`
// all non-allowed chars with `_`
func (f *prometheusFormatter) sanitizeKey(s string) string {
return f.sanitNameRegex.ReplaceAllString(s, "_")
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/exporter/sumologicexporter/prometheus_formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ func TestSanitizeKey(t *testing.T) {
f, err := newPrometheusFormatter()
require.NoError(t, err)

key := "&^*123-abc-ABC!?"
expected := "___123_abc_ABC__"
key := "&^*123-abc-ABC!./?"
expected := "___123_abc_./ABC__"
assert.Equal(t, expected, f.sanitizeKey(key))
}

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

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

Expand Down

0 comments on commit aeecd6b

Please sign in to comment.