Skip to content
代码片段 群组 项目
未验证 提交 d2b5593f 编辑于 作者: Chloe Liu's avatar Chloe Liu 提交者: GitLab
浏览文件

Merge branch 'andrey-filter-resource-api-warnings' into 'master'

Automatically remove metrics related events on deploy failure output

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/168157



Merged-by: default avatarChloe Liu <yliu@gitlab.com>
Approved-by: default avatarChloe Liu <yliu@gitlab.com>
Co-authored-by: default avatarAndrejs Cunskis <acunskis@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -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]
......
......@@ -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
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册