Skip to content

Commit

Permalink
log error instead of making noded crash
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdaGastan committed Sep 13, 2023
1 parent 52dafa2 commit b2698a1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/perf/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// PerformanceMonitor holds the module data
type PerformanceMonitor struct {
scheduler *gocron.Scheduler
pool redis.Pool
pool *redis.Pool
tasks []Task
}

Expand All @@ -29,7 +29,7 @@ func NewPerformanceMonitor(redisAddr string) (*PerformanceMonitor, error) {

return &PerformanceMonitor{
scheduler: scheduler,
pool: *redisPool,
pool: redisPool,
tasks: []Task{},
}, nil
}
Expand Down
17 changes: 15 additions & 2 deletions pkg/perf/tcp_task.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package perf

import (
"bytes"
"context"
"fmt"
"os/exec"

"github.com/rs/zerolog/log"
"github.com/threefoldtech/zos/pkg/network/iperf"
)

Expand All @@ -28,10 +30,21 @@ func (t *TCPTask) Cron() string {

// Run runs the tcp test and returns the result
func (t *TCPTask) Run(ctx context.Context) (interface{}, error) {
output, err := exec.CommandContext(ctx, fmt.Sprintf("iperf3 -c %s -p %d -b %s", t.ClientIP, iperf.IperfPort, t.Bandwidth)).Output()
_, err := exec.LookPath("iperf")
if err != nil {
return nil, err
}

return output, nil
cmd := exec.CommandContext(ctx, "iperf", fmt.Sprintf("-c %s -p %d -b %s", t.ClientIP, iperf.IperfPort, t.Bandwidth))
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr
cmd.Stdout = &out

err = cmd.Run()
if err != nil {
log.Error().Err(err).Msgf("failed to run iperf tcp task: %s", stderr.String())
}

return out.String(), nil
}
17 changes: 15 additions & 2 deletions pkg/perf/udp_task.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package perf

import (
"bytes"
"context"
"fmt"
"os/exec"

"github.com/rs/zerolog/log"
"github.com/threefoldtech/zos/pkg/network/iperf"
)

Expand All @@ -28,10 +30,21 @@ func (t *UDPTask) Cron() string {

// Run runs the udp test and returns the result
func (t *UDPTask) Run(ctx context.Context) (interface{}, error) {
output, err := exec.CommandContext(ctx, fmt.Sprintf("iperf3 -c %s -p %d -b %s -u", t.ClientIP, iperf.IperfPort, t.Bandwidth)).Output()
_, err := exec.LookPath("iperf")
if err != nil {
return nil, err
}

return output, nil
cmd := exec.CommandContext(ctx, "iperf", fmt.Sprintf("-c %s -p %d -b %s -u", t.ClientIP, iperf.IperfPort, t.Bandwidth))
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr
cmd.Stdout = &out

err = cmd.Run()
if err != nil {
log.Error().Err(err).Msgf("failed to run iperf udp task: %s", stderr.String())
}

return out.String(), nil
}

0 comments on commit b2698a1

Please sign in to comment.