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

Allow TaggedNameBuilder to overwrite previous value for a key #85

Open
xiaochuanyu opened this issue Aug 16, 2017 · 0 comments
Open

Allow TaggedNameBuilder to overwrite previous value for a key #85

xiaochuanyu opened this issue Aug 16, 2017 · 0 comments

Comments

@xiaochuanyu
Copy link

Is there a particular reason why we allow duplicate key/val for tags?
I see this in the code:

public TaggedNameBuilder addTag(String key, String val) {
assertNonEmpty(key, "tagKey");
encodedTags.add(new StringBuilder(key).append(':').append(val).toString());
return this;
}

This makes it not possible to overwrite tag values using the builder such as when you want to start with some default values for certain tags but overwrite them later conditionally.
The simplest example:

TaggedName.TaggedNameBuilder taggedNameBuilder =new TaggedName.TaggedNameBuilder().metricName("request_rate");
taggedNameBuilder.addTag("host_type", "default");
if (isSpecialCondition()) {
    taggedNameBuilder.addTag("host_type", "special");    
}
// etc

To maintain 100% backward compatibility, we can add a setTag(key, value) method that will overwrite or create tag with key/value.

@xiaochuanyu xiaochuanyu changed the title Allow TaggedNameBuilder to overwrite tag previous value for a key Allow TaggedNameBuilder to overwrite previous value for a key Aug 16, 2017
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

No branches or pull requests

1 participant