This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-infra-e2e.git


The following commit(s) were added to refs/heads/main by this push:
     new d0b7768  feat: allow `times` to be <= 0 to simulate endless trigger 
(#134)
d0b7768 is described below

commit d0b77685ed8175ae2cf9cff1cef20e893ff05a87
Author: youjie23 <[email protected]>
AuthorDate: Thu Oct 30 13:36:20 2025 +0800

    feat: allow `times` to be <= 0 to simulate endless trigger (#134)
---
 commands/run/run.go                 |  2 +-
 docs/en/setup/Configuration-File.md |  2 +-
 internal/components/trigger/http.go | 19 +++++++++++++++++--
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/commands/run/run.go b/commands/run/run.go
index a304779..e3a9432 100644
--- a/commands/run/run.go
+++ b/commands/run/run.go
@@ -91,7 +91,7 @@ func runAccordingE2E() error {
                if err != nil {
                        return err
                }
-               logger.Log.Infof("trigger part finished successfully")
+               logger.Log.Infof("trigger part started successfully")
        } else {
                logger.Log.Infof("no trigger need to execute")
        }
diff --git a/docs/en/setup/Configuration-File.md 
b/docs/en/setup/Configuration-File.md
index d171214..05f4854 100644
--- a/docs/en/setup/Configuration-File.md
+++ b/docs/en/setup/Configuration-File.md
@@ -144,7 +144,7 @@ After the `Setup` step is finished, use the `Trigger` step 
to generate traffic.
 trigger:
   action: http      # The action of the trigger. support HTTP invoke.
   interval: 3s      # Trigger the action every 3 seconds.
-  times: 5          # The retry count before the request success.
+  times: 5          # The retry count before the request success.A 
non-positive number implies an infinite loop.This property defaults to 0
   url: http://apache.skywalking.com/ # Http trigger url link.
   method: GET       # Http trigger method.
   headers:
diff --git a/internal/components/trigger/http.go 
b/internal/components/trigger/http.go
index 1bec933..e1a035e 100644
--- a/internal/components/trigger/http.go
+++ b/internal/components/trigger/http.go
@@ -21,6 +21,7 @@ package trigger
 import (
        "fmt"
        "io"
+       "math"
        "net/http"
        "os"
        "strings"
@@ -51,6 +52,12 @@ func NewHTTPAction(intervalStr string, times int, url, 
method, body string, head
                return nil, fmt.Errorf("trigger interval should be > 0, but was 
%s", interval)
        }
 
+       if times <= 0 {
+               logger.Log.Warnf("trigger times (%d) is invalid (<=0). It has 
been set to a large number (%d) to simulate infinite runs. "+
+                       "consider using a positive value.", times, 
math.MaxInt32)
+               times = math.MaxInt32
+       }
+
        // there can be env variables in url, say, 
"http://${GATEWAY_HOST}:${GATEWAY_PORT}/test";
        url = os.ExpandEnv(url)
 
@@ -70,7 +77,13 @@ func NewHTTPAction(intervalStr string, times int, url, 
method, body string, head
 func (h *httpAction) Do() chan error {
        t := time.NewTicker(h.interval)
 
-       logger.Log.Infof("trigger will request URL %s %d times with interval 
%s.", h.url, h.times, h.interval)
+       var timesInfo string
+       if h.times == math.MaxInt32 {
+               timesInfo = "a very large number of times (practically until 
stopped)"
+       } else {
+               timesInfo = fmt.Sprintf("%d times", h.times)
+       }
+       logger.Log.Infof("trigger will request URL %s %s with interval %s.", 
h.url, timesInfo, h.interval)
 
        result := make(chan error)
        sent := false
@@ -87,10 +100,12 @@ func (h *httpAction) Do() chan error {
                                        result <- err
                                        sent = true
                                }
-                               if h.times == h.executedCount {
+                               if h.times != math.MaxInt32 && h.executedCount 
>= h.times {
+                                       logger.Log.Infof("trigger has completed 
%d requests and will stop.", h.executedCount)
                                        return
                                }
                        case <-h.stopCh:
+                               logger.Log.Infof("trigger was stopped manually 
after %d executions.", h.executedCount)
                                return
                        }
                }

Reply via email to