Skip to content

Commit d0b7768

Browse files
authored
feat: allow times to be <= 0 to simulate endless trigger (#134)
1 parent 04c668d commit d0b7768

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

commands/run/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func runAccordingE2E() error {
9191
if err != nil {
9292
return err
9393
}
94-
logger.Log.Infof("trigger part finished successfully")
94+
logger.Log.Infof("trigger part started successfully")
9595
} else {
9696
logger.Log.Infof("no trigger need to execute")
9797
}

docs/en/setup/Configuration-File.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ After the `Setup` step is finished, use the `Trigger` step to generate traffic.
144144
trigger:
145145
action: http # The action of the trigger. support HTTP invoke.
146146
interval: 3s # Trigger the action every 3 seconds.
147-
times: 5 # The retry count before the request success.
147+
times: 5 # The retry count before the request success.A non-positive number implies an infinite loop.This property defaults to 0
148148
url: http://apache.skywalking.com/ # Http trigger url link.
149149
method: GET # Http trigger method.
150150
headers:

internal/components/trigger/http.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package trigger
2121
import (
2222
"fmt"
2323
"io"
24+
"math"
2425
"net/http"
2526
"os"
2627
"strings"
@@ -51,6 +52,12 @@ func NewHTTPAction(intervalStr string, times int, url, method, body string, head
5152
return nil, fmt.Errorf("trigger interval should be > 0, but was %s", interval)
5253
}
5354

55+
if times <= 0 {
56+
logger.Log.Warnf("trigger times (%d) is invalid (<=0). It has been set to a large number (%d) to simulate infinite runs. "+
57+
"consider using a positive value.", times, math.MaxInt32)
58+
times = math.MaxInt32
59+
}
60+
5461
// there can be env variables in url, say, "http://${GATEWAY_HOST}:${GATEWAY_PORT}/test"
5562
url = os.ExpandEnv(url)
5663

@@ -70,7 +77,13 @@ func NewHTTPAction(intervalStr string, times int, url, method, body string, head
7077
func (h *httpAction) Do() chan error {
7178
t := time.NewTicker(h.interval)
7279

73-
logger.Log.Infof("trigger will request URL %s %d times with interval %s.", h.url, h.times, h.interval)
80+
var timesInfo string
81+
if h.times == math.MaxInt32 {
82+
timesInfo = "a very large number of times (practically until stopped)"
83+
} else {
84+
timesInfo = fmt.Sprintf("%d times", h.times)
85+
}
86+
logger.Log.Infof("trigger will request URL %s %s with interval %s.", h.url, timesInfo, h.interval)
7487

7588
result := make(chan error)
7689
sent := false
@@ -87,10 +100,12 @@ func (h *httpAction) Do() chan error {
87100
result <- err
88101
sent = true
89102
}
90-
if h.times == h.executedCount {
103+
if h.times != math.MaxInt32 && h.executedCount >= h.times {
104+
logger.Log.Infof("trigger has completed %d requests and will stop.", h.executedCount)
91105
return
92106
}
93107
case <-h.stopCh:
108+
logger.Log.Infof("trigger was stopped manually after %d executions.", h.executedCount)
94109
return
95110
}
96111
}

0 commit comments

Comments
 (0)