Skip to content

Commit

Permalink
Remove validateConfig() (kube-burner#696)
Browse files Browse the repository at this point in the history
## Type of change

- [ ] Refactor
- [ ] New feature
- [ ] Bug fix
- [x] Optimization
- [ ] Documentation Update

## Description

Remove unnecessary validateConfig() from measurements interface 

## Related Tickets & Documents

- Related Issue #
- Closes #

Signed-off-by: Raul Sevilla <[email protected]>
  • Loading branch information
rsevilla87 authored Sep 10, 2024
1 parent c0ca029 commit 6c3033a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 49 deletions.
6 changes: 2 additions & 4 deletions pkg/measurements/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ type measurement interface {
start(*sync.WaitGroup) error
stop() error
collect(*sync.WaitGroup)
setConfig(types.Measurement)
validateConfig() error
setConfig(types.Measurement) error
index(string, map[string]indexers.Indexer)
}

Expand Down Expand Up @@ -83,8 +82,7 @@ func (mf *measurementFactory) register(measurement types.Measurement, measuremen
if _, exists := mf.createFuncs[measurement.Name]; exists {
log.Warnf("Measurement already registered: %s", measurement.Name)
} else {
measurementFunc.setConfig(measurement)
if err := measurementFunc.validateConfig(); err != nil {
if err := measurementFunc.setConfig(measurement); err != nil {
return fmt.Errorf("%s config error: %s", measurement.Name, err)
}
mf.createFuncs[measurement.Name] = measurementFunc
Expand Down
5 changes: 1 addition & 4 deletions pkg/measurements/pod_latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,8 @@ func (p *podLatency) handleUpdatePod(obj interface{}) {
}
}

func (p *podLatency) setConfig(cfg types.Measurement) {
func (p *podLatency) setConfig(cfg types.Measurement) error {
p.config = cfg
}

func (p *podLatency) validateConfig() error {
var metricFound bool
var latencyMetrics = []string{"P99", "P95", "P50", "Avg", "Max"}
for _, th := range p.config.LatencyThresholds {
Expand Down
17 changes: 7 additions & 10 deletions pkg/measurements/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ func init() {
measurementMap["pprof"] = &pprof{}
}

func (p *pprof) setConfig(cfg types.Measurement) {
func (p *pprof) setConfig(cfg types.Measurement) error {
p.config = cfg
for _, target := range p.config.PProfTargets {
if target.BearerToken != "" && (target.CertFile != "" || target.Cert != "") {
return fmt.Errorf("bearerToken and cert auth methods cannot be specified together in the same target")
}
}
return nil
}

func (p *pprof) start(measurementWg *sync.WaitGroup) error {
Expand Down Expand Up @@ -250,12 +256,3 @@ func copyCertsToPod(pod corev1.Pod, cert, privKey io.Reader) error {
log.Infof("Certificate and private key copied into %s %s", pod.Name, pod.Spec.Containers[0].Name)
return nil
}

func (p *pprof) validateConfig() error {
for _, target := range p.config.PProfTargets {
if target.BearerToken != "" && (target.CertFile != "" || target.Cert != "") {
return fmt.Errorf("bearerToken and cert auth methods cannot be specified together in the same target")
}
}
return nil
}
5 changes: 1 addition & 4 deletions pkg/measurements/service_latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,8 @@ func (s *serviceLatency) handleCreateSvc(obj interface{}) {
}(svc)
}

func (s *serviceLatency) setConfig(cfg types.Measurement) {
func (s *serviceLatency) setConfig(cfg types.Measurement) error {
s.config = cfg
}

func (s *serviceLatency) validateConfig() error {
if s.config.ServiceTimeout == 0 {
return fmt.Errorf("svcTimeout cannot be 0")
}
Expand Down
51 changes: 24 additions & 27 deletions pkg/measurements/vmi_latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,31 @@ func (p *vmiLatency) handleUpdateVMIPod(obj interface{}) {
}
}

func (p *vmiLatency) setConfig(cfg types.Measurement) {
func (p *vmiLatency) setConfig(cfg types.Measurement) error {
p.config = cfg
var metricFound bool
var latencyMetrics = []string{"P99", "P95", "P50", "Avg", "Max"}
for _, th := range p.config.LatencyThresholds {
if th.ConditionType == string(kvv1.Pending) ||
th.ConditionType == string(kvv1.Scheduling) ||
th.ConditionType == string(kvv1.Scheduled) ||
th.ConditionType == string(kvv1.Running) ||
th.ConditionType == string(kvv1.VirtualMachineInstanceReady) ||
th.ConditionType == string(kvv1.Succeeded) {
for _, lm := range latencyMetrics {
if th.Metric == lm {
metricFound = true
break
}
}
if !metricFound {
return fmt.Errorf("unsupported metric %s in vmLatency measurement, supported are: %s", th.Metric, strings.Join(latencyMetrics, ", "))
}
} else {
return fmt.Errorf("unsupported vm condition type in vmLatency measurement: %s", th.ConditionType)
}
}
return nil
}

// Start starts vmiLatency measurement
Expand Down Expand Up @@ -453,29 +476,3 @@ func (p *vmiLatency) calcQuantiles() {
p.latencyQuantiles = append(p.latencyQuantiles, calcSummary(podCondition, latencies))
}
}

func (p *vmiLatency) validateConfig() error {
var metricFound bool
var latencyMetrics = []string{"P99", "P95", "P50", "Avg", "Max"}
for _, th := range p.config.LatencyThresholds {
if th.ConditionType == string(kvv1.Pending) ||
th.ConditionType == string(kvv1.Scheduling) ||
th.ConditionType == string(kvv1.Scheduled) ||
th.ConditionType == string(kvv1.Running) ||
th.ConditionType == string(kvv1.VirtualMachineInstanceReady) ||
th.ConditionType == string(kvv1.Succeeded) {
for _, lm := range latencyMetrics {
if th.Metric == lm {
metricFound = true
break
}
}
if !metricFound {
return fmt.Errorf("unsupported metric %s in vmLatency measurement, supported are: %s", th.Metric, strings.Join(latencyMetrics, ", "))
}
} else {
return fmt.Errorf("unsupported vm condition type in vmLatency measurement: %s", th.ConditionType)
}
}
return nil
}

0 comments on commit 6c3033a

Please sign in to comment.