-
Notifications
You must be signed in to change notification settings - Fork 2
/
action_stress_io.go
132 lines (121 loc) · 4.22 KB
/
action_stress_io.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
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2023 Steadybit GmbH
package extcontainer
import (
"fmt"
"github.com/steadybit/action-kit/go/action_kit_api/v2"
"github.com/steadybit/action-kit/go/action_kit_commons/runc"
"github.com/steadybit/action-kit/go/action_kit_commons/stress"
"github.com/steadybit/action-kit/go/action_kit_sdk"
"github.com/steadybit/extension-kit/extbuild"
"github.com/steadybit/extension-kit/extutil"
"time"
)
func NewStressIoContainerAction(r runc.Runc) action_kit_sdk.Action[StressActionState] {
return newStressAction(r, getStressIoDescription, stressIo)
}
type Mode string
const (
ModeReadWriteAndFlush Mode = "read_write_and_flush"
ModeReadWrite Mode = "read_write"
ModeFlush Mode = "flush"
)
func getStressIoDescription() action_kit_api.ActionDescription {
return action_kit_api.ActionDescription{
Id: fmt.Sprintf("%s.stress_io", BaseActionID),
Label: "Stress Container IO",
Description: "Stresses IO in the container using read/write/flush operations for the given duration.",
Version: extbuild.GetSemverVersionStringOrUnknown(),
Icon: extutil.Ptr(stressIOIcon),
TargetSelection: &action_kit_api.TargetSelection{
TargetType: targetID,
SelectionTemplates: &targetSelectionTemplates,
},
Category: extutil.Ptr("resource"),
Kind: action_kit_api.Attack,
TimeControl: action_kit_api.TimeControlExternal,
Parameters: []action_kit_api.ActionParameter{
{
Name: "mode",
Label: "Mode",
Description: extutil.Ptr("How should the IO be stressed?"),
Type: action_kit_api.String,
DefaultValue: extutil.Ptr(string(ModeReadWriteAndFlush)),
Required: extutil.Ptr(true),
Order: extutil.Ptr(0),
MinValue: extutil.Ptr(1),
MaxValue: extutil.Ptr(100),
Options: &[]action_kit_api.ParameterOption{
action_kit_api.ExplicitParameterOption{
Label: "read/write and flush",
Value: string(ModeReadWriteAndFlush),
},
action_kit_api.ExplicitParameterOption{
Label: "read/write only",
Value: string(ModeReadWrite),
},
action_kit_api.ExplicitParameterOption{
Label: "flush only",
Value: string(ModeFlush),
},
},
},
{
Name: "workers",
Label: "Workers",
Description: extutil.Ptr("How many workers should continually write, read and remove temporary files?"),
Type: action_kit_api.StressngWorkers,
DefaultValue: extutil.Ptr("0"),
Required: extutil.Ptr(true),
Order: extutil.Ptr(01),
},
{
Name: "duration",
Label: "Duration",
Description: extutil.Ptr("How long should IO be stressed?"),
Type: action_kit_api.Duration,
DefaultValue: extutil.Ptr("30s"),
Required: extutil.Ptr(true),
Order: extutil.Ptr(2),
},
{
Name: "path",
Label: "Path",
Description: extutil.Ptr("Path where the IO should be inflicted"),
Type: action_kit_api.String,
DefaultValue: extutil.Ptr("/"),
Required: extutil.Ptr(true),
Order: extutil.Ptr(3),
},
{
Name: "mbytes_per_worker",
Label: "MBytes to write",
Description: extutil.Ptr("How many megabytes should be written per stress operation?"),
Type: action_kit_api.Integer,
DefaultValue: extutil.Ptr("1024"),
Required: extutil.Ptr(true),
Order: extutil.Ptr(3),
MinValue: extutil.Ptr(1),
},
},
}
}
func stressIo(request action_kit_api.PrepareActionRequestBody) (stress.Opts, error) {
workers := extutil.ToInt(request.Config["workers"])
mode := extutil.ToString(request.Config["mode"])
if mode == "" {
mode = string(ModeReadWriteAndFlush)
}
opts := stress.Opts{
TempPath: extutil.ToString(request.Config["path"]),
Timeout: time.Duration(extutil.ToInt64(request.Config["duration"])) * time.Millisecond,
}
if mode == string(ModeReadWriteAndFlush) || mode == string(ModeReadWrite) {
opts.HddWorkers = &workers
opts.HddBytes = fmt.Sprintf("%dm", extutil.ToInt64(request.Config["mbytes_per_worker"]))
}
if mode == string(ModeReadWriteAndFlush) || mode == string(ModeFlush) {
opts.IoWorkers = &workers
}
return opts, nil
}