/
objects.go
376 lines (275 loc) · 8.68 KB
/
objects.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
package metrics
import (
"regexp"
"time"
"github.com/Masterminds/semver/v3"
)
// AllJobs represents a regex that will collect results from all jobs.
var AllJobs = regexp.MustCompile(".*")
// Phase is a phase of an osde2e run.
type Phase string
// Result is the result of a JUnit test.
type Result string
const (
// Install phase represents tests that were run after the initial installation of the cluster.
Install Phase = "install"
// Upgrade phase represents tests that were run after the upgrade of the cluster.
Upgrade Phase = "upgrade"
// UnknownPhase represents tests that were run in a phase that is currently unknown to the metrics library.
UnknownPhase Phase = "unknown"
// Passed result represents a JUnitResult that passed acceptably.
Passed Result = "passed"
// Failed result represents a JUnitResult that failed.
Failed Result = "failed"
// Skipped result represents a JUnitResult that was skipped during a run.
Skipped Result = "skipped"
// UnknownResult represents a JUnitResult that is currently unknown to the metrics library.
UnknownResult Result = "unknown"
)
// Event objects that are recorded by osde2e runs. These typically represent occurrences that are of
// some note. For example, cluste provisioning failure, failure to collect Hive logs, etc.
type Event struct {
// InstallVersion is the starting install version of the cluster that generated this event.
InstallVersion *semver.Version
// UpgradeVersion is the upgrade version of the cluster that generated this event. This can be nil.
UpgradeVersion *semver.Version
// CloudProvider is the cluster cloud provider that was used when this event was generated.
CloudProvider string
// Environment is the environment that the cluster provider was using during the generation of this event.
Environment string
// Event is the name of the event that was recorded.
Event string
// ClusterID is the cluster ID of the cluster that was provisioned while generating this event.
ClusterID string
// JobName is the name of the job that generated this event.
JobName string
// JobID is the job ID number that corresponds to the job that generated this event.
JobID int64
// Timestamp is the time when this event was recorded.
Timestamp int64
}
// Equal will return true if two event objects are equal.
func (e Event) Equal(that Event) bool {
if !versionsEqual(e.InstallVersion, that.InstallVersion) {
return false
}
if !versionsEqual(e.UpgradeVersion, that.UpgradeVersion) {
return false
}
if e.CloudProvider != that.CloudProvider {
return false
}
if e.Environment != that.Environment {
return false
}
if e.Event != that.Event {
return false
}
if e.ClusterID != that.ClusterID {
return false
}
if e.JobName != that.JobName {
return false
}
if e.JobID != that.JobID {
return false
}
if e.Timestamp != that.Timestamp {
return false
}
return true
}
// Events is a list of events.
type Events []Event
func (e Events) Len() int {
return len(e)
}
func (e Events) Swap(i, j int) {
e[i], e[j] = e[j], e[i]
}
func (e Events) Less(i, k int) bool {
return e[i].Timestamp < e[k].Timestamp
}
// Metadata objects are numerical values associated with metadata calculated by osde2e.
type Metadata struct {
// InstallVersion is the starting install version of the cluster that generated this metadata.
InstallVersion *semver.Version
// UpgradeVersion is the upgrade version of the cluster that generated this metadata. This can be nil.
UpgradeVersion *semver.Version
// CloudProvider is the cluster cloud provider that was used when this metadata was generated.
CloudProvider string
// Environment is the environment that the cluster provider was using during the generation of this metadata.
Environment string
// MetadataName is the name of the metadata that was recorded.
MetadataName string
// ClusterID is the cluster ID of the cluster that was provisioned while generating this metadata.
ClusterID string
// JobName is the name of the job that generated this metadata.
JobName string
// JobID is the job ID number that corresponds to the job that generated this metadata.
JobID int64
// Value is the numerical value associated with this metadata.
Value float64
// Time is the time when this metadata was recorded.
Timestamp int64
}
// Equal will return true if two metadata objects are equal.
func (m Metadata) Equal(that Metadata) bool {
if !versionsEqual(m.InstallVersion, that.InstallVersion) {
return false
}
if !versionsEqual(m.UpgradeVersion, that.UpgradeVersion) {
return false
}
if m.CloudProvider != that.CloudProvider {
return false
}
if m.Environment != that.Environment {
return false
}
if m.MetadataName != that.MetadataName {
return false
}
if m.ClusterID != that.ClusterID {
return false
}
if m.JobName != that.JobName {
return false
}
if m.JobID != that.JobID {
return false
}
if m.Value != that.Value {
return false
}
if m.Timestamp != that.Timestamp {
return false
}
return true
}
// Metadatas is a list of metadata objects.
type Metadatas []Metadata
func (m Metadatas) Len() int {
return len(m)
}
func (m Metadatas) Swap(i, j int) {
m[i], m[j] = m[j], m[i]
}
func (m Metadatas) Less(i, k int) bool {
return m[i].Timestamp < m[k].Timestamp
}
// AddonMetadata is numerical data captured by osde2e runs, similar to Metadata. However, this is customizable and
// focused on addon testing.
type AddonMetadata struct {
Metadata
// Phase is the test phase where this this metadata was generated in.
Phase Phase
}
// Equal will return true if two addon metadata objects are equal.
func (a AddonMetadata) Equal(that AddonMetadata) bool {
if !a.Metadata.Equal(that.Metadata) {
return false
}
if a.Phase != that.Phase {
return false
}
return true
}
// AddonMetadatas is a list of addon metadata objects.
type AddonMetadatas []AddonMetadata
func (a AddonMetadatas) Len() int {
return len(a)
}
func (a AddonMetadatas) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a AddonMetadatas) Less(i, k int) bool {
return a[i].Timestamp < a[k].Timestamp
}
// JUnitResult represents an individual test that was run over the course of an osde2e run.
type JUnitResult struct {
// InstallVersion is the starting install version of the cluster that generated this result.
InstallVersion *semver.Version
// UpgradeVersion is the upgrade version of the cluster that generated this result. This can be nil.
UpgradeVersion *semver.Version
// CloudProvider is the cluster cloud provider that was used when this result was generated.
CloudProvider string
// Environment is the environment that the cluster provider was using during the generation of this result.
Environment string
// Suite is the name of the test suite that this test belongs to.
Suite string
// TestName is the name of the test that was run.
TestName string
// Result is the result of this test.
Result Result
// ClusterID is the cluster ID of the cluster that was provisioned while generating this result.
ClusterID string
// JobName is the name of the job that generated this result.
JobName string
// JobID is the job ID number that corresponds to the job that generated this result.
JobID int64
// Phase is the test phase where this this result was generated in.
Phase Phase
// Duration is the length of time that this test took to run.
Duration time.Duration
// Timestamp is the timestamp when this result was recorded.
Timestamp int64
}
// Equal will return true if two JUnitResult objects are equal.
func (j JUnitResult) Equal(that JUnitResult) bool {
if !versionsEqual(j.InstallVersion, that.InstallVersion) {
return false
}
if !versionsEqual(j.UpgradeVersion, that.UpgradeVersion) {
return false
}
if j.CloudProvider != that.CloudProvider {
return false
}
if j.Environment != that.Environment {
return false
}
if j.Suite != that.Suite {
return false
}
if j.TestName != that.TestName {
return false
}
if j.Result != that.Result {
return false
}
if j.ClusterID != that.ClusterID {
return false
}
if j.JobName != that.JobName {
return false
}
if j.JobID != that.JobID {
return false
}
if j.Phase != that.Phase {
return false
}
if j.Duration != that.Duration {
return false
}
if j.Timestamp != that.Timestamp {
return false
}
return true
}
// JUnitResults is a list of JUnitResults.
type JUnitResults []JUnitResult
func (jr JUnitResults) Len() int {
return len(jr)
}
func (jr JUnitResults) Swap(i, j int) {
jr[i], jr[j] = jr[j], jr[i]
}
func (jr JUnitResults) Less(i, k int) bool {
return jr[i].Timestamp < jr[k].Timestamp
}
// nil safe semver equivalency
func versionsEqual(version1, version2 *semver.Version) bool {
return (version1 == nil && version1 == version2) || (version1 != nil && version2 != nil && version1.Equal(version2))
}