This repository was archived by the owner on Dec 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 241
This repository was archived by the owner on Dec 21, 2023. It is now read-only.
lighthouse: Allow timeframe to be passed via cloudevent #4079
Copy link
Copy link
Closed
Description
Follow up of #4075
As a user, I want to be able to specify a timeframe for an evaluation, e.g.:
- name: "evaluation"
triggeredAfter: "10m"
properties:
timeframe: "5m"
This needs to be implemented in lighthouse-service, e.g., here:
keptn/lighthouse-service/event_handler/start_evaluation_handler.go
Lines 145 to 152 in 94dfd0a
func getEvaluationTimestamps(e *keptnv2.EvaluationTriggeredEventData) (string, string, error) { | |
if e.Evaluation.Start != "" && e.Evaluation.End != "" { | |
return e.Evaluation.Start, e.Evaluation.End, nil | |
} else if e.Test.Start != "" && e.Test.End != "" { | |
return e.Test.Start, e.Test.End, nil | |
} | |
return "", "", errors.New("evaluation.triggered event does not contain evaluation timeframe") | |
} |
Note: start
should be inferred from the current cloudevent evaluation.triggered timestamp. end
should be calculated as start - timeframe
.
This is currently handled in API and should be refactored accordingly:
keptn/api/handlers/evaluation.go
Lines 84 to 131 in 069dd0f
func getStartEndTime(startDatePoint string, endDatePoint string, timeframe string) (*time.Time, *time.Time, error) { | |
// set default values for start and end time | |
dateLayout := "2006-01-02T15:04:05" | |
var err error | |
minutes := 5 // default timeframe | |
// input validation | |
if startDatePoint != "" && endDatePoint == "" { | |
// if a start date is set, but no end date is set, we require the timeframe to be set | |
if timeframe == "" { | |
errMsg := "Please provide a timeframe, e.g., --timeframe=5m, or an end date using --end=..." | |
return nil, nil, fmt.Errorf(errMsg) | |
} | |
} | |
if endDatePoint != "" && timeframe != "" { | |
// can not use end date and timeframe at the same time | |
errMsg := "You can not use --end together with --timeframe" | |
return nil, nil, fmt.Errorf(errMsg) | |
} | |
if endDatePoint != "" && startDatePoint == "" { | |
errMsg := "start date is required when using an end date" | |
return nil, nil, fmt.Errorf(errMsg) | |
} | |
// parse timeframe | |
if timeframe != "" { | |
errMsg := "The time frame format is invalid. Use the format [duration]m, e.g.: 5m" | |
i := strings.Index(timeframe, "m") | |
if i > -1 { | |
minutesStr := timeframe[:i] | |
minutes, err = strconv.Atoi(minutesStr) | |
if err != nil { | |
return nil, nil, fmt.Errorf(errMsg) | |
} | |
} else { | |
return nil, nil, fmt.Errorf(errMsg) | |
} | |
} | |
// initialize default values for end and start time | |
end := time.Now().UTC() | |
start := time.Now().UTC().Add(-time.Duration(minutes) * time.Minute) |
Definition of Done
- lighthouse-service accepts
evaluation.timeframe
in addition totest.start
,test.end
,evaluation.start
andevaluation.end
- keptn/spec and keptn/go-utils
evaluation.triggered
cloudevent needs to be adapted to also includetimeframe
- api-service refactored/changed to avoid duplicated code between lighthouse and api-service.