Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Async Profiler Feature #203

Merged
merged 27 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
go-version: 1.18

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
version: v1.50.0
args: --timeout 5m
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Release Notes.

### Features

* add the sub-command `profiling async` for async-profiler query API by @zhengziyi0117 in https://github.com/apache/skywalking-cli/pull/203

### Bug Fixes

0.14.0
Expand Down
24 changes: 24 additions & 0 deletions assets/graphqls/profiling/asyncprofiler/CreateTask.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Licensed to Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Apache Software Foundation (ASF) licenses this file to you 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.

mutation ($condition: AsyncProfilerTaskCreationRequest!) {
result: createAsyncProfilerTask(asyncProfilerTaskCreationRequest: $condition) {
errorReason
code
id
}
}
31 changes: 31 additions & 0 deletions assets/graphqls/profiling/asyncprofiler/GetAnalysis.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Licensed to Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Apache Software Foundation (ASF) licenses this file to you 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.

query ($condition: AsyncProfilerAnalyzationRequest!) {
result: queryAsyncProfilerAnalyze(request: $condition) {
tree {
type
elements {
id
parentId
codeSignature
total
self
}
}
}
}
31 changes: 31 additions & 0 deletions assets/graphqls/profiling/asyncprofiler/GetTaskList.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Licensed to Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Apache Software Foundation (ASF) licenses this file to you 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.

query ($condition: AsyncProfilerTaskListRequest!) {
result: queryAsyncProfilerTaskList(request: $condition) {
errorReason
tasks {
serviceId
serviceInstanceIds
createTime
events
duration
execArgs
id
}
}
}
30 changes: 30 additions & 0 deletions assets/graphqls/profiling/asyncprofiler/GetTaskProgress.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Licensed to Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Apache Software Foundation (ASF) licenses this file to you 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.

query ($taskId: String!){
result: queryAsyncProfilerTaskProgress(taskId: $taskId) {
errorInstanceIds
successInstanceIds
logs {
id
instanceId
instanceName
operationType
operationTime
}
}
}
2 changes: 1 addition & 1 deletion dist/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ The text of each license is also included at licenses/license-[project].txt.
k8s.io/utils v0.0.0-20210802155522-efc7438f0176 Apache-2.0
sigs.k8s.io/controller-runtime v0.10.0 Apache-2.0
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 Apache-2.0
skywalking.apache.org/repo/goapi v0.0.0-20240227092755-edee3273b361 Apache-2.0
skywalking.apache.org/repo/goapi v0.0.0-20241023080050-2514649a8007 Apache-2.0

========================================================================
BSD-2-Clause licenses
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
gopkg.in/yaml.v2 v2.4.0
k8s.io/apimachinery v0.22.1
sigs.k8s.io/controller-runtime v0.10.0
skywalking.apache.org/repo/goapi v0.0.0-20240227092755-edee3273b361
skywalking.apache.org/repo/goapi v0.0.0-20241023080050-2514649a8007
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -879,5 +879,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.1.2 h1:Hr/htKFmJEbtMgS/UD0N+gtgctAqz81t3
sigs.k8s.io/structured-merge-diff/v4 v4.1.2/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
skywalking.apache.org/repo/goapi v0.0.0-20240227092755-edee3273b361 h1:FCGGU4Tut3LI/zMRXSgJgUL/kmSQ4b7QktFgRBhqaDs=
skywalking.apache.org/repo/goapi v0.0.0-20240227092755-edee3273b361/go.mod h1:+n8BMuS8eRdzdnGh15ElRGBXPi0eYZSs2TKySBDmRTE=
skywalking.apache.org/repo/goapi v0.0.0-20241023080050-2514649a8007 h1:MQU9yOZxgbs7fU145wd400/E3ES/HWoxTtTCudaCBoA=
skywalking.apache.org/repo/goapi v0.0.0-20241023080050-2514649a8007/go.mod h1:+n8BMuS8eRdzdnGh15ElRGBXPi0eYZSs2TKySBDmRTE=
99 changes: 86 additions & 13 deletions internal/commands/interceptor/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const (
instanceNameFlagName = "instance-name"
destInstanceIDFlagName = "dest-instance-id"
destInstanceNameFlagName = "dest-instance-name"
InstanceIDListFlagName = "instance-id-list"
instanceNameListFlagName = "instance-name-list"
)

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

// ParseInstanceList parses the service instance id slice or service instance name slice,
// and converts the present one to the missing one.
// See flags.InstanceSliceFlags.
func ParseInstanceList(required bool) func(*cli.Context) error {
return func(ctx *cli.Context) error {
if err := ParseService(required)(ctx); err != nil {
return err
}
return parseInstanceList(required, InstanceIDListFlagName, instanceNameListFlagName, serviceIDFlagName)(ctx)
}
}

// ParseInstanceRelation parses the source and destination service instance id or service instance name,
// and converts the present one to the missing one respectively.
// See flags.InstanceRelationFlags.
Expand Down Expand Up @@ -72,26 +86,85 @@ func parseInstance(required bool, idFlagName, nameFlagName, serviceIDFlagName st
return nil
}

if id != "" {
parts := strings.Split(id, "_")
if len(parts) != 2 {
return fmt.Errorf("invalid instance id, cannot be splitted into 2 parts. %v", id)
id, name, err := encode(serviceID, nameFlagName, id, name)
if err != nil {
return err
}

if err := ctx.Set(idFlagName, id); err != nil {
return err
}
return ctx.Set(nameFlagName, name)
}
}

func parseInstanceList(required bool, idListFlagName, nameListFlagName, serviceIDFlagName string) func(*cli.Context) error {
return func(ctx *cli.Context) error {
idsArg := ctx.String(idListFlagName)
namesArgs := ctx.String(nameListFlagName)
serviceID := ctx.String(serviceIDFlagName)

if idsArg == "" && namesArgs == "" {
if required {
return fmt.Errorf(`either flags "--%s" or "--%s" must be given`, idListFlagName, nameListFlagName)
}
return nil
}

ids := strings.Split(idsArg, ",")
names := strings.Split(namesArgs, ",")
var sliceSize int
if l := len(ids); idsArg != "" && l != 0 {
sliceSize = l
} else {
sliceSize = len(names)
}
instanceIDSlice := make([]string, sliceSize)
instanceNameSlice := make([]string, sliceSize)
for i := 0; i < sliceSize; i++ {
id := ""
name := ""
if len(ids) > i {
id = ids[i]
}
if len(names) > i {
name = names[i]
}
s, err := base64.StdEncoding.DecodeString(parts[1])

id, name, err := encode(serviceID, nameListFlagName, id, name)
if err != nil {
return err
}
name = string(s)
} else if name != "" {
if serviceID == "" {
return fmt.Errorf(`"--%s" is specified but its related service name or id is not given`, nameFlagName)
}
id = serviceID + "_" + b64enc(name)

instanceIDSlice[i] = id
instanceNameSlice[i] = name
}

if err := ctx.Set(idFlagName, id); err != nil {
instanceIDSliceString := strings.Join(instanceIDSlice, ",")
instanceNameSliceString := strings.Join(instanceNameSlice, ",")
if err := ctx.Set(idListFlagName, instanceIDSliceString); err != nil {
return err
}
return ctx.Set(nameFlagName, name)
return ctx.Set(nameListFlagName, instanceNameSliceString)
}
}

func encode(serviceID, nameFlagName, id, name string) (encodedID, encodedName string, err error) {
if id != "" {
parts := strings.Split(id, "_")
if len(parts) != 2 {
return "", "", fmt.Errorf("invalid instance id, cannot be splitted into 2 parts. %v", id)
}
s, err := base64.StdEncoding.DecodeString(parts[1])
if err != nil {
return "", "", err
}
name = string(s)
} else if name != "" {
if serviceID == "" {
return "", "", fmt.Errorf(`"--%s" is specified but its related service name or id is not given`, nameFlagName)
}
id = serviceID + "_" + b64enc(name)
}
return id, name, nil
}
34 changes: 34 additions & 0 deletions internal/commands/profiling/asyncprofiler/asyncprofiler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to Apache Software Foundation (ASF) under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Apache Software Foundation (ASF) licenses this file to you 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 asyncprofiler

import "github.com/urfave/cli/v2"

var Command = &cli.Command{
Name: "async",
Usage: "async profiler related sub-command",
UsageText: `If your endpoint has performance issue and could not use tracing to find out what's happening,
you could try it. You could get more information
on https://skywalking.apache.org/docs/main/next/en/concepts-and-designs/profiling.`,
Subcommands: []*cli.Command{
createCommand,
getTaskListCommand,
getTaskProgressCommand,
analysisCommand,
},
}
Loading
Loading