You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2021/10/21 13:17:33 UTC

[skywalking-cli] branch master updated: Support `getProfileTaskLogs` query (#125)

This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-cli.git


The following commit(s) were added to refs/heads/master by this push:
     new 7dfb10b  Support `getProfileTaskLogs` query (#125)
7dfb10b is described below

commit 7dfb10bf79f463f16037e1ac352a8b2f5da6f27e
Author: mrproliu <74...@qq.com>
AuthorDate: Thu Oct 21 21:17:26 2021 +0800

    Support `getProfileTaskLogs` query (#125)
    
    Add `getProfileTaskLogs` to query logs of profile task
---
 assets/graphqls/profile/GetProfileTaskLogs.graphql | 26 ++++++++++++++
 .../profile/{profile.go => getTaskLogs.go}         | 42 +++++++++++++++-------
 internal/commands/profile/profile.go               |  1 +
 pkg/graphql/profile/profile.go                     | 11 ++++++
 4 files changed, 67 insertions(+), 13 deletions(-)

diff --git a/assets/graphqls/profile/GetProfileTaskLogs.graphql b/assets/graphqls/profile/GetProfileTaskLogs.graphql
new file mode 100644
index 0000000..432b7b7
--- /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/profile.go b/internal/commands/profile/getTaskLogs.go
similarity index 53%
copy from internal/commands/profile/profile.go
copy to internal/commands/profile/getTaskLogs.go
index 2483d78..2b7d0e6 100644
--- a/internal/commands/profile/profile.go
+++ b/internal/commands/profile/getTaskLogs.go
@@ -18,21 +18,37 @@
 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 Command = &cli.Command{
-	Name:  "profile",
-	Usage: "Profile related sub-command",
-	UsageText: `If your endpoint has performance issue and could not use tracing to find out what's happening,
-you could try to profile. You could get more information
-on https://github.com/apache/skywalking/blob/master/docs/en/guides/backend-profile.md.
-`,
-	Subcommands: []*cli.Command{
-		createCommand,
-		getTaskListCommand,
-		getTaskSegmentListCommand,
-		getProfiledSegmentCommand,
-		getProfiledAnalyzeCommand,
+var getTaskLogListCommand = &cli.Command{
+	Name:    "logs",
+	Aliases: []string{"logs"},
+	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 logs of task id "task-id"
+$ 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 2483d78..feffabd 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 9800666..76ee298 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