Skip to content

Commit 0738acb

Browse files
authored
Merge branch 'main' into wrong-range-judgement
2 parents 1cc437c + 01b80d9 commit 0738acb

File tree

6 files changed

+79
-22
lines changed

6 files changed

+79
-22
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
}

commands/verify/verify.go

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package verify
2020
import (
2121
"context"
2222
"fmt"
23+
"github.com/apache/skywalking-infra-e2e/internal/constant"
2324
"sync"
2425
"time"
2526

@@ -53,7 +54,8 @@ var Verify = &cobra.Command{
5354
Short: "verify if the actual data match the expected data",
5455
RunE: func(cmd *cobra.Command, args []string) error {
5556
if expected != "" {
56-
return verifySingleCase(expected, actual, query)
57+
_, err := verifySingleCase(expected, actual, query)
58+
return err
5759
}
5860

5961
// If there is no given flags.
@@ -69,34 +71,34 @@ type verifyInfo struct {
6971
failFast bool
7072
}
7173

72-
func verifySingleCase(expectedFile, actualFile, query string) error {
74+
func verifySingleCase(expectedFile, actualFile, query string) (string, error) {
7375
expectedData, err := util.ReadFileContent(expectedFile)
7476
if err != nil {
75-
return fmt.Errorf("failed to read the expected data file: %v", err)
77+
return "", fmt.Errorf("failed to read the expected data file: %v", err)
7678
}
7779

7880
var actualData, sourceName, stderr string
7981
if actualFile != "" {
8082
sourceName = actualFile
8183
actualData, err = util.ReadFileContent(actualFile)
8284
if err != nil {
83-
return fmt.Errorf("failed to read the actual data file: %v", err)
85+
return "", fmt.Errorf("failed to read the actual data file: %v", err)
8486
}
8587
} else if query != "" {
8688
sourceName = query
8789
actualData, stderr, err = util.ExecuteCommand(query)
8890
if err != nil {
89-
return fmt.Errorf("failed to execute the query: %s, output: %s, error: %v", query, actualData, stderr)
91+
return "", fmt.Errorf("failed to execute the query: %s, output: %s, error: %v", query, actualData, stderr)
9092
}
9193
}
9294

9395
if err = verifier.Verify(actualData, expectedData); err != nil {
9496
if me, ok := err.(*verifier.MismatchError); ok {
95-
return fmt.Errorf("failed to verify the output: %s, error:\n%v", sourceName, me.Error())
97+
return actualData, fmt.Errorf("failed to verify the output: %s, error:\n%v", sourceName, me.Error())
9698
}
97-
return fmt.Errorf("failed to verify the output: %s, error:\n%v", sourceName, err)
99+
return actualData, fmt.Errorf("failed to verify the output: %s, error:\n%v", sourceName, err)
98100
}
99-
return nil
101+
return actualData, nil
100102
}
101103

102104
// concurrentlyVerifySingleCase verifies a single case in concurrency mode,
@@ -127,7 +129,7 @@ func concurrentlyVerifySingleCase(
127129
res.Skip = true
128130
return res
129131
default:
130-
if err := verifySingleCase(v.GetExpected(), v.GetActual(), v.Query); err == nil {
132+
if d, err := verifySingleCase(v.GetExpected(), v.GetActual(), v.Query); err == nil {
131133
if current == 0 {
132134
res.Msg = fmt.Sprintf("verified %v\n", caseName(v))
133135
} else {
@@ -138,6 +140,9 @@ func concurrentlyVerifySingleCase(
138140
time.Sleep(verifyInfo.interval)
139141
} else {
140142
res.Msg = fmt.Sprintf("failed to verify %v, retried %d time(s):", caseName(v), current)
143+
if d != "" {
144+
res.Msg += fmt.Sprintf(" the actual data is:\n%s\n", d)
145+
}
141146
res.Err = err
142147
}
143148
}
@@ -215,7 +220,7 @@ func verifyCasesSerially(verify *config.Verify, verifyInfo *verifyInfo) (err err
215220

216221
if v.GetExpected() == "" {
217222
res[idx].Skip = false
218-
res[idx].Msg = fmt.Sprintf("failed to verify %v", caseName(v))
223+
res[idx].Msg = fmt.Sprintf("%s failed to verify %v", formatVerificationTime(), caseName(v))
219224
res[idx].Err = fmt.Errorf("the expected data file for %v is not specified", caseName(v))
220225

221226
printer.Warning(res[idx].Msg)
@@ -227,11 +232,11 @@ func verifyCasesSerially(verify *config.Verify, verifyInfo *verifyInfo) (err err
227232
}
228233

229234
for current := 0; current <= verifyInfo.retryCount; current++ {
230-
if e := verifySingleCase(v.GetExpected(), v.GetActual(), v.Query); e == nil {
235+
if d, e := verifySingleCase(v.GetExpected(), v.GetActual(), v.Query); e == nil {
231236
if current == 0 {
232-
res[idx].Msg = fmt.Sprintf("verified %v \n", caseName(v))
237+
res[idx].Msg = fmt.Sprintf("%s verified %v \n", formatVerificationTime(), caseName(v))
233238
} else {
234-
res[idx].Msg = fmt.Sprintf("verified %v, retried %d time(s)\n", caseName(v), current)
239+
res[idx].Msg = fmt.Sprintf("%s verified %v, retried %d time(s)\n", formatVerificationTime(), caseName(v), current)
235240
}
236241
res[idx].Skip = false
237242
printer.Success(res[idx].Msg)
@@ -240,11 +245,15 @@ func verifyCasesSerially(verify *config.Verify, verifyInfo *verifyInfo) (err err
240245
if current == 0 {
241246
printer.UpdateText(fmt.Sprintf("failed to verify %v, will continue retry:", caseName(v)))
242247
} else {
243-
printer.UpdateText(fmt.Sprintf("failed to verify %v, retry [%d/%d]", caseName(v), current, verifyInfo.retryCount))
248+
printer.UpdateText(fmt.Sprintf("failed to verify %v, retry [%d/%d]", caseName(v), current,
249+
verifyInfo.retryCount))
244250
}
245251
time.Sleep(verifyInfo.interval)
246252
} else {
247-
res[idx].Msg = fmt.Sprintf("failed to verify %v, retried %d time(s)", caseName(v), current)
253+
res[idx].Msg = fmt.Sprintf("%s failed to verify %v, retried %d time(s)", formatVerificationTime(), caseName(v), current)
254+
if d != "" {
255+
res[idx].Msg += fmt.Sprintf(", the actual data is:\n%s\n", d)
256+
}
248257
res[idx].Err = e
249258
res[idx].Skip = false
250259
printer.UpdateText(fmt.Sprintf("failed to verify %v, retry [%d/%d]", caseName(v), current, verifyInfo.retryCount))
@@ -260,6 +269,10 @@ func verifyCasesSerially(verify *config.Verify, verifyInfo *verifyInfo) (err err
260269
return nil
261270
}
262271

272+
func formatVerificationTime() string {
273+
return time.Now().Format(constant.LogTimestampFormat)
274+
}
275+
263276
func caseName(v *config.VerifyCase) string {
264277
if v.Name == "" {
265278
if v.Actual != "" {

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: 22 additions & 4 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

@@ -62,19 +69,26 @@ func NewHTTPAction(intervalStr string, times int, url, method, body string, head
6269
body: body,
6370
headers: headers,
6471
executedCount: 0,
65-
stopCh: make(chan struct{}),
72+
stopCh: make(chan struct{}, 1),
6673
client: &http.Client{},
6774
}, nil
6875
}
6976

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
7790
go func() {
91+
defer t.Stop()
7892
for {
7993
select {
8094
case <-t.C:
@@ -85,10 +99,14 @@ func (h *httpAction) Do() chan error {
8599
if !sent && (err == nil || h.times == h.executedCount) {
86100
result <- err
87101
sent = true
102+
logger.Log.Infof("trigger has sent result after executed %d requests with err: %v", h.executedCount, err)
103+
}
104+
if h.times != math.MaxInt32 && h.executedCount >= h.times {
105+
logger.Log.Infof("trigger has completed %d requests and will stop.", h.executedCount)
106+
return
88107
}
89108
case <-h.stopCh:
90-
t.Stop()
91-
result <- nil
109+
logger.Log.Infof("trigger was stopped manually after %d executions.", h.executedCount)
92110
return
93111
}
94112
}

internal/constant/log.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to Apache Software Foundation (ASF) under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Apache Software Foundation (ASF) licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
//
18+
19+
package constant
20+
21+
const (
22+
LogTimestampFormat = "2006-01-02 15:04:05"
23+
)

internal/logger/log.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package logger
1919

2020
import (
21+
"github.com/apache/skywalking-infra-e2e/internal/constant"
2122
"os"
2223

2324
"github.com/sirupsen/logrus"
@@ -32,7 +33,9 @@ func init() {
3233
Log.Level = logrus.InfoLevel
3334
Log.SetOutput(os.Stdout)
3435
Log.SetFormatter(&logrus.TextFormatter{
35-
DisableTimestamp: true,
36+
DisableTimestamp: false,
37+
FullTimestamp: true,
38+
TimestampFormat: constant.LogTimestampFormat,
3639
DisableLevelTruncation: true,
3740
ForceColors: true,
3841
})

0 commit comments

Comments
 (0)