Skip to content

Commit 01b80d9

Browse files
authored
chore: Add new logs and support time format display (#136)
1 parent d0b7768 commit 01b80d9

4 files changed

Lines changed: 39 additions & 6 deletions

File tree

commands/verify/verify.go

Lines changed: 11 additions & 5 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

@@ -219,7 +220,7 @@ func verifyCasesSerially(verify *config.Verify, verifyInfo *verifyInfo) (err err
219220

220221
if v.GetExpected() == "" {
221222
res[idx].Skip = false
222-
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))
223224
res[idx].Err = fmt.Errorf("the expected data file for %v is not specified", caseName(v))
224225

225226
printer.Warning(res[idx].Msg)
@@ -233,9 +234,9 @@ func verifyCasesSerially(verify *config.Verify, verifyInfo *verifyInfo) (err err
233234
for current := 0; current <= verifyInfo.retryCount; current++ {
234235
if d, e := verifySingleCase(v.GetExpected(), v.GetActual(), v.Query); e == nil {
235236
if current == 0 {
236-
res[idx].Msg = fmt.Sprintf("verified %v \n", caseName(v))
237+
res[idx].Msg = fmt.Sprintf("%s verified %v \n", formatVerificationTime(), caseName(v))
237238
} else {
238-
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)
239240
}
240241
res[idx].Skip = false
241242
printer.Success(res[idx].Msg)
@@ -244,11 +245,12 @@ func verifyCasesSerially(verify *config.Verify, verifyInfo *verifyInfo) (err err
244245
if current == 0 {
245246
printer.UpdateText(fmt.Sprintf("failed to verify %v, will continue retry:", caseName(v)))
246247
} else {
247-
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))
248250
}
249251
time.Sleep(verifyInfo.interval)
250252
} else {
251-
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)
252254
if d != "" {
253255
res[idx].Msg += fmt.Sprintf(", the actual data is:\n%s\n", d)
254256
}
@@ -267,6 +269,10 @@ func verifyCasesSerially(verify *config.Verify, verifyInfo *verifyInfo) (err err
267269
return nil
268270
}
269271

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

internal/components/trigger/http.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func (h *httpAction) Do() chan error {
9999
if !sent && (err == nil || h.times == h.executedCount) {
100100
result <- err
101101
sent = true
102+
logger.Log.Infof("trigger has sent result after executed %d requests with err: %v", h.executedCount, err)
102103
}
103104
if h.times != math.MaxInt32 && h.executedCount >= h.times {
104105
logger.Log.Infof("trigger has completed %d requests and will stop.", h.executedCount)

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)