Skip to content

Commit

Permalink
perf(metrics-operator): improve performance of storing analysis resul…
Browse files Browse the repository at this point in the history
…ts (#1905)

Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT authored Aug 21, 2023
1 parent b6f2172 commit efe3380
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ func NewAnalysisEvaluator(o IObjectiveEvaluator) AnalysisEvaluator {

func (ae *AnalysisEvaluator) Evaluate(values map[string]string, ad *v1alpha3.AnalysisDefinition) types.AnalysisResult {
result := types.AnalysisResult{
ObjectiveResults: make([]types.ObjectiveResult, 0, len(ad.Spec.Objectives)),
ObjectiveResults: make([]types.ObjectiveResult, len(ad.Spec.Objectives)),
}

keyObjectiveFailed := false
for _, objective := range ad.Spec.Objectives {
for index, objective := range ad.Spec.Objectives {
// evaluate a single objective and store it's result
objectiveResult := ae.ObjectiveEvaluator.Evaluate(values, &objective)
result.ObjectiveResults = append(result.ObjectiveResults, objectiveResult)
result.ObjectiveResults[index] = objectiveResult

// count scores
result.MaximumScore += float64(objective.Weight)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package analysis

import (
"errors"
"fmt"
"strconv"

"github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha3"
Expand Down Expand Up @@ -52,7 +52,7 @@ func (oe *ObjectiveEvaluator) Evaluate(values map[string]string, obj *v1alpha3.O
func getValueFromMap(values map[string]string, key string) (float64, error) {
val, ok := values[key]
if !ok {
return 0.0, errors.New("required value not available")
return 0.0, fmt.Errorf("required value '%s' not available", key)
}

floatVal, err := strconv.ParseFloat(val, 64)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package analysis

import (
"errors"
"fmt"
"testing"

"github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha3"
Expand Down Expand Up @@ -29,7 +29,7 @@ func TestObjectiveEvaluator_Evaluate(t *testing.T) {
mockedEvaluator: &fake.ITargetEvaluatorMock{},
want: types.ObjectiveResult{
Score: 0.0,
Error: errors.New("required value not available"),
Error: fmt.Errorf("required value 'name' not available"),
},
},
{
Expand Down

0 comments on commit efe3380

Please sign in to comment.