feat: add trace in redis & mon & sql (#1799)
* feat: add sub spanId with redis Signed-off-by: chenquan <chenquan.dev@gmail.com> * add tests Signed-off-by: chenquan <chenquan.dev@gmail.com> * fix a bug Signed-off-by: chenquan <chenquan.dev@gmail.com> * feat: add sub spanId in sql Signed-off-by: chenquan <chenquan.dev@gmail.com> * feat: add sub spanId in mon Signed-off-by: chenquan <chenquan.dev@gmail.com> * chore: optimize code Signed-off-by: chenquan <chenquan.dev@gmail.com> * feat: add breaker in warpSession Signed-off-by: chenquan <chenquan.dev@gmail.com> * chore: optimize code Signed-off-by: chenquan <chenquan.dev@gmail.com> * test: add tests Signed-off-by: chenquan <chenquan.dev@gmail.com> * chore: reformat code Signed-off-by: chenquan <chenquan.dev@gmail.com> * fix: fix typo Signed-off-by: chenquan <chenquan.dev@gmail.com> * fix a bug Signed-off-by: chenquan <chenquan.dev@gmail.com>
This commit is contained in:
@@ -9,9 +9,17 @@ import (
|
||||
|
||||
red "github.com/go-redis/redis/v8"
|
||||
"github.com/stretchr/testify/assert"
|
||||
ztrace "github.com/zeromicro/go-zero/core/trace"
|
||||
)
|
||||
|
||||
func TestHookProcessCase1(t *testing.T) {
|
||||
ztrace.StartAgent(ztrace.Config{
|
||||
Name: "go-zero-test",
|
||||
Endpoint: "http://localhost:14268/api/traces",
|
||||
Batcher: "jaeger",
|
||||
Sampler: 1.0,
|
||||
})
|
||||
|
||||
writer := log.Writer()
|
||||
var buf strings.Builder
|
||||
log.SetOutput(&buf)
|
||||
@@ -24,9 +32,17 @@ func TestHookProcessCase1(t *testing.T) {
|
||||
|
||||
assert.Nil(t, durationHook.AfterProcess(ctx, red.NewCmd(context.Background())))
|
||||
assert.False(t, strings.Contains(buf.String(), "slow"))
|
||||
assert.Equal(t, "redis", ctx.Value(spanKey).(interface{ Name() string }).Name())
|
||||
}
|
||||
|
||||
func TestHookProcessCase2(t *testing.T) {
|
||||
ztrace.StartAgent(ztrace.Config{
|
||||
Name: "go-zero-test",
|
||||
Endpoint: "http://localhost:14268/api/traces",
|
||||
Batcher: "jaeger",
|
||||
Sampler: 1.0,
|
||||
})
|
||||
|
||||
writer := log.Writer()
|
||||
var buf strings.Builder
|
||||
log.SetOutput(&buf)
|
||||
@@ -36,11 +52,14 @@ func TestHookProcessCase2(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, "redis", ctx.Value(spanKey).(interface{ Name() string }).Name())
|
||||
|
||||
time.Sleep(slowThreshold.Load() + time.Millisecond)
|
||||
|
||||
assert.Nil(t, durationHook.AfterProcess(ctx, red.NewCmd(context.Background(), "foo", "bar")))
|
||||
assert.True(t, strings.Contains(buf.String(), "slow"))
|
||||
assert.True(t, strings.Contains(buf.String(), "trace"))
|
||||
assert.True(t, strings.Contains(buf.String(), "span"))
|
||||
}
|
||||
|
||||
func TestHookProcessCase3(t *testing.T) {
|
||||
@@ -74,6 +93,7 @@ func TestHookProcessPipelineCase1(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, "redis", ctx.Value(spanKey).(interface{ Name() string }).Name())
|
||||
|
||||
assert.Nil(t, durationHook.AfterProcessPipeline(ctx, []red.Cmder{
|
||||
red.NewCmd(context.Background()),
|
||||
@@ -82,6 +102,13 @@ func TestHookProcessPipelineCase1(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHookProcessPipelineCase2(t *testing.T) {
|
||||
ztrace.StartAgent(ztrace.Config{
|
||||
Name: "go-zero-test",
|
||||
Endpoint: "http://localhost:14268/api/traces",
|
||||
Batcher: "jaeger",
|
||||
Sampler: 1.0,
|
||||
})
|
||||
|
||||
writer := log.Writer()
|
||||
var buf strings.Builder
|
||||
log.SetOutput(&buf)
|
||||
@@ -91,6 +118,7 @@ func TestHookProcessPipelineCase2(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, "redis", ctx.Value(spanKey).(interface{ Name() string }).Name())
|
||||
|
||||
time.Sleep(slowThreshold.Load() + time.Millisecond)
|
||||
|
||||
@@ -98,6 +126,8 @@ func TestHookProcessPipelineCase2(t *testing.T) {
|
||||
red.NewCmd(context.Background(), "foo", "bar"),
|
||||
}))
|
||||
assert.True(t, strings.Contains(buf.String(), "slow"))
|
||||
assert.True(t, strings.Contains(buf.String(), "trace"))
|
||||
assert.True(t, strings.Contains(buf.String(), "span"))
|
||||
}
|
||||
|
||||
func TestHookProcessPipelineCase3(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user