Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #255 from thestormforge/locust-runtime
Browse files Browse the repository at this point in the history
Fix parsing and formatting of Locust runTime on the application
  • Loading branch information
jgustie authored Dec 11, 2020
2 parents cc5cb11 + 9b5a3f2 commit 97b1069
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
3 changes: 1 addition & 2 deletions api/apps/v1alpha1/application_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1alpha1

import (
"encoding/json"
"time"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -118,7 +117,7 @@ type LocustScenario struct {
// The rate per second in which users are spawned.
SpawnRate *int `json:"spawnRate,omitempty"`
// Stop after the specified amount of time.
RunTime *time.Duration `json:"runTime,omitempty"`
RunTime *metav1.Duration `json:"runTime,omitempty"`
}

// Objective describes the goal of the optimization in terms of specific metrics. Note that only
Expand Down
10 changes: 5 additions & 5 deletions api/apps/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func AddTrialJob(sc *redskyappsv1alpha1.Scenario, app *redskyappsv1alpha1.Applic
}
if runTime := runTime(sc.Locust); runTime != nil {
pod.Containers[0].Env = append(pod.Containers[0].Env, *runTime)
exp.Spec.TrialTemplate.Spec.ApproximateRuntime = &metav1.Duration{Duration: *sc.Locust.RunTime}
exp.Spec.TrialTemplate.Spec.ApproximateRuntime = sc.Locust.RunTime
}

// Add a ConfigMap with the Locust file
Expand Down Expand Up @@ -170,8 +170,11 @@ func runTime(s *redskyappsv1alpha1.LocustScenario) *corev1.EnvVar {
if s.RunTime == nil {
return nil
}

// Just give Locust the number of seconds
// See: https://github.com/locustio/locust/blob/1f30d36d8f8d646eccb55aab7080fa69bf35c0d7/locust/util/timespan.py
return &corev1.EnvVar{
Name: "RUN_TIME",
Value: s.RunTime.String(),
Value: fmt.Sprintf("%.0f", s.RunTime.Seconds()),
}
}

0 comments on commit 97b1069

Please # to comment.