Skip to content

Commit

Permalink
Duration sent to cloud when starting a test with stages
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfijal authored and robingustafsson committed May 10, 2017
1 parent 70ce134 commit af32c77
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 4 additions & 2 deletions stats/cloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ type TestRun struct {
Name string `json:"name"`
ProjectID int `json:"project_id,omitempty"`
Threasholds map[string][]string `json:"thresholds"`
// Duration of test in seconds. -1 for unknown length, 0 for continuous running.
Duration int64 `json:"duration"`
}

type CreateTestRunResponse struct {
ReferenceID string `json:"reference_id"`
}

func (c *Client) CreateTestRun(name string, thresholds map[string][]string) *CreateTestRunResponse {
testRun := TestRun{Name: name, Threasholds: thresholds}
func (c *Client) CreateTestRun(name string, thresholds map[string][]string, duration int64) *CreateTestRunResponse {
testRun := TestRun{Name: name, Threasholds: thresholds, Duration: duration}

url := fmt.Sprintf("%s/tests", c.baseURL)
req, err := c.NewRequest("POST", url, testRun)
Expand Down
19 changes: 18 additions & 1 deletion stats/cloud/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
type Collector struct {
referenceID string

duration int64
thresholds map[string][]string
client *Client
}
Expand All @@ -31,10 +32,17 @@ func New(fname string, opts lib.Options) (*Collector, error) {
}
}

// Sum test duration from options. -1 for unknown duration.
var duration int64 = -1
if len(opts.Stages) > 0 {
duration = sumStages(opts.Stages)
}

return &Collector{
referenceID: referenceID,
thresholds: thresholds,
client: NewClient(token),
duration: duration,
}, nil
}

Expand All @@ -46,7 +54,7 @@ func (c *Collector) Init() {

// TODO fix this and add proper error handling
if c.referenceID == "" {
response := c.client.CreateTestRun(name, c.thresholds)
response := c.client.CreateTestRun(name, c.thresholds, c.duration)
if response != nil {
c.referenceID = response.ReferenceID
}
Expand Down Expand Up @@ -88,3 +96,12 @@ func (c *Collector) Collect(samples []stats.Sample) {
c.client.PushMetric(c.referenceID, cloudSamples)
}
}

func sumStages(stages []lib.Stage) int64 {
var total time.Duration
for _, stage := range stages {
total += stage.Duration
}

return int64(total.Seconds())
}

0 comments on commit af32c77

Please sign in to comment.