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..2b7d0e61 --- /dev/null +++ b/internal/commands/profile/getTaskLogs.go @@ -0,0 +1,54 @@ +// 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"}, + 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 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