From 382a1ef45360b538a80fd5d34cde71f53522dc2a Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 6 Dec 2017 15:11:38 +0100 Subject: Add invalid builds counter metric to stage seeds class --- lib/gitlab/ci/stage/seed.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/gitlab/ci') diff --git a/lib/gitlab/ci/stage/seed.rb b/lib/gitlab/ci/stage/seed.rb index bc97aa63b02..6a3b2f6cc4a 100644 --- a/lib/gitlab/ci/stage/seed.rb +++ b/lib/gitlab/ci/stage/seed.rb @@ -39,6 +39,10 @@ module Gitlab pipeline.stages.create!(stage).tap do |stage| builds_attributes = builds.map do |attributes| attributes.merge(stage_id: stage.id) + + if attributes.fetch(:stage_id).nil? + invalid_builds_counter.increment(node: hostname) + end end pipeline.builds.create!(builds_attributes).each do |build| @@ -52,6 +56,15 @@ module Gitlab def protected_ref? @protected_ref ||= project.protected_for?(pipeline.ref) end + + def invalid_builds_counter + @counter ||= Gitlab::Metrics.counter(:invalid_builds_counter, + 'Builds without stage assigned counter') + end + + def hostname + @hostname ||= Socket.gethostname + end end end end -- cgit v1.2.1