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

Add commands for support network profiling #158

Merged
merged 5 commits into from
Jul 14, 2022
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Release Notes.
- [Breaking Change] Remove `total` field in `trace list` and `logs list` commands.(#152)
- [Breaking Change] Remove `total` field in `event list`, `browser logs list`, `alarm list` commands.(#153)
- Add `aggregate` flag in `profiling ebpf analysis` commands.(#154)
- Add the sub-command `profiling ebpf create network` and `profiling ebpf keep network` to create and keep the network eBPF profiling task.(#158)
- Add the sub-command `dependency process` to query the process relation.(#158)
- Support query the metrics of process relation.(#158)

0.10.0
------------------
Expand Down
36 changes: 36 additions & 0 deletions assets/graphqls/dependency/ProcessTopology.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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 ($serviceInstanceId: ID!, $duration: Duration!){
result: getProcessTopology(serviceInstanceId: $serviceInstanceId, duration: $duration) {
nodes {
id
serviceId
serviceName
serviceInstanceId
serviceInstanceName
name
isReal
}
calls {
source
target
id
detectPoints
}
}
}
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 ($request: EBPFProfilingNetworkTaskRequest!){
result: createEBPFNetworkProfiling(request: $request) {
status
id
errorReason
}
}
23 changes: 23 additions & 0 deletions assets/graphqls/profiling/ebpf/KeepNetworkProfilingTask.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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 ($taskId: ID!){
result: keepEBPFNetworkProfiling(taskId: $taskId) {
status
errorReason
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ require (
gopkg.in/yaml.v2 v2.4.0
k8s.io/apimachinery v0.21.1
sigs.k8s.io/controller-runtime v0.7.0
skywalking.apache.org/repo/goapi v0.0.0-20220519102801-965f76fbe437
skywalking.apache.org/repo/goapi v0.0.0-20220714130828-0d56d1f4c592
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -950,5 +950,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.1.0/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
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-20220519102801-965f76fbe437 h1:tWUESKwKU50ZEzQJsOQv50qPvPHj72MjIxFwgeoM7Hg=
skywalking.apache.org/repo/goapi v0.0.0-20220519102801-965f76fbe437/go.mod h1:uWwwvhcwe2MD/nJCg0c1EE/eL6KzaBosLHDfMFoEJ30=
skywalking.apache.org/repo/goapi v0.0.0-20220714130828-0d56d1f4c592 h1:3UbXoMUpGBoYLvuUCaKPzlHCM9Q+enaaOcQ19QbTDr8=
skywalking.apache.org/repo/goapi v0.0.0-20220714130828-0d56d1f4c592/go.mod h1:uWwwvhcwe2MD/nJCg0c1EE/eL6KzaBosLHDfMFoEJ30=
1 change: 1 addition & 0 deletions internal/commands/dependency/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ var Command = &cli.Command{
EndpointCommand,
ServiceCommand,
InstanceCommand,
ProcessCommand,
},
}
67 changes: 67 additions & 0 deletions internal/commands/dependency/process.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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 dependency

import (
"github.com/apache/skywalking-cli/internal/commands/interceptor"
"github.com/apache/skywalking-cli/internal/flags"
"github.com/apache/skywalking-cli/internal/model"
"github.com/apache/skywalking-cli/pkg/display"
"github.com/apache/skywalking-cli/pkg/display/displayable"
"github.com/apache/skywalking-cli/pkg/graphql/dependency"

"github.com/urfave/cli/v2"

api "skywalking.apache.org/repo/goapi/query"
)

var ProcessCommand = &cli.Command{
Name: "process",
Aliases: []string{"pros"},
Usage: "Query the process topology, based on the given service instance",
Flags: flags.Flags(
flags.DurationFlags,
flags.ServiceRelationFlags,
flags.InstanceRelationFlags,
),
Before: interceptor.BeforeChain(
interceptor.DurationInterceptor,
interceptor.ParseInstance(true),
),

Action: func(ctx *cli.Context) error {
instanceID := ctx.String("instance-id")

end := ctx.String("end")
start := ctx.String("start")
step := ctx.Generic("step")

duration := api.Duration{
Start: start,
End: end,
Step: step.(*model.StepEnumValue).Selected,
}

dependency, err := dependency.ProcessTopology(ctx, instanceID, duration)
if err != nil {
return err
}

return display.Display(ctx, &displayable.Displayable{Data: dependency})
},
}
12 changes: 12 additions & 0 deletions internal/commands/interceptor/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ func ParseEntity(ctx *cli.Context) (*api.Entity, error) {
serviceID := ctx.String("service-id")
instance := ctx.String("instance-name")
endpoint := ctx.String("endpoint-name")
process := ctx.String("process-name")

destServiceID := ctx.String("dest-service-id")
destInstance := ctx.String("dest-instance-name")
destEndpoint := ctx.String("dest-endpoint-name")
destProcess := ctx.String("dest-process-name")

serviceName, isNormal, err := ParseServiceID(serviceID)
if err != nil {
Expand All @@ -56,13 +58,23 @@ func ParseEntity(ctx *cli.Context) (*api.Entity, error) {
Normal: &isNormal,
ServiceInstanceName: &instance,
EndpointName: &endpoint,
ProcessName: &process,
DestServiceName: &destServiceName,
DestNormal: &destIsNormal,
DestServiceInstanceName: &destInstance,
DestEndpointName: &destEndpoint,
DestProcessName: &destProcess,
}
entity.Scope = utils.ParseScope(entity)

// adapt for the old version of backend
if *entity.ProcessName == "" {
entity.ProcessName = nil
}
if *entity.DestProcessName == "" {
entity.DestProcessName = nil
}

if logger.Log.GetLevel() <= logrus.DebugLevel {
s, _ := json.Marshal(&entity)
logger.Log.Debugf("entity: %+v", string(s))
Expand Down
91 changes: 91 additions & 0 deletions internal/commands/interceptor/process.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// 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 interceptor

import (
"crypto/sha256"
"fmt"

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

const (
processIDFlagName = "process-id"
processNameFlagName = "process-name"
destProcessNameFlagName = "dest-process-name"
)

// ParseProcess parses the process id or process name,
// and converts the present one to the missing one.
// See flags.InstanceFlags.
func ParseProcess(required bool) func(*cli.Context) error {
return func(ctx *cli.Context) error {
if err := ParseService(required)(ctx); err != nil {
return err
}
if err := ParseInstance(required)(ctx); err != nil {
return err
}
return parseProcess(required, processIDFlagName, processNameFlagName, instanceIDFlagName)(ctx)
}
}

// ParseProcessRelation 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.
func ParseProcessRelation(required bool) func(*cli.Context) error {
return func(ctx *cli.Context) error {
if err := ParseService(required)(ctx); err != nil {
return err
}
if err := ParseInstance(required)(ctx); err != nil {
return err
}
if err := ParseProcess(required)(ctx); err != nil {
return err
}
if ctx.String(destProcessNameFlagName) == "" && required {
return fmt.Errorf(`flag "--%s" must given`, destProcessNameFlagName)
}
return nil
}
}

func parseProcess(required bool, idFlagName, nameFlagName, instanceIDFlagName string) func(*cli.Context) error {
return func(ctx *cli.Context) error {
id := ctx.String(idFlagName)
name := ctx.String(nameFlagName)
instanceID := ctx.String(instanceIDFlagName)

if id == "" && name == "" {
if required {
return fmt.Errorf(`either flags "--%s" or "--%s" must be given`, idFlagName, nameFlagName)
}
return nil
}

if name != "" {
if instanceID == "" {
return fmt.Errorf(`"--%s" is specified but its related service name or id is not given`, nameFlagName)
}
id = fmt.Sprintf("%x", sha256.New().Sum([]byte(fmt.Sprintf("%s_%s", instanceID, name))))
}

return ctx.Set(idFlagName, id)
}
}
2 changes: 2 additions & 0 deletions internal/commands/metrics/linear/linear-metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ $ swctl metrics linear --name=service_relation_client_cpm --service-name consume
flags.MetricsFlags,
flags.InstanceRelationFlags,
flags.EndpointRelationFlags,
flags.ProcessRelationFlags,
),
Before: interceptor.BeforeChain(
interceptor.DurationInterceptor,
interceptor.ParseEndpointRelation(false),
interceptor.ParseInstanceRelation(false),
interceptor.ParseProcessRelation(false),
),
Action: func(ctx *cli.Context) error {
end := ctx.String("end")
Expand Down
2 changes: 2 additions & 0 deletions internal/commands/metrics/linear/multiple-linear-metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ $ swctl metrics multiple-linear --name all_percentile --labels=0,1,2,3,4 --relab
flags.MetricsFlags,
flags.InstanceRelationFlags,
flags.EndpointRelationFlags,
flags.ProcessRelationFlags,
[]cli.Flag{
&cli.StringFlag{
Name: "labels",
Expand All @@ -71,6 +72,7 @@ $ swctl metrics multiple-linear --name all_percentile --labels=0,1,2,3,4 --relab
interceptor.DurationInterceptor,
interceptor.ParseEndpointRelation(false),
interceptor.ParseInstanceRelation(false),
interceptor.ParseProcessRelation(false),
),
Action: func(ctx *cli.Context) error {
end := ctx.String("end")
Expand Down
2 changes: 2 additions & 0 deletions internal/commands/metrics/single/single-metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ $ swctl metrics single --name endpoint_cpm --service-name business-zone::project
flags.MetricsFlags,
flags.InstanceRelationFlags,
flags.EndpointRelationFlags,
flags.ProcessRelationFlags,
),
Before: interceptor.BeforeChain(
interceptor.DurationInterceptor,
interceptor.ParseEndpointRelation(false),
interceptor.ParseInstanceRelation(false),
interceptor.ParseProcessRelation(false),
),
Action: func(ctx *cli.Context) error {
end := ctx.String("end")
Expand Down
2 changes: 2 additions & 0 deletions internal/commands/metrics/thermodynamic/thermodynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ $ swctl metrics thermodynamic --scope all --name all_heatmap
flags.MetricsFlags,
flags.InstanceRelationFlags,
flags.EndpointRelationFlags,
flags.ProcessRelationFlags,
),
Before: interceptor.BeforeChain(
interceptor.DurationInterceptor,
interceptor.ParseEndpointRelation(false),
interceptor.ParseInstanceRelation(false),
interceptor.ParseProcessRelation(false),
),
Action: func(ctx *cli.Context) error {
end := ctx.String("end")
Expand Down
1 change: 1 addition & 0 deletions internal/commands/profiling/ebpf/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ var CreateCommand = &cli.Command{
Subcommands: []*cli.Command{
PrepareCreateCommand,
FixedTimeCreateCommand,
NetworkCreateCommand,
},
}
Loading