-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Trace query and debug enhancement (#1553)
* trace feature * openapi * fix duration check * fix duration bug * fix service name * update ut * add license * imports format * update ut * update ut * add ut TestTranslateCondition() * add ut Test_queryConditions() * add ut Test_traceService_getDebugStatus() * imports format * Keep spaces between Chinese characters and letters
- Loading branch information
1 parent
6103ca2
commit 8d486f5
Showing
15 changed files
with
710 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ALTER TABLE `sp_trace_request_history` MODIFY COLUMN `response_body` MEDIUMTEXT DEFAULT NULL COMMENT '请求响应体'; | ||
|
||
ALTER TABLE `sp_trace_request_history` ADD COLUMN `name` VARCHAR(100) NOT NULL COMMENT '链路调试名称' AFTER `request_id`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package common | ||
|
||
const Layout = "2006-01-02 15:04:05" | ||
|
||
type Void struct{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package debug | ||
|
||
type Status int32 | ||
|
||
const ( | ||
Init Status = 0 | ||
Success Status = 1 | ||
Fail Status = 2 | ||
Stop Status = 3 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package query | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
|
||
"github.com/erda-project/erda-infra/providers/i18n" | ||
"github.com/erda-project/erda-proto-go/msp/apm/trace/pb" | ||
) | ||
|
||
type SpanTree map[string]*pb.Span | ||
type ConditionType string | ||
|
||
const ( | ||
INPUT ConditionType = "input" | ||
) | ||
|
||
var sortConditions = []*pb.TraceQueryCondition{ | ||
{Key: strings.ToLower(pb.SortCondition_TRACE_TIME_DESC.String()), Value: strings.ToLower(pb.SortCondition_TRACE_TIME_DESC.String())}, | ||
{Key: strings.ToLower(pb.SortCondition_TRACE_TIME_ASC.String()), Value: strings.ToLower(pb.SortCondition_TRACE_TIME_ASC.String())}, | ||
{Key: strings.ToLower(pb.SortCondition_SPAN_COUNT_DESC.String()), Value: strings.ToLower(pb.SortCondition_SPAN_COUNT_DESC.String())}, | ||
{Key: strings.ToLower(pb.SortCondition_SPAN_COUNT_ASC.String()), Value: strings.ToLower(pb.SortCondition_SPAN_COUNT_ASC.String())}, | ||
{Key: strings.ToLower(pb.SortCondition_TRACE_DURATION_DESC.String()), Value: strings.ToLower(pb.SortCondition_TRACE_DURATION_DESC.String())}, | ||
{Key: strings.ToLower(pb.SortCondition_TRACE_DURATION_ASC.String()), Value: strings.ToLower(pb.SortCondition_TRACE_DURATION_ASC.String())}, | ||
} | ||
|
||
var limitConditions = []*pb.TraceQueryCondition{ | ||
{Key: strings.ToLower(pb.LimitCondition_NUMBER_100.String()), Value: "100", DisplayName: "100"}, | ||
{Key: strings.ToLower(pb.LimitCondition_NUMBER_200.String()), Value: "200", DisplayName: "200"}, | ||
{Key: strings.ToLower(pb.LimitCondition_NUMBER_500.String()), Value: "500", DisplayName: "500"}, | ||
{Key: strings.ToLower(pb.LimitCondition_NUMBER_1000.String()), Value: "1000", DisplayName: "1000"}, | ||
} | ||
|
||
var TraceStatusConditions = []*pb.TraceQueryCondition{ | ||
{Key: strings.ToLower(pb.TraceStatusCondition_TRACE_ALL.String()), Value: strings.ToLower(pb.TraceStatusCondition_TRACE_ALL.String())}, | ||
{Key: strings.ToLower(pb.TraceStatusCondition_TRACE_SUCCESS.String()), Value: strings.ToLower(pb.TraceStatusCondition_TRACE_SUCCESS.String())}, | ||
{Key: strings.ToLower(pb.TraceStatusCondition_TRACE_ERROR.String()), Value: strings.ToLower(pb.TraceStatusCondition_TRACE_ERROR.String())}, | ||
} | ||
|
||
var TraceQueryConditions = pb.TraceQueryConditions{ | ||
Sort: sortConditions, | ||
Limit: limitConditions, | ||
TraceStatus: TraceStatusConditions, | ||
Others: []*pb.OtherTraceQueryCondition{ | ||
{Key: strings.ToLower(pb.OtherCondition_SERVICE_NAME.String()), ParamKey: "serviceName", Type: string(INPUT)}, | ||
{Key: strings.ToLower(pb.OtherCondition_TRACE_ID.String()), ParamKey: "traceID", Type: string(INPUT)}, | ||
{Key: strings.ToLower(pb.OtherCondition_DUBBO_METHOD.String()), ParamKey: "dubboMethod", Type: string(INPUT)}, | ||
{Key: strings.ToLower(pb.OtherCondition_HTTP_PATH.String()), ParamKey: "httpPath", Type: string(INPUT)}, | ||
}, | ||
} | ||
|
||
func TranslateCondition(i18n i18n.Translator, lang i18n.LanguageCodes, key string) string { | ||
if lang == nil { | ||
return key | ||
} | ||
return i18n.Text(lang, strings.ToLower(key)) | ||
} | ||
|
||
func DepthCopyQueryConditions() *pb.TraceQueryConditions { | ||
conditions, err := clone(&TraceQueryConditions) | ||
if err != nil { | ||
return nil | ||
} | ||
return conditions | ||
} | ||
|
||
func clone(src *pb.TraceQueryConditions) (*pb.TraceQueryConditions, error) { | ||
var dst pb.TraceQueryConditions | ||
buffer, _ := json.Marshal(&src) | ||
err := json.Unmarshal(buffer, &dst) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &dst, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package query | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/erda-project/erda-infra/providers/i18n" | ||
"github.com/erda-project/erda-proto-go/msp/apm/trace/pb" | ||
) | ||
|
||
func TestDepthCopyQueryConditions(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
want *pb.TraceQueryConditions | ||
}{ | ||
{"case1", &TraceQueryConditions}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := DepthCopyQueryConditions() | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("DepthCopyQueryConditions() = %v, want %v", got, tt.want) | ||
} | ||
// got point | ||
gotPoint := getMemoryPoint(got) | ||
gotPointOthers := getMemoryPoint(got.Others) | ||
gotPointLimit := getMemoryPoint(got.Limit) | ||
gotPointSort := getMemoryPoint(got.Sort) | ||
gotPointTraceStatus := getMemoryPoint(got.TraceStatus) | ||
|
||
// TraceQueryConditions point | ||
wantPoint := getMemoryPoint(tt.want) | ||
wantPointOthers := getMemoryPoint(tt.want.Others) | ||
wantPointLimit := getMemoryPoint(tt.want.Limit) | ||
wantPointSort := getMemoryPoint(tt.want.Sort) | ||
wantPointTraceStatus := getMemoryPoint(tt.want.TraceStatus) | ||
|
||
if gotPoint == wantPoint { | ||
t.Errorf("gotPointServiceName = %v, wantPointServiceName %v", gotPoint, wantPoint) | ||
} | ||
if gotPointOthers == wantPointOthers { | ||
t.Errorf("gotPointOthers = %v, wantPointOthers %v", gotPointOthers, wantPointOthers) | ||
} | ||
if gotPointLimit == wantPointLimit { | ||
t.Errorf("gotPointServiceName = %v, wantPointServiceName %v", gotPointLimit, wantPointLimit) | ||
} | ||
if gotPointSort == wantPointSort { | ||
t.Errorf("gotPointServiceName = %v, wantPointServiceName %v", gotPointSort, wantPointSort) | ||
} | ||
if gotPointTraceStatus == wantPointTraceStatus { | ||
t.Errorf("gotPointServiceName = %v, wantPointServiceName %v", gotPointTraceStatus, wantPointTraceStatus) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func getMemoryPoint(need interface{}) string { | ||
return fmt.Sprintf("%p", need) | ||
} | ||
|
||
func Test_clone(t *testing.T) { | ||
type args struct { | ||
src *pb.TraceQueryConditions | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *pb.TraceQueryConditions | ||
wantErr bool | ||
}{ | ||
{"case1", args{src: &TraceQueryConditions}, &TraceQueryConditions, false}, | ||
{"case2", args{src: nil}, &TraceQueryConditions, true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := clone(tt.args.src) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("clone() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if err != nil { | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("clone() got = %v, want %v", got, tt.want) | ||
} | ||
gotPoint := getMemoryPoint(got) | ||
wantPoint := getMemoryPoint(tt.want) | ||
if gotPoint == wantPoint { | ||
t.Errorf("gotPointServiceName = %v, wantPointServiceName %v", gotPoint, wantPoint) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestTranslateCondition(t *testing.T) { | ||
type args struct { | ||
i18n i18n.Translator | ||
lang i18n.LanguageCodes | ||
key string | ||
} | ||
i18n := new(i18n.Translator) | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{"case1", args{i18n: *i18n, lang: nil, key: "test"}, "test"}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := TranslateCondition(tt.args.i18n, tt.args.lang, tt.args.key); got != tt.want { | ||
t.Errorf("TranslateCondition() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.