Skip to content

Commit

Permalink
Merge pull request #402 from Shopify/fix_dep
Browse files Browse the repository at this point in the history
Bump statsd-instrument dep for prefix
  • Loading branch information
KnVerey committed Dec 14, 2018
2 parents edba90c + 7b5113c commit 01dc26f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion kubernetes-deploy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "googleauth", "~> 0.6.6" # https://github.com/google/google-auth-library-ruby/issues/153
spec.add_dependency "ejson", "~> 1.0"
spec.add_dependency "colorize", "~> 0.8"
spec.add_dependency "statsd-instrument", "~> 2.3"
spec.add_dependency "statsd-instrument", '~> 2.3', '>= 2.3.2'
spec.add_dependency "oj", "~> 3.7"
spec.add_dependency "concurrent-ruby", "~> 1.1"

Expand Down
2 changes: 1 addition & 1 deletion lib/kubernetes-deploy/deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def deploy_resources(resources, prune: false, verify:, record_summary: true)

if verify
watcher = ResourceWatcher.new(resources: resources, logger: @logger, deploy_started_at: deploy_started_at,
timeout: @max_watch_seconds, namespace: @namespace, context: @context)
timeout: @max_watch_seconds, namespace: @namespace, context: @context, sha: @current_sha)
watcher.run(record_summary: record_summary)
end
end
Expand Down
11 changes: 10 additions & 1 deletion lib/kubernetes-deploy/resource_watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ResourceWatcher
extend KubernetesDeploy::StatsD::MeasureMethods

def initialize(resources:, logger:, context:, namespace:,
deploy_started_at: Time.now.utc, operation_name: "deploy", timeout: nil)
deploy_started_at: Time.now.utc, operation_name: "deploy", timeout: nil, sha: nil)
unless resources.is_a?(Enumerable)
raise ArgumentError, <<~MSG
ResourceWatcher expects Enumerable collection, got `#{resources.class}` instead
Expand All @@ -17,6 +17,7 @@ def initialize(resources:, logger:, context:, namespace:,
@deploy_started_at = deploy_started_at
@operation_name = operation_name
@timeout = timeout
@sha = sha
end

def run(delay_sync: 3.seconds, reminder_interval: 30.seconds, record_summary: true)
Expand Down Expand Up @@ -54,6 +55,14 @@ def sync_resources(resources)
end
measure_method(:sync_resources, "sync.duration")

def statsd_tags
{
namespace: @namespace,
context: @context,
sha: @sha
}
end

def global_timeout?(started_at)
@timeout && (Time.now.utc - started_at > @timeout)
end
Expand Down
9 changes: 4 additions & 5 deletions test/integration-serial/serial_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,11 @@ def test_stage_related_metrics_include_custom_tags_from_namespace

def test_all_expected_statsd_metrics_emitted_with_essential_tags
metrics = capture_statsd_calls do
result = deploy_fixtures('hello-cloud', subset: ['configmap-data.yml'], wait: false)
result = deploy_fixtures('hello-cloud', subset: ['configmap-data.yml'], wait: false, sha: 'test-sha')
assert_deploy_success(result)
end

assert_equal 1, metrics.count { |m| m.type == :_e }, "Expected to find one event metric"
assert_predicate metrics, :all? do |metric|
assert_includes metric.tags, "namespace:#{@namespace}"
assert_includes metric.tags, "context:#{KubeclientHelper::TEST_CONTEXT}"
end

%w(
KubernetesDeploy.validate_configuration.duration
Expand All @@ -233,6 +229,9 @@ def test_all_expected_statsd_metrics_emitted_with_essential_tags
).each do |expected_metric|
metric = metrics.find { |m| m.name == expected_metric }
refute_nil metric, "Metric #{expected_metric} not emitted"
assert_includes metric.tags, "namespace:#{@namespace}", "#{metric.name} is missing namespace tag"
assert_includes metric.tags, "context:#{KubeclientHelper::TEST_CONTEXT}", "#{metric.name} is missing context tag"
assert_includes metric.tags, "sha:test-sha", "#{metric.name} is missing sha tag"
end
end

Expand Down

0 comments on commit 01dc26f

Please sign in to comment.