diff --git a/qa/gems/gitlab-cng/lib/gitlab/cng/lib/deployment/installation.rb b/qa/gems/gitlab-cng/lib/gitlab/cng/lib/deployment/installation.rb index 2adaf9d671a3269d8accb8e5101544d647f53142..ac3e09e9852916e64aca5ef83f58a87c56dee579 100644 --- a/qa/gems/gitlab-cng/lib/gitlab/cng/lib/deployment/installation.rb +++ b/qa/gems/gitlab-cng/lib/gitlab/cng/lib/deployment/installation.rb @@ -17,6 +17,12 @@ class Installation LICENSE_SECRET = "gitlab-license" TROUBLESHOOTING_LINK = "https://gitlab.com/gitlab-org/gitlab/-/tree/master/qa/gems/gitlab-cng?ref_type=heads#troubleshooting" + # Ignore metrics events when logging events on deploy failure, + # these get generated on pod startup due to various reasons like pod not ready and don't affect deployment state + # + # @return [Array] + IGNORED_EVENTS = %w[FailedComputeMetricsReplicas FailedGetResourceMetric].freeze + # Delete installation # # @param [String] name @@ -254,6 +260,7 @@ def get_warning_events events = items .select { |item| item[:kind] == "Event" && item[:type] == "Warning" } + .reject { |item| IGNORED_EVENTS.include?(item[:reason]) } .map do |item| object = item[:involvedObject] diff --git a/qa/gems/gitlab-cng/spec/unit/gitlab/cng/deployment/installation_spec.rb b/qa/gems/gitlab-cng/spec/unit/gitlab/cng/deployment/installation_spec.rb index 85cdde63c20dc169383f5c27c9734823deb400e4..b1ffb7e90bfb410bcc39eb493527e279ead5e0d0 100644 --- a/qa/gems/gitlab-cng/spec/unit/gitlab/cng/deployment/installation_spec.rb +++ b/qa/gems/gitlab-cng/spec/unit/gitlab/cng/deployment/installation_spec.rb @@ -75,41 +75,53 @@ end context "with deployment failure" do - let(:warn_event) do - { - involvedObject: { - kind: "HorizontalPodAutoscaler", - name: "gitlab-webservice-default" + let(:warn_events) do + [ + { + involvedObject: { + kind: "Pod", + name: "gitlab-webservice-default" + }, + kind: "Event", + message: "failed to sync secret cache: timed out waiting for the condition", + reason: "FailedMount", + type: "Warning" }, - kind: "Event", - message: "failed to get cpu usage", - reason: "FailedGetResourceMetric", - type: "Warning" - } + { + involvedObject: { + kind: "HorizontalPodAutoscaler", + name: "gitlab-webservice-default" + }, + kind: "Event", + message: "failed to get cpu usage", + reason: "FailedGetResourceMetric", + type: "Warning" + } + ] end + let(:valid_event) { warn_events.first } + let(:removed_event) { warn_events.last } + before do allow(helmclient).to receive(:upgrade).and_raise(Gitlab::Cng::Helm::Client::Error, "error") - allow(kubeclient).to receive(:events).with(json_format: true).and_return(<<~EVENTS) - { - "items": [ - #{JSON.pretty_generate(warn_event)}, - { - "type": "Normal" - } - ] - } - EVENTS + allow(kubeclient).to receive(:events).with(json_format: true).and_return({ items: warn_events }.to_json) end context "without retry" do - it "automatically prints warning events" do + it "automatically prints warning events and troubleshooting info" do expect { expect { installation.create }.to raise_error(SystemExit) }.to output( - match("#{warn_event[:involvedObject][:kind]}/#{warn_event[:involvedObject][:name]}") - .and(match(warn_event[:message])) + match("#{valid_event[:involvedObject][:kind]}/#{valid_event[:involvedObject][:name]}") + .and(match(valid_event[:message])) .and(match(/For more information on troubleshooting failures, see: \S+/)) ).to_stdout end + + it "removes metrics related warning events" do + expect { expect { installation.create }.to raise_error(SystemExit) }.not_to output( + match("#{removed_event[:involvedObject][:kind]}/#{removed_event[:involvedObject][:name]}") + ).to_stdout + end end context "with retry" do