Use operationCode instead of string directly

Signed-off-by: kerthcet <kerthcet@gmail.com>
This commit is contained in:
kerthcet 2022-11-01 17:01:22 +08:00
parent 36dd5f2846
commit 21e8a69a22

View File

@ -52,17 +52,19 @@ import (
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
const ( type operationCode string
configFile = "config/performance-config.yaml"
createNodesOpcode = "createNodes"
createNamespacesOpcode = "createNamespaces"
createPodsOpcode = "createPods"
createPodSetsOpcode = "createPodSets"
churnOpcode = "churn"
barrierOpcode = "barrier"
sleepOpcode = "sleep"
extensionPointsLabelName = "extension_point"
const (
createNodesOpcode operationCode = "createNodes"
createNamespacesOpcode operationCode = "createNamespaces"
createPodsOpcode operationCode = "createPods"
createPodSetsOpcode operationCode = "createPodSets"
churnOpcode operationCode = "churn"
barrierOpcode operationCode = "barrier"
sleepOpcode operationCode = "sleep"
)
const (
// Two modes supported in "churn" operator. // Two modes supported in "churn" operator.
// Recreate creates a number of API objects and then delete them, and repeat the iteration. // Recreate creates a number of API objects and then delete them, and repeat the iteration.
@ -71,6 +73,11 @@ const (
Create = "create" Create = "create"
) )
const (
configFile = "config/performance-config.yaml"
extensionPointsLabelName = "extension_point"
)
var ( var (
defaultMetricsCollectorConfig = metricsCollectorConfig{ defaultMetricsCollectorConfig = metricsCollectorConfig{
Metrics: map[string]*labelValues{ Metrics: map[string]*labelValues{
@ -253,7 +260,7 @@ func isValidParameterizable(val string) bool {
// createNodesOp defines an op where nodes are created as a part of a workload. // createNodesOp defines an op where nodes are created as a part of a workload.
type createNodesOp struct { type createNodesOp struct {
// Must be "createNodes". // Must be "createNodes".
Opcode string Opcode operationCode
// Number of nodes to create. Parameterizable through CountParam. // Number of nodes to create. Parameterizable through CountParam.
Count int Count int
// Template parameter for Count. // Template parameter for Count.
@ -297,7 +304,7 @@ func (cno createNodesOp) patchParams(w *workload) (realOp, error) {
// createNamespacesOp defines an op for creating namespaces // createNamespacesOp defines an op for creating namespaces
type createNamespacesOp struct { type createNamespacesOp struct {
// Must be "createNamespaces". // Must be "createNamespaces".
Opcode string Opcode operationCode
// Name prefix of the Namespace. The format is "<prefix>-<number>", where number is // Name prefix of the Namespace. The format is "<prefix>-<number>", where number is
// between 0 and count-1. // between 0 and count-1.
Prefix string Prefix string
@ -341,7 +348,7 @@ func (cmo createNamespacesOp) patchParams(w *workload) (realOp, error) {
// continue asynchronously. // continue asynchronously.
type createPodsOp struct { type createPodsOp struct {
// Must be "createPods". // Must be "createPods".
Opcode string Opcode operationCode
// Number of pods to schedule. Parameterizable through CountParam. // Number of pods to schedule. Parameterizable through CountParam.
Count int Count int
// Template parameter for Count. // Template parameter for Count.
@ -400,7 +407,7 @@ func (cpo createPodsOp) patchParams(w *workload) (realOp, error) {
// createPodSetsOp defines an op where a set of createPodsOp is created each in a unique namespace. // createPodSetsOp defines an op where a set of createPodsOp is created each in a unique namespace.
type createPodSetsOp struct { type createPodSetsOp struct {
// Must be "createPodSets". // Must be "createPodSets".
Opcode string Opcode operationCode
// Number of sets to create. // Number of sets to create.
Count int Count int
// Template parameter for Count. // Template parameter for Count.
@ -442,7 +449,7 @@ func (cpso createPodSetsOp) patchParams(w *workload) (realOp, error) {
// churnOp defines an op where services are created as a part of a workload. // churnOp defines an op where services are created as a part of a workload.
type churnOp struct { type churnOp struct {
// Must be "churnOp". // Must be "churnOp".
Opcode string Opcode operationCode
// Value must be one of the followings: // Value must be one of the followings:
// - recreate. In this mode, API objects will be created for N cycles, and then // - recreate. In this mode, API objects will be created for N cycles, and then
// deleted in the next N cycles. N is specified by the "Number" field. // deleted in the next N cycles. N is specified by the "Number" field.
@ -493,7 +500,7 @@ func (co churnOp) patchParams(w *workload) (realOp, error) {
// were scheduled with SkipWaitToCompletion set to true. // were scheduled with SkipWaitToCompletion set to true.
type barrierOp struct { type barrierOp struct {
// Must be "barrier". // Must be "barrier".
Opcode string Opcode operationCode
// Namespaces to block on. Empty array or not specifying this field signifies // Namespaces to block on. Empty array or not specifying this field signifies
// that the barrier should block on all namespaces. // that the barrier should block on all namespaces.
Namespaces []string Namespaces []string
@ -518,14 +525,14 @@ func (bo barrierOp) patchParams(w *workload) (realOp, error) {
// This is useful in simulating workloads that require some sort of time-based synchronisation. // This is useful in simulating workloads that require some sort of time-based synchronisation.
type sleepOp struct { type sleepOp struct {
// Must be "sleep". // Must be "sleep".
Opcode string Opcode operationCode
// duration of sleep. // duration of sleep.
Duration time.Duration Duration time.Duration
} }
func (so *sleepOp) UnmarshalJSON(data []byte) (err error) { func (so *sleepOp) UnmarshalJSON(data []byte) (err error) {
var tmp struct { var tmp struct {
Opcode string Opcode operationCode
Duration string Duration string
} }
if err = json.Unmarshal(data, &tmp); err != nil { if err = json.Unmarshal(data, &tmp); err != nil {