Skip to content
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

Conversation

theshadow
Copy link

  • 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.

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.

}

// 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.

Copy link
Member

@raphael raphael left a 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.

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.

This comment was marked as off-topic.

@raphael
Copy link
Member

raphael commented Sep 20, 2016

Thank you for all the work!

@raphael raphael merged commit bc7bea7 into goadesign:master Sep 20, 2016
ikawaha pushed a commit to ikawaha/goa that referenced this pull request Dec 13, 2016
…#771)

* Add normalizeKeys() function for normalizing metric key names

* Properly synchronize updates to metrics object
raphael pushed a commit that referenced this pull request Dec 14, 2016
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants