From c65f4648418629ad696ab71d1b0d244b42001f3f Mon Sep 17 00:00:00 2001 From: Mrproliu <741550557@qq.com> Date: Thu, 21 Oct 2021 16:11:52 +0800 Subject: [PATCH 1/4] Support `getProfileTaskLogs` query --- .../profile/GetProfileTaskLogs.graphql | 26 +++++++++ internal/commands/profile/getTaskLogs.go | 55 +++++++++++++++++++ internal/commands/profile/profile.go | 1 + pkg/graphql/profile/profile.go | 11 ++++ 4 files changed, 93 insertions(+) create mode 100644 assets/graphqls/profile/GetProfileTaskLogs.graphql create mode 100644 internal/commands/profile/getTaskLogs.go diff --git a/assets/graphqls/profile/GetProfileTaskLogs.graphql b/assets/graphqls/profile/GetProfileTaskLogs.graphql new file mode 100644 index 00000000..432b7b72 --- /dev/null +++ b/assets/graphqls/profile/GetProfileTaskLogs.graphql @@ -0,0 +1,26 @@ +# 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: getProfileTaskLogs(taskID: $taskID) { + id + instanceId + instanceName + operationType + operationTime + } +} diff --git a/internal/commands/profile/getTaskLogs.go b/internal/commands/profile/getTaskLogs.go new file mode 100644 index 00000000..75ce8966 --- /dev/null +++ b/internal/commands/profile/getTaskLogs.go @@ -0,0 +1,55 @@ +// 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 profile + +import ( + "github.com/apache/skywalking-cli/pkg/display" + "github.com/apache/skywalking-cli/pkg/display/displayable" + "github.com/apache/skywalking-cli/pkg/graphql/profile" + + "github.com/urfave/cli/v2" +) + +var getTaskLogListCommand = &cli.Command{ + Name: "logs", + Aliases: []string{"logs"}, + ArgsUsage: "[parameters...]", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "task-id", + Usage: "profile task id.", + }, + }, + Usage: "Query profile task log list", + UsageText: `Query profile task log list + +Examples: +1. Query all profile task logs +$ swctl profile logs --task-id=task-id`, + Action: func(ctx *cli.Context) error { + taskID := ctx.String("task-id") + + task, err := profile.GetTaskLogList(ctx, taskID) + + if err != nil { + return err + } + + return display.Display(ctx, &displayable.Displayable{Data: task, Condition: taskID}) + }, +} diff --git a/internal/commands/profile/profile.go b/internal/commands/profile/profile.go index 2483d789..feffabde 100644 --- a/internal/commands/profile/profile.go +++ b/internal/commands/profile/profile.go @@ -31,6 +31,7 @@ on https://github.com/apache/skywalking/blob/master/docs/en/guides/backend-profi Subcommands: []*cli.Command{ createCommand, getTaskListCommand, + getTaskLogListCommand, getTaskSegmentListCommand, getProfiledSegmentCommand, getProfiledAnalyzeCommand, diff --git a/pkg/graphql/profile/profile.go b/pkg/graphql/profile/profile.go index 98006663..76ee2987 100644 --- a/pkg/graphql/profile/profile.go +++ b/pkg/graphql/profile/profile.go @@ -51,6 +51,17 @@ func GetTaskList(ctx *cli.Context, serviceID, endpointName string) ([]*api.Profi return response["result"], err } +func GetTaskLogList(ctx *cli.Context, taskID string) ([]*api.ProfileTaskLog, error) { + var response map[string][]*api.ProfileTaskLog + + request := graphql.NewRequest(assets.Read("graphqls/profile/GetProfileTaskLogs.graphql")) + request.Var("taskID", taskID) + + err := client.ExecuteQuery(ctx, request, &response) + + return response["result"], err +} + func GetTaskSegmentList(ctx *cli.Context, taskID string) ([]*api.BasicTrace, error) { var response map[string][]*api.BasicTrace From ccb91054c9249b19ba92be49f53d1e0e86875606 Mon Sep 17 00:00:00 2001 From: Mrproliu <741550557@qq.com> Date: Thu, 21 Oct 2021 16:20:20 +0800 Subject: [PATCH 2/4] Remove useless field setting --- internal/commands/profile/getTaskLogs.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/commands/profile/getTaskLogs.go b/internal/commands/profile/getTaskLogs.go index 75ce8966..9500f90d 100644 --- a/internal/commands/profile/getTaskLogs.go +++ b/internal/commands/profile/getTaskLogs.go @@ -26,9 +26,8 @@ import ( ) var getTaskLogListCommand = &cli.Command{ - Name: "logs", - Aliases: []string{"logs"}, - ArgsUsage: "[parameters...]", + Name: "logs", + Aliases: []string{"logs"}, Flags: []cli.Flag{ &cli.StringFlag{ Name: "task-id", From b7aeb26e613badc7d005c507842358a062477dae Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Thu, 21 Oct 2021 21:10:34 +0800 Subject: [PATCH 3/4] Update internal/commands/profile/getTaskLogs.go --- internal/commands/profile/getTaskLogs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/commands/profile/getTaskLogs.go b/internal/commands/profile/getTaskLogs.go index 9500f90d..de740091 100644 --- a/internal/commands/profile/getTaskLogs.go +++ b/internal/commands/profile/getTaskLogs.go @@ -38,7 +38,7 @@ var getTaskLogListCommand = &cli.Command{ UsageText: `Query profile task log list Examples: -1. Query all profile task logs +1. Query all profile logs of task id `task-id` $ swctl profile logs --task-id=task-id`, Action: func(ctx *cli.Context) error { taskID := ctx.String("task-id") From a7d01cf084b36d06c6d95baec011048df6c44b1e Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Thu, 21 Oct 2021 21:12:04 +0800 Subject: [PATCH 4/4] Update getTaskLogs.go --- internal/commands/profile/getTaskLogs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/commands/profile/getTaskLogs.go b/internal/commands/profile/getTaskLogs.go index de740091..2b7d0e61 100644 --- a/internal/commands/profile/getTaskLogs.go +++ b/internal/commands/profile/getTaskLogs.go @@ -38,7 +38,7 @@ var getTaskLogListCommand = &cli.Command{ UsageText: `Query profile task log list Examples: -1. Query all profile logs of task id `task-id` +1. Query all profile logs of task id "task-id" $ swctl profile logs --task-id=task-id`, Action: func(ctx *cli.Context) error { taskID := ctx.String("task-id")