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

Don't hijack statsd #384

Merged
merged 19 commits into from
Dec 12, 2018
Merged

Don't hijack statsd #384

merged 19 commits into from
Dec 12, 2018

Conversation

timothysmith0609
Copy link
Contributor

@timothysmith0609 timothysmith0609 commented Nov 26, 2018

Problem

Currently, if KubernetesDeploy is used as part of a library, it will hijack the global StatsD configuration and, among other things, will prefix all metrics with KubernetesDeploy. Ideally, KubernetesDeploy should not mutate global config like this and its StatsD configuration should be scoped more tightly to itself.

Closes #336.

Proposed solution

Instead of KubernetesDeploy::StatsD simply acting as an interface to the global StatsD configuration, it will instead extend it and become a singleton in its own right. This allows us to specify config parameters for KubernetesDeploy::StatsD without overriding the global configuration.

Issues

Unfortunately, some methods in the StatsD library make statically scoped calls to the StatsD gem itself. Thankfully this only seems to occur when initializing new metrics. After perusing the statsd-instrument repo, I noticed that we aren't the first to come across this and the proposed solution was pretty much what I had in mind. The PR is here. Testing locally with the changes to the gem yields successful test passes Edit: this has been shipped

lib/kubernetes-deploy/statsd.rb Outdated Show resolved Hide resolved
@timothysmith0609 timothysmith0609 changed the title -WIP- Dont hijack statsd Dont hijack statsd Nov 27, 2018
@timothysmith0609 timothysmith0609 changed the title Dont hijack statsd Don't hijack statsd Nov 27, 2018
@timothysmith0609
Copy link
Contributor Author

This PR is currently blocked by statsd-instrument #148, which allows for multiple prefixes.

@timothysmith0609
Copy link
Contributor Author

statsd-instrument #148 has been shipped and released as v2.3.2. This lets us use the :prefix option when creating metrics.

Copy link
Contributor

@KnVerey KnVerey left a comment

Choose a reason for hiding this comment

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

Few comments + this needs a rebase, but approach looks great!

lib/kubernetes-deploy/statsd.rb Outdated Show resolved Hide resolved
lib/kubernetes-deploy/runner_task.rb Outdated Show resolved Hide resolved
test/helpers/statsd_helper.rb Outdated Show resolved Hide resolved
test/integration-serial/serial_task_run_test.rb Outdated Show resolved Hide resolved
test/test_helper.rb Outdated Show resolved Hide resolved
remove accidental file, fix line length

Extract prefix to const

simpler scoping for StatsD.build call

Don't need to build StatsD in test_helper

include StatsDHelper, not class method

policial

rebase fix

rebase fix

rebase fix

centralize adding prefix

more fix

more fix
@timothysmith0609
Copy link
Contributor Author

Rebased on master. This is ready for a final round of 👀

lib/kubernetes-deploy/deploy_task.rb Outdated Show resolved Hide resolved
lib/kubernetes-deploy/statsd.rb Outdated Show resolved Hide resolved
lib/kubernetes-deploy/statsd.rb Outdated Show resolved Hide resolved
lib/kubernetes-deploy/statsd.rb Show resolved Hide resolved
test/unit/kubernetes-deploy/statsd_test.rb Show resolved Hide resolved
test/unit/kubernetes-deploy/statsd_test.rb Outdated Show resolved Hide resolved
@timothysmith0609 timothysmith0609 self-assigned this Dec 10, 2018
Copy link
Contributor

@dturn dturn left a comment

Choose a reason for hiding this comment

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

Looks good, the dashboards will need to be updated before we deploy this.

def self.duration(start_time)
(Time.now.utc - start_time).round(1)
end

def self.build
::StatsD.default_sample_rate = 1.0
::StatsD.prefix = "KubernetesDeploy"
self.default_sample_rate = 1.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this the default behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually this suffers from the same problem as StatsD.prefix in that it's statically referenced in the underlying library so won't have an effect here (`options[:sample_rate] is used to override if ever we need). I'll remove this line as well.

lib/kubernetes-deploy/statsd.rb Show resolved Hide resolved
@timothysmith0609
Copy link
Contributor Author

timothysmith0609 commented Dec 11, 2018

Looks good, the dashboards will need to be updated before we deploy this.

Perhaps it's my unfamiliarity with DataDog, but what do we need to change, exactly?

@KnVerey
Copy link
Contributor

KnVerey commented Dec 12, 2018

Aggregations on distribution metrics aren't done automatically, so we need to configure our new metrics in the Datadog UI. The graphs then apparently need to be adjusted as well, because the format isn't quite the same even once the aggregations exist. Danny was working on both, but I'm intending to pick it up from him tomorrow since he's busy with KubeCon. If you'd like to own that instead though, just let me know! I haven't started yet. 😄

@timothysmith0609 timothysmith0609 merged commit eebf155 into master Dec 12, 2018
@timothysmith0609 timothysmith0609 deleted the dont_hijack_statsd branch December 12, 2018 17:09
@KnVerey KnVerey temporarily deployed to rubygems December 14, 2018 23:13 Inactive
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.

Don't hijack global StatsD configuration
3 participants