Skip to content

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.

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.

2 participants