-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
services/horizon: Strip regexes from routes before sending to prometh…
…eus (#3459) * Strip regexes from routes before sending to prometheus Fixes #3436 * Escape the regex values instead of removing them, when sending to prometheus * Update changelog for pull 3459 * use assert.Equal for consistency
- Loading branch information
1 parent
c908d78
commit 0977967
Showing
3 changed files
with
68 additions
and
5 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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package httpx | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMiddlewareSanitizesRoutesForPrometheus(t *testing.T) { | ||
for _, setup := range []struct { | ||
name string | ||
route string | ||
expected string | ||
}{ | ||
{ | ||
"normal routes", | ||
"/accounts", | ||
"/accounts", | ||
}, | ||
{ | ||
"non-regex params", | ||
"/claimable_balances/{id}", | ||
"/claimable_balances/{id}", | ||
}, | ||
{ | ||
"named regexes", | ||
"/accounts/{account_id:\\w+}/effects", | ||
"/accounts/{account_id}/effects", | ||
}, | ||
{ | ||
"unnamed regexes", | ||
"/accounts/{\\w+}/effects", | ||
"/accounts/{\\\\w+}/effects", | ||
}, | ||
{ | ||
// Not likely used in routes, but just safer for prom metrics anyway | ||
"quotes", | ||
"/{\"}", | ||
"/{\\\"}", | ||
}, | ||
} { | ||
t.Run(setup.name, func(t *testing.T) { | ||
assert.Equal(t, setup.expected, sanitizeMetricRoute(setup.route)) | ||
}) | ||
} | ||
|
||
} |