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

Adding Sanitizer interface and implementation #70

Closed
wants to merge 1 commit into from

Conversation

ravirajj
Copy link

@ravirajj ravirajj commented May 3, 2020

  • Sanitizes metric names and tag keys and values.
  • Does nothing by default.
  • The ScopeBulider can be configured with the standard M3Sanitizer.
  • Fixes Add Metrics Sanitizer  #8

/**
* Sanitize returns a sanitized version of the input string value.
*/
public interface Sanitize {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try for a different name. Sanitize next to Sanitizer confused me thoroughly

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Sanitizer interface matches the uber-go/tally Sanitizer interface.

The Sanitize interface is meant to match the uber-go/tally SanitizeFn interface. Name it SanitizeFn too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please elaborate on what this interface is needed for


// first check if the provided character is valid
boolean validCurr =
ranges.stream().anyMatch(range -> ch >= range.low() && ch <= range.high())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this operation performance-sensitive? If so, this looks very expensive

Copy link
Author

@ravirajj ravirajj May 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It matches the uber-go/tally sanitzeFn(). Like the go version, it optimizes allocations by avoiding copying if the all characters are valid. Any suggestions on how to optimize this in Java?

@longquanzheng
Copy link

Any progress on this PR? @ravirajj @inetchitailo ?

@longquanzheng
Copy link

@SokolAndrey @andrewmains12 @alexeykudinkin can you help take a look? I am needing this in my project. Thanks so much

@@ -313,6 +320,14 @@ public Snapshot snapshot() {
return snap;
}

private ImmutableMap<String, String> copyAndSanitizeMap(Map<String, String> tags) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid copying if there are no changes to the map

* @param name the name string
* @return the sanitized name
*/
String name(String name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the naming convention -- method name should bear a verb in it

/**
* Sanitize returns a sanitized version of the input string value.
*/
public interface Sanitize {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please elaborate on what this interface is needed for

@longquanzheng
Copy link

@alexeykudinkin @ravirajj Hello, thanks so much for this.
Would you mind if I fork this branch and open another PR to address the comments?

Thanks

@alexeykudinkin
Copy link
Contributor

@longquanzheng works for me

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.

Add Metrics Sanitizer
4 participants