/
config.go
174 lines (153 loc) · 6.8 KB
/
config.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
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package loadtest
import (
"errors"
"math"
"github.com/mattermost/mattermost-load-test-ng/defaults"
"github.com/mattermost/mattermost-load-test-ng/logger"
)
// ConnectionConfiguration holds information needed to connect to the instance.
type ConnectionConfiguration struct {
// URL of the instance to connect to.
ServerURL string `default:"http://localhost:8065" validate:"url"`
// WebSocket URL of the instance to connect to.
WebSocketURL string `default:"ws://localhost:8065" validate:"url"`
// Email of the system admin.
AdminEmail string `default:"sysadmin@sample.mattermost.com" validate:"email"`
// Password of the system admin.
AdminPassword string `default:"Sys@dmin-sample1" validate:"notempty"`
}
// userControllerType describes the type of a UserController.
type userControllerType string
// Available UserController implementations.
const (
UserControllerSimple userControllerType = "simple"
UserControllerSimulative = "simulative"
UserControllerNoop = "noop"
UserControllerGenerative = "generative"
UserControllerCluster = "cluster"
)
// RatesDistribution maps a rate to a percentage of controllers that should run
// at that rate.
type RatesDistribution struct {
Rate float64 `default:"1.0" validate:"range:[0,)"`
Percentage float64 `default:"1.0" validate:"range:[0,1]"`
}
// UserControllerConfiguration holds information about the UserController to
// run during a load-test.
type UserControllerConfiguration struct {
// The type of the UserController to run.
// Possible values:
// UserControllerSimple - A simple version of a controller.
// UserControllerSimulative - A more realistic controller.
// UserControllerNoop
// UserControllerGenerative - A controller used to generate data.
Type userControllerType `default:"simulative" validate:"oneof:{simple,simulative,noop,cluster,generative}"`
// A distribution of rate multipliers that will affect the speed at which user actions are
// executed by the UserController.
// A Rate of < 1.0 will run actions at a faster pace.
// A Rate of 1.0 will run actions at the default pace.
// A Rate > 1.0 will run actions at a slower pace.
RatesDistribution []RatesDistribution `default_len:"1"`
// An optional MM server version to use when running actions (e.g. `5.30.0`).
// This value overrides the actual server version. If left empty,
// the one returned by the server is used instead.
ServerVersion string
}
// IsValid reports whether a given UserControllerConfiguration is valid or not.
// Returns an error if the validation fails.
func (ucc *UserControllerConfiguration) IsValid() error {
var sum float64
for _, el := range ucc.RatesDistribution {
sum += el.Percentage
}
if len(ucc.RatesDistribution) > 0 && sum != 1 {
return errors.New("Percentages in RatesDistribution should sum to 1")
}
return nil
}
// InstanceConfiguration holds information about the data to be populated
// during the init process.
type InstanceConfiguration struct {
// The target number of teams to be created.
NumTeams int64 `default:"2" validate:"range:[0,]"`
// The target number of channels to be created.
NumChannels int64 `default:"10" validate:"range:[0,]"`
// The target number of posts to be created.
NumPosts int64 `default:"0" validate:"range:[0,]"`
// The target number of reactions to be created.
NumReactions int64 `default:"0" validate:"range:[0,]"`
// The target number of admin users to be created.
NumAdmins int64 `default:"0" validate:"range:[0,]"`
// The percentage of replies to be created.
PercentReplies float64 `default:"0.5" validate:"range:[0,1]"`
// The percentage of replies that should be in long threads
PercentRepliesInLongThreads float64 `default:"0.05" validate:"range:[0,1]"`
// The percentage of post that are marked as urgent
PercentUrgentPosts float64 `default:"0.001" validate:"range:[0,1]"`
// Percentages of channels to be created, grouped by type.
// The total sum of these values must be equal to 1.
// The percentage of public channels to be created.
PercentPublicChannels float64 `default:"0.2" validate:"range:[0,1]"`
// The percentage of private channels to be created.
PercentPrivateChannels float64 `default:"0.1" validate:"range:[0,1]"`
// The percentage of direct channels to be created.
PercentDirectChannels float64 `default:"0.6" validate:"range:[0,1]"`
// The percentage of group channels to be created.
PercentGroupChannels float64 `default:"0.1" validate:"range:[0,1]"`
}
// IsValid reports whether a given InstanceConfiguration is valid or not.
// Returns an error if the validation fails.
func (c *InstanceConfiguration) IsValid() error {
percentChannels := c.PercentPublicChannels + c.PercentPrivateChannels + c.PercentDirectChannels + c.PercentGroupChannels
if (math.Round(percentChannels*100) / 100) != 1 {
return errors.New("sum of percentages for channels should be equal to 1")
}
return nil
}
// UsersConfiguration holds information about the users of the load-test.
type UsersConfiguration struct {
// The file which contains the user emails and passwords in case the operator
// wants to login using a different set of credentials. This is helpful during
// LDAP logins.
UsersFilePath string
// The number of initial users the load-test should start with.
InitialActiveUsers int `default:"0" validate:"range:[0,$MaxActiveUsers]"`
// The maximum number of users that can be simulated by a single load-test
// agent.
MaxActiveUsers int `default:"2000" validate:"range:(0,]"`
// The average number of sessions per user.
AvgSessionsPerUser int `default:"1" validate:"range:[1,]"`
// The percentage of users generated that will be system admins
PercentOfUsersAreAdmin float64 `default:"0.0005" validate:"range:[0,1]"`
}
// Config holds information needed to create and initialize a new load-test
// agent.
type Config struct {
ConnectionConfiguration ConnectionConfiguration
UserControllerConfiguration UserControllerConfiguration
InstanceConfiguration InstanceConfiguration
UsersConfiguration UsersConfiguration
LogSettings logger.Settings
}
// IsValid reports whether a given Config is valid or not.
// Returns an error if the validation fails.
func (c *Config) IsValid() error {
if err := c.UserControllerConfiguration.IsValid(); err != nil {
return err
}
if err := c.InstanceConfiguration.IsValid(); err != nil {
return err
}
return nil
}
// ReadConfig reads the configuration file from the given string. If the string
// is empty, it will return a config with default values.
func ReadConfig(configFilePath string) (*Config, error) {
var cfg Config
if err := defaults.ReadFromJSON(configFilePath, "./config/config.json", &cfg); err != nil {
return nil, err
}
return &cfg, nil
}