k8s.io/perf-tests/clusterloader2@v0.0.0-20240304094227-64bdb12da87e/pkg/tuningset/simple_tuning_set_factory.go (about) 1 /* 2 Copyright 2018 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package tuningset 18 19 import ( 20 "fmt" 21 22 "k8s.io/perf-tests/clusterloader2/api" 23 ) 24 25 type simpleFactory struct { 26 tuningSetMap map[string]*api.TuningSet 27 globalQPSLoadFactory *globalQPSLoadFactory 28 } 29 30 // NewFactory creates new ticker factory. 31 func NewFactory() Factory { 32 return &simpleFactory{ 33 tuningSetMap: make(map[string]*api.TuningSet), 34 globalQPSLoadFactory: newGlobalQPSLoadFactory(), 35 } 36 } 37 38 // Init sets available tuning sets. 39 func (tf *simpleFactory) Init(tuningSets []*api.TuningSet) { 40 tf.tuningSetMap = make(map[string]*api.TuningSet) 41 for i := range tuningSets { 42 tf.tuningSetMap[tuningSets[i].Name] = tuningSets[i] 43 } 44 } 45 46 // CreateTuningSet creates new tuning set based on provided tuning set name. 47 func (tf *simpleFactory) CreateTuningSet(name string) (TuningSet, error) { 48 tuningSet, exists := tf.tuningSetMap[name] 49 if !exists { 50 return nil, fmt.Errorf("tuningset %s not found", name) 51 } 52 switch { 53 case tuningSet.QPSLoad != nil: 54 return newQPSLoad(tuningSet.QPSLoad), nil 55 case tuningSet.RandomizedLoad != nil: 56 return newRandomizedLoad(tuningSet.RandomizedLoad), nil 57 case tuningSet.SteppedLoad != nil: 58 return newSteppedLoad(tuningSet.SteppedLoad), nil 59 case tuningSet.TimeLimitedLoad != nil: 60 return newTimeLimitedLoad(tuningSet.TimeLimitedLoad), nil 61 case tuningSet.RandomizedTimeLimitedLoad != nil: 62 return newRandomizedTimeLimitedLoad(tuningSet.RandomizedTimeLimitedLoad), nil 63 case tuningSet.ParallelismLimitedLoad != nil: 64 return newParallelismLimitedLoad(tuningSet.ParallelismLimitedLoad), nil 65 case tuningSet.GlobalQPSLoad != nil: 66 return tf.globalQPSLoadFactory.GetOrCreate(name, tuningSet.GlobalQPSLoad), nil 67 default: 68 return nil, fmt.Errorf("incorrect tuning set: %v", tuningSet) 69 } 70 }