-
Notifications
You must be signed in to change notification settings - Fork 57
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
Feature request (again): Tags #53
Comments
@bconway As mentioned in the previous issue (#38), the current send pipeline was not really designed with tag support in mind, and as such there are some send pipeline and buffer optimizations that make it a bit harder to just glue on tag support. However, I'm willing to take another look when I get some available time, and see how difficult it would be to add tag support (without breaking the existing api for existing users). I've been busy with work lately though, so it might take a while to dig into things. |
@bconway I've come up with two possible ways to accomplish this in some local test code. proposal 1: Subclient-styleThis creates a subclient that "owns" the tags. Perhaps helpful if you want to pass a tagged subclient off to a module that will send specific tags for every stat call.
Pros
Cons
proposal 2: Duplicate methods, but with TagsThis just adds a duplicate set of methods to the client struct that accepts a tag list
Pros
Cons
I'm leaning towards the second proposal, even though it results in more code and a bit of duplication, due to the reduction in memory garbage that the subclient generates when it is created and then just thrown away (when used in the |
Thank you for that write-up, it was extensive and you've obviously put a lot of thought into it. I agree with all your pros and cons. The Have you considered a third approach, a variadic final arg?
I can't speak the garbage generation, but the API would remain backward compatible, I believe. |
I did consider the variadic format, but discounted it because at one point long ago I remembered reading something about variadic functions in Go doing some extra heap allocation because the escape analytics couldn't ensure it wasn't used outside the function call... but thinking about it now that was a real long time ago, and is probably a non-issue now (I did some searching and only ran across very old posts about it). ...As such that does seem like another viable option too, and in fact seems preferable over the others I proposed. Nice! I'll give that one a try, and see if it adds much overhead for non-tag calls. |
* Add Tag support: suffix-octothorpe, infix-comma, infix-semicolon (GH-53) * Remove previously deprecated NoopClient. Use a nil `*Client` Statter as a replacement, if needed. Ex: ``` var client Client // A nil *Client has noop behavior, so this is safe. // It will become a small overhead (just a couple function calls) noop. err = client.Inc("stat1", 42, 1.0) ```
* Add Tag support: suffix-octothorpe, infix-comma, infix-semicolon (GH-53) * Remove previously deprecated NoopClient. Use a nil `*Client` Statter as a replacement, if needed. Ex: ``` var client Client // A nil *Client has noop behavior, so this is safe. // It will become a small overhead (just a couple function calls) noop. err = client.Inc("stat1", 42, 1.0) ``` * bump major ver
work in progress branch here: https://github.com/cactus/go-statsd-client/tree/taggle-rock-2 usage: // First create a client config. Here is a simple config that sends one
// stat per packet (for compatibility).
config := &statsd.ClientConfig{
Address: "127.0.0.1:8125",
Prefix: "test-client",
}
/*
// This one is an example of configuring "Tag" support
// Supported formats are:
// InfixComma
// InfixSemicolon
// SuffixOctothorpe
// The default, if not otherwise specified, is SuffixOctothorpe.
config := &statsd.ClientConfig{
Address: "127.0.0.1:8125",
Prefix: "test-client",
ResInterval: 30 * time.Second,
TagFormat: statsd.InfixSemicolon,
}
*/
// Now create the client
client, err := statsd.NewClientWithConfig(config)
// and handle any initialization errors
if err != nil {
log.Fatal(err)
}
// make sure to close to clean up when done, to avoid leaks.
defer client.Close()
// Send a stat
client.Inc("stat1", 42, 1.0)
// Send a stat with "Tags"
client.Inc("stat2", 41, 1.0, Tag{"mytag", "tagval"}) |
* Add Tag support: suffix-octothorpe, infix-comma, infix-semicolon (GH-53) * Remove previously deprecated NoopClient. Use a nil `*Client` Statter as a replacement, if needed. Ex: ``` var client Client // A nil *Client has noop behavior, so this is safe. // It will become a small overhead (just a couple function calls) noop. err = client.Inc("stat1", 42, 1.0) ``` * bump major ver
@bconway this has been merged, but it is tagged as v5.0.0-alpha.0. To experiment with it, make the following modifications to your project's.... go.mod
using in code
Once it gets some more testing, and barring any major issues, I'll tag it as v5.0.0 |
closing as completed. |
Much appreciated! |
Since the last issue over two years ago (#38), Graphite, Datadog, and InfluxDB have all accepted tags as relatively important functionality, with slightly different formatting between them (example: https://github.com/smira/go-statsd/pull/29/files). Would it be possible to support this?
The text was updated successfully, but these errors were encountered: