Skip to content

Commit bce7faa

Browse files
Support Async Profiler Feature (#203)
1 parent c653be5 commit bce7faa

25 files changed

Lines changed: 773 additions & 18 deletions

File tree

.github/workflows/CI.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
go-version: 1.18
9191

9292
- name: golangci-lint
93-
uses: golangci/golangci-lint-action@v3
93+
uses: golangci/golangci-lint-action@v6
9494
with:
9595
version: v1.50.0
9696
args: --timeout 5m

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Release Notes.
77

88
### Features
99

10+
* add the sub-command `profiling async` for async-profiler query API by @zhengziyi0117 in https://github.com/apache/skywalking-cli/pull/203
11+
1012
### Bug Fixes
1113

1214
0.14.0
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
mutation ($condition: AsyncProfilerTaskCreationRequest!) {
19+
result: createAsyncProfilerTask(asyncProfilerTaskCreationRequest: $condition) {
20+
errorReason
21+
code
22+
id
23+
}
24+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
query ($condition: AsyncProfilerAnalyzationRequest!) {
19+
result: queryAsyncProfilerAnalyze(request: $condition) {
20+
tree {
21+
type
22+
elements {
23+
id
24+
parentId
25+
codeSignature
26+
total
27+
self
28+
}
29+
}
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
query ($condition: AsyncProfilerTaskListRequest!) {
19+
result: queryAsyncProfilerTaskList(request: $condition) {
20+
errorReason
21+
tasks {
22+
serviceId
23+
serviceInstanceIds
24+
createTime
25+
events
26+
duration
27+
execArgs
28+
id
29+
}
30+
}
31+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
query ($taskId: String!){
19+
result: queryAsyncProfilerTaskProgress(taskId: $taskId) {
20+
errorInstanceIds
21+
successInstanceIds
22+
logs {
23+
id
24+
instanceId
25+
instanceName
26+
operationType
27+
operationTime
28+
}
29+
}
30+
}

dist/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ The text of each license is also included at licenses/license-[project].txt.
213213
k8s.io/utils v0.0.0-20210802155522-efc7438f0176 Apache-2.0
214214
sigs.k8s.io/controller-runtime v0.10.0 Apache-2.0
215215
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 Apache-2.0
216-
skywalking.apache.org/repo/goapi v0.0.0-20240227092755-edee3273b361 Apache-2.0
216+
skywalking.apache.org/repo/goapi v0.0.0-20241023080050-2514649a8007 Apache-2.0
217217

218218
========================================================================
219219
BSD-2-Clause licenses

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
gopkg.in/yaml.v2 v2.4.0
1919
k8s.io/apimachinery v0.22.1
2020
sigs.k8s.io/controller-runtime v0.10.0
21-
skywalking.apache.org/repo/goapi v0.0.0-20240227092755-edee3273b361
21+
skywalking.apache.org/repo/goapi v0.0.0-20241023080050-2514649a8007
2222
)
2323

2424
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,5 +879,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.1.2 h1:Hr/htKFmJEbtMgS/UD0N+gtgctAqz81t3
879879
sigs.k8s.io/structured-merge-diff/v4 v4.1.2/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4=
880880
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
881881
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
882-
skywalking.apache.org/repo/goapi v0.0.0-20240227092755-edee3273b361 h1:FCGGU4Tut3LI/zMRXSgJgUL/kmSQ4b7QktFgRBhqaDs=
883-
skywalking.apache.org/repo/goapi v0.0.0-20240227092755-edee3273b361/go.mod h1:+n8BMuS8eRdzdnGh15ElRGBXPi0eYZSs2TKySBDmRTE=
882+
skywalking.apache.org/repo/goapi v0.0.0-20241023080050-2514649a8007 h1:MQU9yOZxgbs7fU145wd400/E3ES/HWoxTtTCudaCBoA=
883+
skywalking.apache.org/repo/goapi v0.0.0-20241023080050-2514649a8007/go.mod h1:+n8BMuS8eRdzdnGh15ElRGBXPi0eYZSs2TKySBDmRTE=

internal/commands/interceptor/instance.go

Lines changed: 86 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const (
3030
instanceNameFlagName = "instance-name"
3131
destInstanceIDFlagName = "dest-instance-id"
3232
destInstanceNameFlagName = "dest-instance-name"
33+
InstanceIDListFlagName = "instance-id-list"
34+
instanceNameListFlagName = "instance-name-list"
3335
)
3436

3537
// ParseInstance parses the service instance id or service instance name,
@@ -44,6 +46,18 @@ func ParseInstance(required bool) func(*cli.Context) error {
4446
}
4547
}
4648

49+
// ParseInstanceList parses the service instance id slice or service instance name slice,
50+
// and converts the present one to the missing one.
51+
// See flags.InstanceSliceFlags.
52+
func ParseInstanceList(required bool) func(*cli.Context) error {
53+
return func(ctx *cli.Context) error {
54+
if err := ParseService(required)(ctx); err != nil {
55+
return err
56+
}
57+
return parseInstanceList(required, InstanceIDListFlagName, instanceNameListFlagName, serviceIDFlagName)(ctx)
58+
}
59+
}
60+
4761
// ParseInstanceRelation parses the source and destination service instance id or service instance name,
4862
// and converts the present one to the missing one respectively.
4963
// See flags.InstanceRelationFlags.
@@ -72,26 +86,85 @@ func parseInstance(required bool, idFlagName, nameFlagName, serviceIDFlagName st
7286
return nil
7387
}
7488

75-
if id != "" {
76-
parts := strings.Split(id, "_")
77-
if len(parts) != 2 {
78-
return fmt.Errorf("invalid instance id, cannot be splitted into 2 parts. %v", id)
89+
id, name, err := encode(serviceID, nameFlagName, id, name)
90+
if err != nil {
91+
return err
92+
}
93+
94+
if err := ctx.Set(idFlagName, id); err != nil {
95+
return err
96+
}
97+
return ctx.Set(nameFlagName, name)
98+
}
99+
}
100+
101+
func parseInstanceList(required bool, idListFlagName, nameListFlagName, serviceIDFlagName string) func(*cli.Context) error {
102+
return func(ctx *cli.Context) error {
103+
idsArg := ctx.String(idListFlagName)
104+
namesArgs := ctx.String(nameListFlagName)
105+
serviceID := ctx.String(serviceIDFlagName)
106+
107+
if idsArg == "" && namesArgs == "" {
108+
if required {
109+
return fmt.Errorf(`either flags "--%s" or "--%s" must be given`, idListFlagName, nameListFlagName)
110+
}
111+
return nil
112+
}
113+
114+
ids := strings.Split(idsArg, ",")
115+
names := strings.Split(namesArgs, ",")
116+
var sliceSize int
117+
if l := len(ids); idsArg != "" && l != 0 {
118+
sliceSize = l
119+
} else {
120+
sliceSize = len(names)
121+
}
122+
instanceIDSlice := make([]string, sliceSize)
123+
instanceNameSlice := make([]string, sliceSize)
124+
for i := 0; i < sliceSize; i++ {
125+
id := ""
126+
name := ""
127+
if len(ids) > i {
128+
id = ids[i]
129+
}
130+
if len(names) > i {
131+
name = names[i]
79132
}
80-
s, err := base64.StdEncoding.DecodeString(parts[1])
133+
134+
id, name, err := encode(serviceID, nameListFlagName, id, name)
81135
if err != nil {
82136
return err
83137
}
84-
name = string(s)
85-
} else if name != "" {
86-
if serviceID == "" {
87-
return fmt.Errorf(`"--%s" is specified but its related service name or id is not given`, nameFlagName)
88-
}
89-
id = serviceID + "_" + b64enc(name)
138+
139+
instanceIDSlice[i] = id
140+
instanceNameSlice[i] = name
90141
}
91142

92-
if err := ctx.Set(idFlagName, id); err != nil {
143+
instanceIDSliceString := strings.Join(instanceIDSlice, ",")
144+
instanceNameSliceString := strings.Join(instanceNameSlice, ",")
145+
if err := ctx.Set(idListFlagName, instanceIDSliceString); err != nil {
93146
return err
94147
}
95-
return ctx.Set(nameFlagName, name)
148+
return ctx.Set(nameListFlagName, instanceNameSliceString)
149+
}
150+
}
151+
152+
func encode(serviceID, nameFlagName, id, name string) (encodedID, encodedName string, err error) {
153+
if id != "" {
154+
parts := strings.Split(id, "_")
155+
if len(parts) != 2 {
156+
return "", "", fmt.Errorf("invalid instance id, cannot be splitted into 2 parts. %v", id)
157+
}
158+
s, err := base64.StdEncoding.DecodeString(parts[1])
159+
if err != nil {
160+
return "", "", err
161+
}
162+
name = string(s)
163+
} else if name != "" {
164+
if serviceID == "" {
165+
return "", "", fmt.Errorf(`"--%s" is specified but its related service name or id is not given`, nameFlagName)
166+
}
167+
id = serviceID + "_" + b64enc(name)
96168
}
169+
return id, name, nil
97170
}

0 commit comments

Comments
 (0)