diff --git a/CHANGES.md b/CHANGES.md index c098d1e7..39f0e2a6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Release Notes. - Update the sub-command `process list/get` to add the `labels` field.(#141) - Add the sub-command `profiling ebpf create prepare` to query data for prepare creating task.(#141) - Add the sub-command `process estimate scale` to estimate the process scale.(#142) +- Update the `process list` to must be provided the instance and duration.(#144) 0.10.0 ------------------ diff --git a/assets/graphqls/metadata/v2/EstimateProcessScale.graphql b/assets/graphqls/metadata/v2/EstimateProcessScale.graphql index 4ac94917..ab62f639 100644 --- a/assets/graphqls/metadata/v2/EstimateProcessScale.graphql +++ b/assets/graphqls/metadata/v2/EstimateProcessScale.graphql @@ -15,6 +15,6 @@ # specific language governing permissions and limitations # under the License. -query ($serviceId: ID!, $labels: [String!]!, $duration: Duration!) { - result: estimateProcessScale(serviceId: $serviceId, labels: $labels, duration: $duration) +query ($serviceId: ID!, $labels: [String!]!) { + result: estimateProcessScale(serviceId: $serviceId, labels: $labels) } \ No newline at end of file diff --git a/assets/graphqls/metadata/v2/Processes.graphql b/assets/graphqls/metadata/v2/Processes.graphql index adc74f75..b0befbff 100644 --- a/assets/graphqls/metadata/v2/Processes.graphql +++ b/assets/graphqls/metadata/v2/Processes.graphql @@ -15,8 +15,8 @@ # specific language governing permissions and limitations # under the License. -query ($serviceId: ID, $instanceId: ID) { - result: listProcesses(serviceId: $serviceId, instanceId: $instanceId) { +query ($instanceId: ID!, $duration: Duration!) { + result: listProcesses(instanceId: $instanceId, duration: $duration) { id name serviceId serviceName instanceId instanceName layer agentId detectType labels attributes { name value } } } \ No newline at end of file diff --git a/internal/commands/process/estimate/scale.go b/internal/commands/process/estimate/scale.go index 82a3b3ea..77d55099 100644 --- a/internal/commands/process/estimate/scale.go +++ b/internal/commands/process/estimate/scale.go @@ -20,13 +20,10 @@ package estimate import ( "strings" - api "skywalking.apache.org/repo/goapi/query" - "github.com/urfave/cli/v2" "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/metadata" @@ -42,7 +39,6 @@ Examples: $ swctl process estimate scale --service-name abc --labels t1,t2`, Flags: flags.Flags( flags.ServiceFlags, - flags.DurationFlags, []cli.Flag{ &cli.StringFlag{ Name: "labels", @@ -52,12 +48,8 @@ $ swctl process estimate scale --service-name abc --labels t1,t2`, ), Before: interceptor.BeforeChain( interceptor.ParseService(true), - interceptor.DurationInterceptor, ), Action: func(ctx *cli.Context) error { - end := ctx.String("end") - start := ctx.String("start") - step := ctx.Generic("step") serviceID := ctx.String("service-id") labelString := ctx.String("labels") labels := make([]string, 0) @@ -65,11 +57,7 @@ $ swctl process estimate scale --service-name abc --labels t1,t2`, labels = strings.Split(labelString, ",") } - scale, err := metadata.EstimateProcessScale(ctx, serviceID, labels, api.Duration{ - Start: start, - End: end, - Step: step.(*model.StepEnumValue).Selected, - }) + scale, err := metadata.EstimateProcessScale(ctx, serviceID, labels) if err != nil { return err diff --git a/internal/commands/process/list.go b/internal/commands/process/list.go index 2faca351..3fea5e03 100644 --- a/internal/commands/process/list.go +++ b/internal/commands/process/list.go @@ -18,12 +18,13 @@ package process import ( - "fmt" - "github.com/urfave/cli/v2" + api "skywalking.apache.org/repo/goapi/query" + "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/metadata" @@ -32,16 +33,10 @@ import ( var ListCommand = &cli.Command{ Name: "list", Aliases: []string{"ls"}, - Usage: `list all monitored processes of the given id or name in service or instance`, - UsageText: `This command lists all processes of the service-instance, via id or name in service or instance. + Usage: `list all monitored processes under the instance`, + UsageText: `This command lists all processes of the service-instance. Examples: -1. List all processes by service name "provider": -$ swctl process ls --service-name provider - -2. List all processes by service id "YnVzaW5lc3Mtem9uZTo6cHJvamVjdEM=.1": -$ swctl process ls --service-id YnVzaW5lc3Mtem9uZTo6cHJvamVjdEM=.1 - 3. List all processes by instance name "provider-01" and service name "provider": $ swctl process ls --instance-name provider-01 --service-name provider @@ -50,19 +45,23 @@ $ swctl process ls --instance-id cHJvdmlkZXI=.1_cHJvdmlkZXIx`, Flags: flags.Flags( flags.ServiceFlags, flags.InstanceFlags, + flags.DurationFlags, ), Before: interceptor.BeforeChain( - interceptor.ParseService(false), - interceptor.ParseInstance(false), + interceptor.ParseInstance(true), + interceptor.DurationInterceptor, ), Action: func(ctx *cli.Context) error { - serviceID := ctx.String("service-id") instanceID := ctx.String("instance-id") - if serviceID == "" && instanceID == "" { - return fmt.Errorf("service or instance must provide one") - } + end := ctx.String("end") + start := ctx.String("start") + step := ctx.Generic("step") - processes, err := metadata.Processes(ctx, serviceID, instanceID) + processes, err := metadata.Processes(ctx, instanceID, api.Duration{ + Start: start, + End: end, + Step: step.(*model.StepEnumValue).Selected, + }) if err != nil { return err } diff --git a/pkg/graphql/metadata/metadata.go b/pkg/graphql/metadata/metadata.go index 1926cdac..bebca2c5 100644 --- a/pkg/graphql/metadata/metadata.go +++ b/pkg/graphql/metadata/metadata.go @@ -174,12 +174,12 @@ func GetEndpointInfo(cliCtx *cli.Context, endpointID string) (api.EndpointInfo, return response["result"], err } -func Processes(cliCtx *cli.Context, serviceID, instanceID string) ([]api.Process, error) { +func Processes(cliCtx *cli.Context, instanceID string, duration api.Duration) ([]api.Process, error) { var response map[string][]api.Process request := graphql.NewRequest(assets.Read("graphqls/metadata/v2/Processes.graphql")) - request.Var("serviceId", serviceID) - request.Var("instanceID", instanceID) + request.Var("instanceId", instanceID) + request.Var("duration", duration) err := client.ExecuteQuery(cliCtx, request, &response) @@ -197,13 +197,12 @@ func GetProcess(cliCtx *cli.Context, processID string) (api.Process, error) { return response["result"], err } -func EstimateProcessScale(cliCtx *cli.Context, serviceID string, labels []string, duration api.Duration) (int64, error) { +func EstimateProcessScale(cliCtx *cli.Context, serviceID string, labels []string) (int64, error) { var response map[string]int64 request := graphql.NewRequest(assets.Read("graphqls/metadata/v2/EstimateProcessScale.graphql")) request.Var("serviceId", serviceID) request.Var("labels", labels) - request.Var("duration", duration) err := client.ExecuteQuery(cliCtx, request, &response)