gitlab_quality-test_tooling 2.19.1 → 2.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.tool-versions +1 -1
- data/Gemfile.lock +30 -28
- data/exe/epic-readiness-notification +58 -0
- data/lib/gitlab_quality/test_tooling/click_house/client.rb +85 -0
- data/lib/gitlab_quality/test_tooling/feature_readiness/concerns/issue_concern.rb +1 -1
- data/lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb +11 -0
- data/lib/gitlab_quality/test_tooling/feature_readiness/epic_readiness_notifier.rb +308 -0
- data/lib/gitlab_quality/test_tooling/gcs_tools.rb +49 -0
- data/lib/gitlab_quality/test_tooling/gitlab_client/group_labels_client.rb +34 -0
- data/lib/gitlab_quality/test_tooling/report/generate_test_session.rb +1 -1
- data/lib/gitlab_quality/test_tooling/report/health_problem_reporter.rb +3 -3
- data/lib/gitlab_quality/test_tooling/report/merge_request_slow_tests_report.rb +2 -6
- data/lib/gitlab_quality/test_tooling/runtime/env.rb +5 -3
- data/lib/gitlab_quality/test_tooling/system_logs/finders/rails/api_log_finder.rb +1 -1
- data/lib/gitlab_quality/test_tooling/system_logs/finders/rails/application_log_finder.rb +1 -1
- data/lib/gitlab_quality/test_tooling/system_logs/finders/rails/exception_log_finder.rb +1 -1
- data/lib/gitlab_quality/test_tooling/system_logs/finders/rails/graphql_log_finder.rb +1 -1
- data/lib/gitlab_quality/test_tooling/test_meta/test_meta_updater.rb +2 -2
- data/lib/gitlab_quality/test_tooling/test_metrics_exporter/config.rb +88 -15
- data/lib/gitlab_quality/test_tooling/test_metrics_exporter/formatter.rb +71 -34
- data/lib/gitlab_quality/test_tooling/test_metrics_exporter/test_metrics.rb +105 -80
- data/lib/gitlab_quality/test_tooling/version.rb +1 -1
- metadata +58 -55
- data/lib/gitlab_quality/test_tooling/test_metrics_exporter/log_test_metrics.rb +0 -117
- data/lib/gitlab_quality/test_tooling/test_metrics_exporter/support/gcs_tools.rb +0 -49
- data/lib/gitlab_quality/test_tooling/test_metrics_exporter/support/influxdb_tools.rb +0 -33
@@ -5,131 +5,138 @@ require 'time'
|
|
5
5
|
module GitlabQuality
|
6
6
|
module TestTooling
|
7
7
|
module TestMetricsExporter
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def time
|
13
|
-
return @time if defined?(@time)
|
14
|
-
|
15
|
-
created_at = Time.strptime(env('CI_PIPELINE_CREATED_AT'), '%Y-%m-%dT%H:%M:%S%z') if env('CI_PIPELINE_CREATED_AT')
|
16
|
-
@time = Time.parse((created_at || Time.now).utc.strftime('%Y-%m-%d %H:%M:%S %z'))
|
8
|
+
class TestMetrics
|
9
|
+
def initialize(example, timestamp)
|
10
|
+
@example = example
|
11
|
+
@timestamp = timestamp
|
17
12
|
end
|
18
13
|
|
19
|
-
#
|
20
|
-
# Metrics tags
|
14
|
+
# Test data hash
|
21
15
|
#
|
22
|
-
# @param [RSpec::Core::Example] example
|
23
|
-
# @param [Array<String>] custom_keys
|
24
|
-
# @param [String]
|
25
16
|
# @return [Hash]
|
26
|
-
def
|
17
|
+
def data
|
27
18
|
{
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
job_name: job_name,
|
33
|
-
merge_request: merge_request,
|
34
|
-
run_type: run_type,
|
35
|
-
feature_category: example.metadata[:feature_category],
|
36
|
-
product_group: example.metadata[:product_group],
|
37
|
-
exception_class: example.execution_result.exception&.class&.to_s,
|
38
|
-
**custom_metrics(example.metadata, custom_keys)
|
19
|
+
time: timestamp,
|
20
|
+
**rspec_metrics,
|
21
|
+
**ci_metrics,
|
22
|
+
**custom_metrics
|
39
23
|
}.compact
|
40
24
|
end
|
41
|
-
# rubocop:enable Metrics/AbcSize
|
42
25
|
|
43
|
-
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :example, :timestamp
|
29
|
+
|
30
|
+
# Exporter configuration
|
31
|
+
#
|
32
|
+
# @return [Config]
|
33
|
+
def config
|
34
|
+
Config.configuration
|
35
|
+
end
|
36
|
+
|
37
|
+
# Rspec related metrics
|
44
38
|
#
|
45
|
-
# @param [RSpec::Core::Example] example
|
46
|
-
# @param [Array<String>] custom_keys
|
47
39
|
# @return [Hash]
|
48
|
-
def
|
40
|
+
def rspec_metrics # rubocop:disable Metrics/AbcSize
|
49
41
|
{
|
50
42
|
id: example.id,
|
43
|
+
name: example.full_description,
|
44
|
+
file_path: example.metadata[:file_path].sub(/\A./, ''),
|
45
|
+
status: example.execution_result.status,
|
51
46
|
run_time: (example.execution_result.run_time * 1000).round,
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
**custom_metrics(example.metadata, custom_keys)
|
59
|
-
}.compact
|
47
|
+
location: example_location,
|
48
|
+
exception_class: exception_class,
|
49
|
+
failure_exception: failure_exception,
|
50
|
+
quarantined: quarantined?,
|
51
|
+
test_retried: config.test_retried_proc.call(example)
|
52
|
+
}
|
60
53
|
end
|
61
54
|
|
62
|
-
#
|
63
|
-
#
|
64
|
-
# - if test is failed or pending, return rspec status
|
65
|
-
# - if test passed but had more than 1 attempt, consider test flaky
|
55
|
+
# CI related metrics
|
66
56
|
#
|
67
|
-
# @
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
57
|
+
# @return [Hash]
|
58
|
+
def ci_metrics
|
59
|
+
{
|
60
|
+
ci_project_id: env("CI_PROJECT_ID")&.to_i,
|
61
|
+
ci_project_path: env("CI_PROJECT_PATH"),
|
62
|
+
ci_job_name: ci_job_name,
|
63
|
+
ci_job_id: env('CI_JOB_ID')&.to_i,
|
64
|
+
ci_pipeline_id: env('CI_PIPELINE_ID')&.to_i,
|
65
|
+
ci_merge_request_iid: (env('CI_MERGE_REQUEST_IID') || env('TOP_UPSTREAM_MERGE_REQUEST_IID'))&.to_i,
|
66
|
+
ci_branch: env("CI_COMMIT_REF_NAME"),
|
67
|
+
ci_target_branch: env("CI_MERGE_REQUEST_TARGET_BRANCH_NAME")
|
68
|
+
}
|
74
69
|
end
|
75
70
|
|
76
|
-
#
|
71
|
+
# Additional custom metrics
|
77
72
|
#
|
78
|
-
# @
|
79
|
-
|
80
|
-
|
81
|
-
|
73
|
+
# @return [Hash]
|
74
|
+
def custom_metrics
|
75
|
+
metrics = example.metadata
|
76
|
+
.slice(*config.extra_rspec_metadata_keys)
|
77
|
+
.merge(config.custom_metrics_proc.call(example))
|
78
|
+
|
79
|
+
metrics.each_with_object({}) do |(k, value), custom_metrics|
|
80
|
+
custom_metrics[k.to_sym] = metrics_value(value)
|
81
|
+
end
|
82
82
|
end
|
83
83
|
|
84
84
|
# Checks if spec is quarantined
|
85
85
|
#
|
86
|
-
# @param [RSpec::Core::Example] example
|
87
86
|
# @return [String]
|
88
|
-
def quarantined
|
89
|
-
return
|
87
|
+
def quarantined?
|
88
|
+
return false unless example.metadata.key?(:quarantine)
|
90
89
|
|
91
90
|
# if quarantine key is present and status is pending, consider it quarantined
|
92
|
-
|
91
|
+
example.execution_result.status == :pending
|
93
92
|
end
|
94
93
|
|
95
94
|
# Base ci job name
|
96
95
|
#
|
97
96
|
# @return [String]
|
98
|
-
def
|
99
|
-
|
97
|
+
def ci_job_name
|
98
|
+
env("CI_JOB_NAME")&.gsub(%r{ \d{1,2}/\d{1,2}}, '')
|
100
99
|
end
|
101
100
|
|
102
|
-
#
|
101
|
+
# Example location
|
103
102
|
#
|
104
103
|
# @return [String]
|
105
|
-
def
|
106
|
-
|
104
|
+
def example_location
|
105
|
+
# ensures that location will be correct even in case of shared examples
|
106
|
+
file = example
|
107
|
+
.metadata
|
108
|
+
.fetch(:shared_group_inclusion_backtrace)
|
109
|
+
.last
|
110
|
+
&.formatted_inclusion_location
|
111
|
+
|
112
|
+
return example.location unless file
|
113
|
+
|
114
|
+
file
|
107
115
|
end
|
108
116
|
|
109
|
-
#
|
117
|
+
# Failure exception class
|
110
118
|
#
|
111
119
|
# @return [String]
|
112
|
-
def
|
113
|
-
|
120
|
+
def exception_class
|
121
|
+
example.execution_result.exception&.class&.to_s
|
114
122
|
end
|
115
123
|
|
116
|
-
#
|
124
|
+
# Truncated exception stacktrace
|
117
125
|
#
|
118
|
-
# @
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
return {} if custom_keys.nil?
|
123
|
-
|
124
|
-
custom_metrics = {}
|
125
|
-
custom_keys.each do |k|
|
126
|
-
value = metadata[k.to_sym]
|
127
|
-
v = value.is_a?(Numeric) || value.nil? ? value : value.to_s
|
126
|
+
# @return [String]
|
127
|
+
def failure_exception
|
128
|
+
example.execution_result.exception.then do |exception|
|
129
|
+
next unless exception
|
128
130
|
|
129
|
-
|
131
|
+
exception.to_s.tr("\n", " ").slice(0, 1000)
|
130
132
|
end
|
133
|
+
end
|
131
134
|
|
132
|
-
|
135
|
+
# Test run type | suite name
|
136
|
+
#
|
137
|
+
# @return [String]
|
138
|
+
def run_type
|
139
|
+
config.run_type || ci_job_name || "unknown"
|
133
140
|
end
|
134
141
|
|
135
142
|
# Return non empty environment variable value
|
@@ -141,6 +148,24 @@ module GitlabQuality
|
|
141
148
|
|
142
149
|
ENV.fetch(name)
|
143
150
|
end
|
151
|
+
|
152
|
+
# Metrics value cast to a valid type
|
153
|
+
#
|
154
|
+
# @param value [Object]
|
155
|
+
# @return [Object]
|
156
|
+
def metrics_value(value)
|
157
|
+
return value if value.is_a?(Numeric) || value.is_a?(String) || bool?(value) || value.nil?
|
158
|
+
|
159
|
+
value.to_s
|
160
|
+
end
|
161
|
+
|
162
|
+
# Value is a true or false
|
163
|
+
#
|
164
|
+
# @param val [Object]
|
165
|
+
# @return [Boolean]
|
166
|
+
def bool?(val)
|
167
|
+
[true, false].include?(val)
|
168
|
+
end
|
144
169
|
end
|
145
170
|
end
|
146
171
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab_quality-test_tooling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.20.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitLab Quality
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: climate_control
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.1'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: guard-rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,117 +109,117 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '13.0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rest-client
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 2.1.0
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 2.1.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: rspec
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '3.12'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
138
|
+
version: '3.12'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: rspec_junit_formatter
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
145
|
+
version: 0.6.0
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
152
|
+
version: 0.6.0
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: simplecov
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '0.
|
159
|
+
version: '0.22'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: '0.
|
166
|
+
version: '0.22'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
168
|
+
name: simplecov-cobertura
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
173
|
+
version: '2.1'
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
180
|
+
version: '2.1'
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
|
-
name:
|
182
|
+
name: solargraph
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
|
-
- -
|
185
|
+
- - "~>"
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version:
|
187
|
+
version: '0.41'
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
|
-
- -
|
192
|
+
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version:
|
194
|
+
version: '0.41'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
|
-
name:
|
196
|
+
name: timecop
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
199
|
- - "~>"
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version: 0.
|
201
|
+
version: 0.9.5
|
202
202
|
type: :development
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
206
|
- - "~>"
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version: 0.
|
208
|
+
version: 0.9.5
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
|
-
name:
|
210
|
+
name: webmock
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
212
212
|
requirements:
|
213
|
-
- -
|
213
|
+
- - '='
|
214
214
|
- !ruby/object:Gem::Version
|
215
|
-
version:
|
215
|
+
version: 3.7.0
|
216
216
|
type: :development
|
217
217
|
prerelease: false
|
218
218
|
version_requirements: !ruby/object:Gem::Requirement
|
219
219
|
requirements:
|
220
|
-
- -
|
220
|
+
- - '='
|
221
221
|
- !ruby/object:Gem::Version
|
222
|
-
version:
|
222
|
+
version: 3.7.0
|
223
223
|
- !ruby/object:Gem::Dependency
|
224
224
|
name: activesupport
|
225
225
|
requirement: !ruby/object:Gem::Requirement
|
@@ -254,6 +254,26 @@ dependencies:
|
|
254
254
|
- - "~>"
|
255
255
|
- !ruby/object:Gem::Version
|
256
256
|
version: 0.4.1
|
257
|
+
- !ruby/object:Gem::Dependency
|
258
|
+
name: fog-google
|
259
|
+
requirement: !ruby/object:Gem::Requirement
|
260
|
+
requirements:
|
261
|
+
- - "~>"
|
262
|
+
- !ruby/object:Gem::Version
|
263
|
+
version: '1.24'
|
264
|
+
- - ">="
|
265
|
+
- !ruby/object:Gem::Version
|
266
|
+
version: 1.24.1
|
267
|
+
type: :runtime
|
268
|
+
prerelease: false
|
269
|
+
version_requirements: !ruby/object:Gem::Requirement
|
270
|
+
requirements:
|
271
|
+
- - "~>"
|
272
|
+
- !ruby/object:Gem::Version
|
273
|
+
version: '1.24'
|
274
|
+
- - ">="
|
275
|
+
- !ruby/object:Gem::Version
|
276
|
+
version: 1.24.1
|
257
277
|
- !ruby/object:Gem::Dependency
|
258
278
|
name: gitlab
|
259
279
|
requirement: !ruby/object:Gem::Requirement
|
@@ -302,26 +322,6 @@ dependencies:
|
|
302
322
|
- - "~>"
|
303
323
|
- !ruby/object:Gem::Version
|
304
324
|
version: '3.1'
|
305
|
-
- !ruby/object:Gem::Dependency
|
306
|
-
name: fog-google
|
307
|
-
requirement: !ruby/object:Gem::Requirement
|
308
|
-
requirements:
|
309
|
-
- - "~>"
|
310
|
-
- !ruby/object:Gem::Version
|
311
|
-
version: '1.24'
|
312
|
-
- - ">="
|
313
|
-
- !ruby/object:Gem::Version
|
314
|
-
version: 1.24.1
|
315
|
-
type: :runtime
|
316
|
-
prerelease: false
|
317
|
-
version_requirements: !ruby/object:Gem::Requirement
|
318
|
-
requirements:
|
319
|
-
- - "~>"
|
320
|
-
- !ruby/object:Gem::Version
|
321
|
-
version: '1.24'
|
322
|
-
- - ">="
|
323
|
-
- !ruby/object:Gem::Version
|
324
|
-
version: 1.24.1
|
325
325
|
- !ruby/object:Gem::Dependency
|
326
326
|
name: nokogiri
|
327
327
|
requirement: !ruby/object:Gem::Requirement
|
@@ -435,6 +435,7 @@ email:
|
|
435
435
|
- quality@gitlab.com
|
436
436
|
executables:
|
437
437
|
- detect-infrastructure-failures
|
438
|
+
- epic-readiness-notification
|
438
439
|
- existing-test-health-issue
|
439
440
|
- failed-test-issues
|
440
441
|
- feature-readiness-checklist
|
@@ -468,6 +469,7 @@ files:
|
|
468
469
|
- README.md
|
469
470
|
- Rakefile
|
470
471
|
- exe/detect-infrastructure-failures
|
472
|
+
- exe/epic-readiness-notification
|
471
473
|
- exe/existing-test-health-issue
|
472
474
|
- exe/failed-test-issues
|
473
475
|
- exe/feature-readiness-checklist
|
@@ -485,6 +487,7 @@ files:
|
|
485
487
|
- exe/update-test-meta
|
486
488
|
- lefthook.yml
|
487
489
|
- lib/gitlab_quality/test_tooling.rb
|
490
|
+
- lib/gitlab_quality/test_tooling/click_house/client.rb
|
488
491
|
- lib/gitlab_quality/test_tooling/concerns/find_set_dri.rb
|
489
492
|
- lib/gitlab_quality/test_tooling/failed_jobs_table.rb
|
490
493
|
- lib/gitlab_quality/test_tooling/feature_readiness/analyzed_items/analyzed_epic.rb
|
@@ -492,14 +495,17 @@ files:
|
|
492
495
|
- lib/gitlab_quality/test_tooling/feature_readiness/analyzed_items/analyzed_merge_request.rb
|
493
496
|
- lib/gitlab_quality/test_tooling/feature_readiness/concerns/issue_concern.rb
|
494
497
|
- lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb
|
498
|
+
- lib/gitlab_quality/test_tooling/feature_readiness/epic_readiness_notifier.rb
|
495
499
|
- lib/gitlab_quality/test_tooling/feature_readiness/evaluation.rb
|
496
500
|
- lib/gitlab_quality/test_tooling/feature_readiness/operational_readiness_check.rb
|
501
|
+
- lib/gitlab_quality/test_tooling/gcs_tools.rb
|
497
502
|
- lib/gitlab_quality/test_tooling/gitlab_client/branches_client.rb
|
498
503
|
- lib/gitlab_quality/test_tooling/gitlab_client/branches_dry_client.rb
|
499
504
|
- lib/gitlab_quality/test_tooling/gitlab_client/commits_client.rb
|
500
505
|
- lib/gitlab_quality/test_tooling/gitlab_client/commits_dry_client.rb
|
501
506
|
- lib/gitlab_quality/test_tooling/gitlab_client/gitlab_client.rb
|
502
507
|
- lib/gitlab_quality/test_tooling/gitlab_client/gitlab_graphql_client.rb
|
508
|
+
- lib/gitlab_quality/test_tooling/gitlab_client/group_labels_client.rb
|
503
509
|
- lib/gitlab_quality/test_tooling/gitlab_client/issues_client.rb
|
504
510
|
- lib/gitlab_quality/test_tooling/gitlab_client/issues_dry_client.rb
|
505
511
|
- lib/gitlab_quality/test_tooling/gitlab_client/job_client.rb
|
@@ -573,9 +579,6 @@ files:
|
|
573
579
|
- lib/gitlab_quality/test_tooling/test_metrics/json_test_metric_collection.rb
|
574
580
|
- lib/gitlab_quality/test_tooling/test_metrics_exporter/config.rb
|
575
581
|
- lib/gitlab_quality/test_tooling/test_metrics_exporter/formatter.rb
|
576
|
-
- lib/gitlab_quality/test_tooling/test_metrics_exporter/log_test_metrics.rb
|
577
|
-
- lib/gitlab_quality/test_tooling/test_metrics_exporter/support/gcs_tools.rb
|
578
|
-
- lib/gitlab_quality/test_tooling/test_metrics_exporter/support/influxdb_tools.rb
|
579
582
|
- lib/gitlab_quality/test_tooling/test_metrics_exporter/test_metrics.rb
|
580
583
|
- lib/gitlab_quality/test_tooling/test_result/base_test_result.rb
|
581
584
|
- lib/gitlab_quality/test_tooling/test_result/j_unit_test_result.rb
|
@@ -1,117 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module GitlabQuality
|
4
|
-
module TestTooling
|
5
|
-
module TestMetricsExporter
|
6
|
-
class LogTestMetrics
|
7
|
-
include TestMetrics
|
8
|
-
include Support::InfluxdbTools
|
9
|
-
include Support::GcsTools
|
10
|
-
|
11
|
-
CUSTOM_METRICS_KEY = :custom_test_metrics
|
12
|
-
|
13
|
-
def initialize(
|
14
|
-
examples:,
|
15
|
-
run_type: nil
|
16
|
-
)
|
17
|
-
@examples = examples
|
18
|
-
@run_type = run_type
|
19
|
-
end
|
20
|
-
|
21
|
-
def configure_influxdb_client(influxdb_url: nil, influxdb_token: nil, influxdb_bucket: nil)
|
22
|
-
@influxdb_url = influxdb_url
|
23
|
-
@influxdb_token = influxdb_token
|
24
|
-
@influxdb_bucket = influxdb_bucket
|
25
|
-
end
|
26
|
-
|
27
|
-
def configure_gcs_client(gcs_bucket: nil, gcs_project_id: nil, gcs_credentials: nil, gcs_metrics_file_name: nil)
|
28
|
-
@gcs_bucket = gcs_bucket
|
29
|
-
@gcs_project_id = gcs_project_id
|
30
|
-
@gcs_credentials = gcs_credentials
|
31
|
-
@gcs_metrics_file_name = gcs_metrics_file_name
|
32
|
-
end
|
33
|
-
|
34
|
-
# Push test execution metrics
|
35
|
-
#
|
36
|
-
# @param [Array<String>] custom_keys_tags
|
37
|
-
# @param [Array<String>] custom_keys_fields
|
38
|
-
# @return [nil]
|
39
|
-
def push_test_metrics(custom_keys_tags: nil, custom_keys_fields: nil)
|
40
|
-
@test_metrics ||= examples.filter_map { |example| parse_test_results(example, custom_keys_tags, custom_keys_fields) }
|
41
|
-
|
42
|
-
push_test_metrics_to_influxdb
|
43
|
-
push_test_metrics_to_gcs
|
44
|
-
end
|
45
|
-
|
46
|
-
# Save metrics in json file
|
47
|
-
#
|
48
|
-
# @param [String] file_name
|
49
|
-
# @param [Array<String>] custom_keys_tags
|
50
|
-
# @param [Array<String>] custom_keys_fields
|
51
|
-
# @return [nil]
|
52
|
-
def save_test_metrics(file_name:, custom_keys_tags: nil, custom_keys_fields: nil)
|
53
|
-
return Runtime::Logger.warn("No file_name provided, not saving test metrics") if file_name.nil?
|
54
|
-
|
55
|
-
@test_metrics ||= examples.filter_map { |example| parse_test_results(example, custom_keys_tags, custom_keys_fields) }
|
56
|
-
file = "tmp/#{file_name}"
|
57
|
-
|
58
|
-
File.write(file, test_metrics.to_json) && Runtime::Logger.info("Saved test metrics to #{file}")
|
59
|
-
rescue StandardError => e
|
60
|
-
Runtime::Logger.error("Failed to save test execution metrics, error: #{e}")
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
attr_reader :examples, :test_metrics, :influxdb_url, :influxdb_token, :influxdb_bucket, :run_type, :gcs_bucket,
|
66
|
-
:gcs_project_id, :gcs_credentials, :gcs_metrics_file_name
|
67
|
-
|
68
|
-
# Push test execution metrics to Influxdb
|
69
|
-
#
|
70
|
-
# @return [nil]
|
71
|
-
def push_test_metrics_to_influxdb
|
72
|
-
write_api(url: influxdb_url, token: influxdb_token, bucket: influxdb_bucket).write(data: test_metrics)
|
73
|
-
Runtime::Logger.info("Pushed #{test_metrics.length} test execution entries to Influxdb")
|
74
|
-
rescue StandardError => e
|
75
|
-
Runtime::Logger.error("Failed to push test execution metrics to Influxdb, error: #{e}")
|
76
|
-
end
|
77
|
-
|
78
|
-
# Push test execution metrics to GCS
|
79
|
-
#
|
80
|
-
# @return [nil]
|
81
|
-
def push_test_metrics_to_gcs
|
82
|
-
gcs_client(project_id: gcs_project_id, credentials: gcs_credentials)
|
83
|
-
.put_object(
|
84
|
-
gcs_bucket || raise("Missing GCS bucket name"),
|
85
|
-
gcs_metrics_file_name,
|
86
|
-
test_metrics.to_json,
|
87
|
-
force: true,
|
88
|
-
content_type: 'application/json'
|
89
|
-
)
|
90
|
-
|
91
|
-
Runtime::Logger.info("Pushed #{test_metrics.length} test execution entries to GCS")
|
92
|
-
rescue StandardError => e
|
93
|
-
Runtime::Logger.error("Failed to push test execution metrics to GCS, error: #{e}")
|
94
|
-
end
|
95
|
-
|
96
|
-
# Transform example to influxdb compatible metrics data
|
97
|
-
# https://github.com/influxdata/influxdb-client-ruby#data-format
|
98
|
-
#
|
99
|
-
# @param [RSpec::Core::Example] example
|
100
|
-
# @param [Array<String>] custom_keys_tags
|
101
|
-
# @param [Array<String>] custom_keys_fields
|
102
|
-
# @return [Hash]
|
103
|
-
def parse_test_results(example, custom_keys_tags, custom_keys_fields)
|
104
|
-
{
|
105
|
-
name: 'test-stats',
|
106
|
-
time: time,
|
107
|
-
tags: tags(example, custom_keys_tags, run_type),
|
108
|
-
fields: fields(example, custom_keys_fields)
|
109
|
-
}
|
110
|
-
rescue StandardError => e
|
111
|
-
Runtime::Logger.error("Failed to transform example '#{example.id}', error: #{e}")
|
112
|
-
nil
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|