-
Notifications
You must be signed in to change notification settings - Fork 31
/
settings.go
308 lines (284 loc) · 13.3 KB
/
settings.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
package storage
import (
"strconv"
"github.com/dynatrace-oss/terraform-provider-dynatrace/terraform/hcl"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/cluster/v2/envs/storage/retention"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
// Settings represents environment level storage usage and limit information. Not returned if includeStorageInfo param is not true. If skipped when editing via PUT method then already set limits will remain
type Settings struct {
TransactionTrafficQuota *TransactionTrafficQuota `json:"transactionTrafficQuota"` // Maximum number of newly monitored entry point PurePaths captured per process/minute on environment level. Can be set to any value from 100 to 100000. If skipped when editing via PUT method then already set limit will remain
UserActionsPerMinute *UserActionsPerMinute `json:"userActionsPerMinute"` // Maximum number of user actions generated per minute on environment level. Can be set to any value from 1 to 2147483646 or left unlimited. If skipped when editing via PUT method then already set limit will remain
Transactions *Transactions `json:"transactionStorage"` // Transaction storage usage and limit information on environment level. If skipped when editing via PUT method then already set limit will remain
SessionReplayStorage *SessionReplayStorage `json:"sessionReplayStorage"` // Session replay storage usage and limit information on environment level. If skipped when editing via PUT method then already set limit will remain
SymbolFilesFromMobileApps *SymbolFilesFromMobileApps `json:"symbolFilesFromMobileApps"` // Symbol files from mobile apps storage usage and limit information on environment level. If skipped when editing via PUT method then already set limit will remain
LogMonitoringStorage *LogMonitoringStorage `json:"logMonitoringStorage,omitempty"` // Log monitoring storage usage and limit information on environment level. Not editable when Log monitoring is not allowed by license or not configured on cluster level. If skipped when editing via PUT method then already set limit will remain
ServiceRequestLevelRetention *retention.ServiceRequestLevel `json:"serviceRequestLevelRetention,omitempty"` // Service request level retention settings on environment level. Service code level retention time can't be greater than service request level retention time and both can't exceed one year.If skipped when editing via PUT method then already set limit will remain
ServiceCodeLevelRetention *retention.ServiceCodeLevel `json:"serviceCodeLevelRetention,omitempty"` // Service code level retention settings on environment level. Service code level retention time can't be greater than service request level retention time and both can't exceed one year.If skipped when editing via PUT method then already set limit will remain
RealUserMonitoringRetention *retention.RealUserMonitoring `json:"realUserMonitoringRetention,omitempty"` // Real user monitoring retention settings on environment level. Can be set to any value from 1 to 35 days. If skipped when editing via PUT method then already set limit will remain
SyntheticMonitoringRetention *retention.SyntheticMonitoring `json:"syntheticMonitoringRetention,omitempty"` // Synthetic monitoring retention settings on environment level. Can be set to any value from 1 to 35 days. If skipped when editing via PUT method then already set limit will remain
SessionReplayRetention *retention.SessionReplay `json:"sessionReplayRetention,omitempty"` // Session replay retention settings on environment level. Can be set to any value from 1 to 35 days. If skipped when editing via PUT method then already set limit will remain
LogMonitoringRetention *retention.LogMonitoring `json:"logMonitoringRetention,omitempty"` // Log monitoring retention settings on environment level. Not editable when Log monitoring is not allowed by license or not configured on cluster level. Can be set to any value from 5 to 90 days. If skipped when editing via PUT method then already set limit will remain
}
type limits struct {
Transactions *int64
SessionReplay *int64
SymbolFiles *int64
Logs *int64
}
func (me *limits) IsEmpty() bool {
return me == nil || (me.Transactions == nil && me.SessionReplay == nil && me.SymbolFiles == nil && me.Logs == nil)
}
func (me *limits) Schema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"transactions": {
Type: schema.TypeInt,
Optional: true,
Description: "Transaction storage usage and limit information on environment level in bytes. 0 for unlimited.",
},
"session_replay": {
Type: schema.TypeInt,
Optional: true,
Description: "Session replay storage usage and limit information on environment level in bytes. 0 for unlimited.",
},
"symbol_files": {
Type: schema.TypeInt,
Optional: true,
Description: "Session replay storage usage and limit information on environment level in bytes. 0 for unlimited.",
},
"logs": {
Type: schema.TypeInt,
Optional: true,
Description: "Log monitoring storage usage and limit information on environment level in bytes. Not editable when Log monitoring is not allowed by license or not configured on cluster level. 0 for unlimited.",
}}
}
func (me *limits) MarshalHCL(properties hcl.Properties) error {
if err := properties.Encode("transactions", me.Transactions); err != nil {
return err
}
if err := properties.Encode("session_replay", me.SessionReplay); err != nil {
return err
}
if err := properties.Encode("symbol_files", me.SymbolFiles); err != nil {
return err
}
if err := properties.Encode("logs", me.Logs); err != nil {
return err
}
return nil
}
func (me *limits) UnmarshalHCL(decoder hcl.Decoder) error {
return decoder.DecodeAll(map[string]any{
"transactions": &me.Transactions,
"session_replay": &me.SessionReplay,
"symbol_files": &me.SymbolFiles,
"logs": &me.Logs,
})
}
type retent struct {
ServiceRequestLevel *int64
ServiceCodeLevel *int64
RUM *int64
Synthetic *int64
SessionReplay *int64
Logs *int64
}
func (me *retent) Schema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"service_request_level": {
Type: schema.TypeInt,
Required: true,
Description: "Service request level retention settings on environment level in days. Service code level retention time can't be greater than service request level retention time and both can't exceed one year",
},
"service_code_level": {
Type: schema.TypeInt,
Required: true,
Description: "Service code level retention settings on environment level in days. Service code level retention time can't be greater than service request level retention time and both can't exceed one year",
},
"rum": {
Type: schema.TypeInt,
Required: true,
Description: "Real user monitoring retention settings on environment level in days. Can be set to any value from 1 to 35 days",
},
"synthetic": {
Type: schema.TypeInt,
Required: true,
Description: "Synthetic monitoring retention settings on environment level in days. Can be set to any value from 1 to 35 days",
},
"session_replay": {
Type: schema.TypeInt,
Required: true,
Description: "Session replay retention settings on environment level in days. Can be set to any value from 1 to 35 days",
},
"logs": {
Type: schema.TypeInt,
Optional: true,
Description: "Log monitoring retention settings on environment level in days. Not editable when Log monitoring is not allowed by license or not configured on cluster level. Can be set to any value from 5 to 90 days",
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
iOldValue, err := strconv.Atoi(oldValue)
if err != nil {
return false
}
iNewValue, err := strconv.Atoi(newValue)
if err != nil {
return false
}
return iOldValue == 35 && iNewValue == 0
},
}}
}
func (me *retent) MarshalHCL(properties hcl.Properties) error {
if me.ServiceCodeLevel != nil && *me.ServiceCodeLevel != 0 {
if err := properties.Encode("service_code_level", me.ServiceCodeLevel); err != nil {
return err
}
}
if me.ServiceRequestLevel != nil && *me.ServiceRequestLevel != 0 {
if err := properties.Encode("service_request_level", me.ServiceRequestLevel); err != nil {
return err
}
}
if me.RUM != nil && *me.RUM != 0 {
if err := properties.Encode("rum", me.RUM); err != nil {
return err
}
}
if me.Synthetic != nil && *me.Synthetic != 0 {
if err := properties.Encode("synthetic", me.Synthetic); err != nil {
return err
}
}
if me.SessionReplay != nil && *me.SessionReplay != 0 {
if err := properties.Encode("session_replay", me.SessionReplay); err != nil {
return err
}
}
if me.Logs != nil && *me.Logs != 0 {
if err := properties.Encode("logs", me.Logs); err != nil {
return err
}
}
return nil
}
func (me *retent) UnmarshalHCL(decoder hcl.Decoder) error {
return decoder.DecodeAll(map[string]any{
"service_request_level": &me.ServiceRequestLevel,
"service_code_level": &me.ServiceCodeLevel,
"rum": &me.RUM,
"synthetic": &me.Synthetic,
"session_replay": &me.SessionReplay,
"logs": &me.Logs,
})
}
func (me *Settings) Schema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"user_actions": {
Type: schema.TypeInt,
Optional: true,
Description: "Maximum number of user actions generated per minute on environment level. Can be set to any value from 1 to 2147483646 or left unlimited by omitting this property",
},
"transactions": {
Type: schema.TypeInt,
Required: true,
Description: "Maximum number of newly monitored entry point PurePaths captured per process/minute on environment level. Can be set to any value from 100 to 100000",
},
"limits": {
Type: schema.TypeList,
Optional: true,
MinItems: 1,
MaxItems: 1,
Elem: &schema.Resource{Schema: new(limits).Schema()},
},
"retention": {
Type: schema.TypeList,
Optional: true,
MinItems: 1,
MaxItems: 1,
Elem: &schema.Resource{Schema: new(retent).Schema()},
},
}
}
func (me *Settings) MarshalHCL(properties hcl.Properties) error {
if !me.UserActionsPerMinute.IsEmpty() {
if err := properties.Encode("user_actions", me.UserActionsPerMinute.MaxLimit); err != nil {
return err
}
}
if !me.TransactionTrafficQuota.IsEmpty() {
if err := properties.Encode("transactions", me.TransactionTrafficQuota.MaxLimit); err != nil {
return err
}
}
vLimits := new(limits)
if !me.Transactions.IsEmpty() {
vLimits.Transactions = me.Transactions.MaxLimit
}
if !me.SessionReplayStorage.IsEmpty() {
vLimits.SessionReplay = me.SessionReplayStorage.MaxLimit
}
if !me.SymbolFilesFromMobileApps.IsEmpty() {
vLimits.SymbolFiles = me.SymbolFilesFromMobileApps.MaxLimit
}
if !me.LogMonitoringStorage.IsEmpty() {
vLimits.Logs = me.LogMonitoringStorage.MaxLimit
}
if !vLimits.IsEmpty() {
if err := properties.Encode("limits", vLimits); err != nil {
return err
}
}
if err := properties.Encode("retention", &retent{
Logs: &me.LogMonitoringRetention.MaxLimitInDays,
SessionReplay: &me.SessionReplayRetention.MaxLimitInDays,
ServiceCodeLevel: &me.ServiceCodeLevelRetention.MaxLimitInDays,
ServiceRequestLevel: &me.ServiceRequestLevelRetention.MaxLimitInDays,
RUM: &me.RealUserMonitoringRetention.MaxLimitInDays,
Synthetic: &me.SyntheticMonitoringRetention.MaxLimitInDays,
}); err != nil {
return err
}
return nil
}
func (me *Settings) UnmarshalHCL(decoder hcl.Decoder) error {
me.UserActionsPerMinute = new(UserActionsPerMinute)
if err := decoder.Decode("user_actions", &me.UserActionsPerMinute.MaxLimit); err != nil {
return err
}
me.TransactionTrafficQuota = new(TransactionTrafficQuota)
if err := decoder.Decode("transactions", &me.TransactionTrafficQuota.MaxLimit); err != nil {
return err
}
vLimits := new(limits)
if err := decoder.Decode("limits", &vLimits); err != nil {
return err
}
me.Transactions = &Transactions{MaxLimit: vLimits.Transactions}
me.SessionReplayStorage = &SessionReplayStorage{MaxLimit: vLimits.SessionReplay}
me.SymbolFilesFromMobileApps = &SymbolFilesFromMobileApps{MaxLimit: vLimits.SymbolFiles}
if vLimits.Logs != nil {
me.LogMonitoringStorage = &LogMonitoringStorage{MaxLimit: vLimits.Logs}
}
ret := new(retent)
if err := decoder.Decode("retention", &ret); err != nil {
return err
}
if ret.Logs != nil {
me.LogMonitoringRetention = &retention.LogMonitoring{MaxLimitInDays: *ret.Logs}
}
if ret.ServiceCodeLevel != nil {
me.SessionReplayRetention = &retention.SessionReplay{MaxLimitInDays: *ret.SessionReplay}
}
if ret.Synthetic != nil {
me.SyntheticMonitoringRetention = &retention.SyntheticMonitoring{MaxLimitInDays: *ret.Synthetic}
}
if ret.RUM != nil {
me.RealUserMonitoringRetention = &retention.RealUserMonitoring{MaxLimitInDays: *ret.RUM}
}
if ret.ServiceCodeLevel != nil {
me.ServiceCodeLevelRetention = &retention.ServiceCodeLevel{MaxLimitInDays: *ret.ServiceCodeLevel}
}
if ret.ServiceRequestLevel != nil {
me.ServiceRequestLevelRetention = &retention.ServiceRequestLevel{MaxLimitInDays: *ret.ServiceRequestLevel}
}
return nil
}