forked from keptn-sandbox/artillery-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artilleryUtils.go
50 lines (40 loc) · 1.04 KB
/
artilleryUtils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"encoding/json"
"fmt"
"io"
"os"
keptn "github.com/keptn/go-utils/pkg/lib"
)
func getScenarioErrors(file *os.File) (map[string]float64, error) {
errors := make(map[string]float64)
decoder := json.NewDecoder(file)
for {
var data map[string]interface{}
if err := decoder.Decode(&data); err == io.EOF {
break
} else if err != nil {
fmt.Println(fmt.Errorf("Error: failed to unmarshal json %s", err.Error()))
return errors, err
}
for key, value := range data["errors"].(map[string]interface{}) {
if counter, exists := errors[key]; exists {
errors[key] = value.(float64) + counter
} else {
errors[key] = value.(float64)
}
}
}
return errors, nil
}
func runArtillery(resource string, serviceURL string, outputDestination string) (string, error) {
args := []string{
"run",
"-t",
serviceURL,
"--overrides",
fmt.Sprintf("{\"config\": { \"plugins\": {\"save-stats\": { \"destination\": \"%s\" }}}}", outputDestination),
resource,
}
return keptn.ExecuteCommand("artillery", args)
}