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

statsd: add Flush() to datadogBackend #142

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mtwstudios
Copy link

Remade this PR from #141 to re-trigger CLA

This PR adds a public method to flush any remaining metrics manually (rather than waiting for the flush interval), by calling the Flush() method on the dogstatsd client.

This is helpful in the case of recording a metric right before terminating the program. In this case, the metric will not get submitted to datadog - the only workaround being putting a sleep in place for at least as long as the flush interval.

With this, one can call Flush() before the program terminates to make sure any remaining metrics are submitted to Datadog.

@mtwstudios
Copy link
Author

@lavoiesl would you be the right person to review this? Let me know if you have any questions/concerns, etc.

@@ -55,3 +55,7 @@ func (b *datadogBackend) Set(ctx context.Context, name string, value string, tag
func (b *datadogBackend) Timing(ctx context.Context, name string, value time.Duration, tags []string, rate float64) error {
return b.client.Timing(name, value, tags, rate)
}

func (b *datadogBackend) Flush() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding the method here would not be accessible because only the interface is exported.

Adding the method on the interface would be a breaking change.

Not saying it can't be done, but it's a more complicated change than adding it here.

As an alternative could be to add a method to take in a Client such that one could flush the client directly?

func NewDatadogBackend(endpoint, namespace string, tags []string) (Backend, error) {
	client, err := statsd.New(endpoint)
	if err != nil {
		return nil, err
	}
	client.Tags = tags
	return NewDatadogBackendFromClient(client, namespace)
}

func NewDatadogBackendFromClient(client *statsd.Client, namespace string) (Backend, error) {
	client.Namespace = namespace
	client.Tags = append(defaultTagsFromEnv(), client.Tags...)
	return &datadogBackend{
		client: client,
	}, nil
}

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