-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.go
115 lines (106 loc) · 3.25 KB
/
benchmark.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
package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
"entgo.io/ent/schema/mixin"
"github.com/nikoksr/dbench/ent/schema/datetime"
"github.com/nikoksr/dbench/ent/schema/pulid"
)
// Benchmark struct extends ent.Schema to describe the Benchmark database table.
type Benchmark struct {
ent.Schema
}
// BenchmarkMixin is a struct with embedded mixin.Schema (a predefined structure)
type BenchmarkMixin struct {
mixin.Schema
}
// Fields method defines the fields within the Benchmark database table.
func (BenchmarkMixin) Fields() []ent.Field {
return []ent.Field{
// The group this benchmark belongs to.
field.String("group_id").
GoType(pulid.ID("")).
Immutable(),
// An optional comment for the benchmark.
field.String("comment").
Optional().
Nillable(),
// Remaining fields are optional and cannot be changed once set.
field.String("version").
Optional().
Immutable(),
field.String("command").
Optional().
Immutable(),
field.String("transaction_type").
Optional().
Immutable(),
field.Float("scaling_factor").
Optional().
Immutable(),
field.String("query_mode").
Optional().
Immutable(),
field.Int("clients").
Optional().
Immutable(),
field.Int("threads").
Optional().
Immutable(),
field.Time("recorded_at").
Default(datetime.NowUTC).
Immutable(),
}
}
// Mixin function defines the mixins to be incorporated into the Benchmark schema.
func (Benchmark) Mixin() []ent.Mixin {
return []ent.Mixin{
// Primary key using PULIDs
pulid.NewMixinWithPrefix("id", "bmk"),
// The Benchmark itself
BenchmarkMixin{},
// CreatedAt and UpdatedAt timestamps
datetime.NewMixin(),
}
}
// Edges function defines the relations/edges of the Benchmark schema.
func (Benchmark) Edges() []ent.Edge {
return []ent.Edge{
edge.To("result", BenchmarkResult.Type).
Unique().
Annotations(entsql.OnDelete(entsql.Cascade)).
Comment("The result produced by the benchmark run."),
edge.To("system_metric", SystemMetric.Type).
Unique().
Annotations(entsql.OnDelete(entsql.Cascade)).
Comment("The metrics that we collected from the system during the benchmark run."),
edge.To("system", SystemConfig.Type).
Unique().
Annotations(entsql.OnDelete(entsql.Cascade)).
Comment("The system config that was used for the benchmark run."),
}
}
// Indexes function defines the indexed fields for faster queries on the Benchmark schema.
func (Benchmark) Indexes() []ent.Index {
return []ent.Index{
// Index group id and id for faster sorting of default queries.
index.Fields("group_id", "id"),
// Index group id for faster sorting of default queries.
index.Fields("group_id"),
// Index clients for faster sorting of default queries.
index.Fields("clients"),
// RecordedAt index for faster sorting of default queries.
index.Fields("recorded_at"),
}
}
// Annotations function adds annotations to the Benchmark schema.
func (Benchmark) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.WithComments(true),
schema.Comment("Benchmarks are the main entity of this application. They represent a single pgbench run. This table stores the config of the run."),
}
}