New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify metrics so that names are normalized to legal chars #771
Modify metrics so that names are normalized to legal chars #771
Conversation
theshadow
commented
Sep 7, 2016
- Add function for normalizing metric keys
- Add tests for metrics functions.
// This function is used to make metric names safe for all metric services. Specifically, prometheus does | ||
// not support * or / in metric names. | ||
func normalizeKeys(key []string) { | ||
if key != nil { |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
k = strings.Replace(k, allMatcher, allReplacement, -1) | ||
|
||
// now replace all other invalid characters with a safe one. | ||
key[i] = invalidCharactersRE.ReplaceAllString(k, normalizedToken) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
} | ||
|
||
// SetMetrics initializes goa's metrics instance with the supplied metrics adapter interface. | ||
func SetMetrics(m Metrics) { | ||
metriks = m | ||
mu.Lock() |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Left a few comments to address, mainly removing the mutex and changing the regexp used by the test code.
// metriks atomic value storage | ||
metriks atomic.Value | ||
|
||
// mu mutex for metriks |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
invalidCharactersRE = regexp.MustCompile(`[\*/]`) | ||
|
||
// Taken from https://github.com/prometheus/client_golang/blob/66058aac3a83021948e5fb12f1f408ff556b9037/prometheus/desc.go | ||
metricsNameRE = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_:]*$`) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
* Refactor NoopSink to be NoOpSink * Create NoOpSink factory method
Thank you for all the work! |
…#771) * Add normalizeKeys() function for normalizing metric key names * Properly synchronize updates to metrics object
* Added the ability to dynamically add/remove keys from the jwt security middleware after creation. (#818) * Refactor JWT key resolver (#832) To introduce new "simple" resolver. * Add an interface instead of using testing.T (#733) * removed unneeded check which would make an unsafe concurrent modification (#736) - logit() doesn't need to modify a.keyvals because it was already fixed up in New() * Modify metrics so that names are normalized to legal chars (#771) * Add normalizeKeys() function for normalizing metric key names * Properly synchronize updates to metrics object * Fix setting a default value to datetime * Add tests for a default value of datetime * address issue #738 by creating a title for the test file * Fix a finalize test * Revert "Refactor JWT key resolver (#832)" This reverts commit f6ecb66. * Revert "Added the ability to dynamically add/remove keys from the jwt security middleware after creation. (#818)" This reverts commit 4c7fc9d.