Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: added slack notification to runsim #4547

Merged
merged 21 commits into from
Jun 26, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Pass slack config as comma-separated list of values
  • Loading branch information
alessio authored and mircea-c committed Jun 19, 2019
commit e989b46a31d9c56120d3ad391c8251375fdceea2
65 changes: 42 additions & 23 deletions contrib/runsim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
"time"
)

const (
SlackConfigSep = ","
)

var (
// default seeds
seeds = []int{
Expand All @@ -29,6 +33,7 @@ var (
29892989, 30123012, 47284728, 7601778, 8090485,
977367484, 491163361, 424254581, 673398983,
}
seedOverrideList = ""

// goroutine-safe process map
procs map[int]*os.Process
Expand All @@ -49,8 +54,7 @@ var (
slackThread string
seedsStrRepr string
exitOnFail bool
gitReport bool
slackReport bool
slackConfig string

// logs temporary directory
tempdir string
Expand All @@ -65,9 +69,9 @@ func init() {

flag.IntVar(&jobs, "j", jobs, "Number of parallel processes")
flag.StringVar(&genesis, "g", "", "Genesis file")
flag.StringVar(&seedOverrideList, "seeds", "", "run the supplied comma-separated list of seeds instead of defaults")
flag.BoolVar(&exitOnFail, "e", false, "Exit on fail during multi-sim, print error")
flag.BoolVar(&gitReport, "p", false, "Report results to git check")
flag.BoolVar(&slackReport, "s", false, "Report results to slack channel")
flag.StringVar(&slackConfig, "slack", "", "Report results to slack channel")

flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(),
Expand All @@ -83,19 +87,26 @@ func main() {
var err error

flag.Parse()
if flag.NArg() < 8 && (gitReport || slackReport) {
log.Fatal("wrong number of arguments")
} else if !(gitReport || slackReport) && flag.NArg() != 4 {
if flag.NArg() != 4 {
log.Fatal("wrong number of arguments")
}

// prepare input channel
if gitReport || slackReport {
slackToken = flag.Arg(4)
slackChannel = flag.Arg(5)
slackThread = flag.Arg(6)
seeds, seedsStrRepr = makeSeedList(flag.Args()[7:])
if slackConfig != "" {
opts := strings.Split(slackConfig, SlackConfigSep)
if len(opts) != 3 {
log.Fatal("please don't fuck with slack config format")
}
slackToken, slackChannel, slackThread = opts[0], opts[1], opts[2]
}

seedOverrideList = strings.TrimSpace(seedOverrideList)
if seedOverrideList != "" {
seeds, err = makeSeedList(seedOverrideList)
if err != nil {
log.Fatal(err)
}
}

queue := make(chan int, len(seeds))
for _, seed := range seeds {
queue <- seed
Expand Down Expand Up @@ -172,8 +183,8 @@ wait:
os.Exit(1)
}
}
if slackReport {
slackMessage(slackToken, slackChannel, &slackThread, "Finished running simulation for seeds: "+seedsStrRepr)
if slackConfigSupplied() {
slackMessage(slackToken, slackChannel, &slackThread, "Finished running simulation for seeds: "+seedOverrideList)
}
os.Exit(0)
}
Expand Down Expand Up @@ -201,7 +212,7 @@ func worker(id int, seeds <-chan int) {
results <- false
log.Printf("[W%d] Seed %d: FAILED", id, seed)
log.Printf("To reproduce run: %s", buildCommand(testname, blocks, period, genesis, seed))
if slackReport {
if slackConfigSupplied() {
slackMessage(slackToken, slackChannel, nil, "Seed "+strconv.Itoa(seed)+" failed. To reproduce, run: "+buildCommand(testname, blocks, period, genesis, seed))
}
if exitOnFail {
Expand Down Expand Up @@ -286,12 +297,20 @@ func checkSignal(proc *os.Process, signal syscall.Signal) {
}
}

func makeSeedList(args []string) ([]int, string) {
seeds = make([]int, len(args))
var seedsStrRepr string
for i := range seeds {
seeds[i], _ = strconv.Atoi(args[i])
seedsStrRepr = seedsStrRepr + args[i] + " "
func makeSeedList(seeds string) ([]int, error) {
strSeedsLst := strings.Split(seeds, ",")
if len(strSeedsLst) == 0 {
return nil, fmt.Errorf("seeds was empty")
}
intSeeds := make([]int, len(strSeedsLst))
for i, seedstr := range strSeedsLst {
intSeed, err := strconv.Atoi(strings.TrimSpace(seedstr))
if err != nil {
return nil, fmt.Errorf("cannot convert seed to integer: %v", err)
}
intSeeds[i] = intSeed
}
return seeds, seedsStrRepr
return intSeeds, nil
}

func slackConfigSupplied() bool { return slackConfig != "" }