Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Release Notes.
- Add the sub-command `endpoint get` to query single endpoint info.(#134)
- Change the GraphQL method to the v9 version according to the server version.(#134)
- Add `normal` field to Service entity.(#136)
- Add the command `process` for query Process metadata.(#137)

### Bug Fixes

Expand Down
22 changes: 22 additions & 0 deletions assets/graphqls/metadata/v2/GetProcess.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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 ($processId: ID!) {
result: getProcess(processId: $processId) {
id name serviceId serviceName instanceId instanceName layer agentId detectType attributes { name value }
}
}
22 changes: 22 additions & 0 deletions assets/graphqls/metadata/v2/Processes.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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 ($serviceId: ID, $instanceId: ID) {
result: listProcesses(serviceId: $serviceId, instanceId: $instanceId) {
id name serviceId serviceName instanceId instanceName layer agentId detectType attributes { name value }
}
}
2 changes: 2 additions & 0 deletions cmd/swctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/apache/skywalking-cli/internal/commands/layer"
"github.com/apache/skywalking-cli/internal/commands/logs"
"github.com/apache/skywalking-cli/internal/commands/metrics"
"github.com/apache/skywalking-cli/internal/commands/process"
"github.com/apache/skywalking-cli/internal/commands/profile"
"github.com/apache/skywalking-cli/internal/commands/service"
"github.com/apache/skywalking-cli/internal/commands/trace"
Expand Down Expand Up @@ -100,6 +101,7 @@ services, service instances, etc.`
dependency.Command,
alarm.Command,
layer.Command,
process.Command,
}

app.Before = interceptor.BeforeChain(
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,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-20220121092418-9c455d0dda3f
skywalking.apache.org/repo/goapi v0.0.0-20220310042848-795a2b3fcdfe
)
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210224082022-3d97a244fca7/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420 h1:a8jGStKg0XqKDlKqjLrXn0ioF5MH36pT7Z0BRTqLhbk=
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -698,8 +698,8 @@ golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678 h1:J27LZFQBFoihqXoegpscI10HpjZ7B5WQLLKL2FZXQKw=
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand All @@ -710,8 +710,9 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -940,5 +941,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-20220121092418-9c455d0dda3f h1:i0cL/mhLt8xVO05SCKshkzWNUkXOkiW+zRIIuVWjPko=
skywalking.apache.org/repo/goapi v0.0.0-20220121092418-9c455d0dda3f/go.mod h1:4KrWd+Oi4lkB+PtxZgIlf+3T6EECPru4fOWNMEHjxRk=
skywalking.apache.org/repo/goapi v0.0.0-20220310042848-795a2b3fcdfe h1:Txa1/FZfiA++l6gEC843VMhM4nMGatag/mzk1j4dhWw=
skywalking.apache.org/repo/goapi v0.0.0-20220310042848-795a2b3fcdfe/go.mod h1:wzVLZ8F88Idy5tlmcGgJCH2NY8GUWxJ2RuNVXkao+SM=
50 changes: 50 additions & 0 deletions internal/commands/process/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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 process

import (
"fmt"

"github.com/urfave/cli/v2"

"github.com/apache/skywalking-cli/pkg/display"
"github.com/apache/skywalking-cli/pkg/display/displayable"
"github.com/apache/skywalking-cli/pkg/graphql/metadata"
)

var GetCommand = &cli.Command{
Name: "get",
Usage: `get monitored process of the given <process-id>`,
UsageText: `This command get single process, via process-id.

Examples:
1. get single process by process id "2b9e46c13c91803695a4364257415e523af7cbf17bf4058e025c16b944a6a85b":
$ swctl process get 2b9e46c13c91803695a4364257415e523af7cbf17bf4058e025c16b944a6a85b`,
Action: func(ctx *cli.Context) error {
if ctx.Args().Len() == 0 {
return fmt.Errorf("process-id must be provided")
}

instance, err := metadata.GetProcess(ctx, ctx.Args().First())
if err != nil {
return err
}

return display.Display(ctx, &displayable.Displayable{Data: instance})
},
}
72 changes: 72 additions & 0 deletions internal/commands/process/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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 process

import (
"fmt"

"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/pkg/display"
"github.com/apache/skywalking-cli/pkg/display/displayable"
"github.com/apache/skywalking-cli/pkg/graphql/metadata"
)

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.

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

4. List all processes by instance id "cHJvdmlkZXI=.1_cHJvdmlkZXIx":
$ swctl process ls --instance-id cHJvdmlkZXI=.1_cHJvdmlkZXIx`,
Flags: flags.Flags(
flags.ServiceFlags,
flags.InstanceFlags,
),
Before: interceptor.BeforeChain(
interceptor.ParseService(false),
interceptor.ParseInstance(false),
),
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")
}

processes, err := metadata.Processes(ctx, serviceID, instanceID)
if err != nil {
return err
}

return display.Display(ctx, &displayable.Displayable{Data: processes})
},
}
32 changes: 32 additions & 0 deletions internal/commands/process/process.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 process

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

var Command = &cli.Command{
Name: "process",
Aliases: []string{"p"},
Usage: "Process related sub-command",
Subcommands: cli.Commands{
ListCommand,
GetCommand,
},
}
23 changes: 23 additions & 0 deletions pkg/graphql/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,29 @@ func GetEndpointInfo(cliCtx *cli.Context, endpointID string) (api.EndpointInfo,
return response["result"], err
}

func Processes(cliCtx *cli.Context, serviceID, instanceID string) ([]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)

err := client.ExecuteQuery(cliCtx, request, &response)

return response["result"], err
}

func GetProcess(cliCtx *cli.Context, processID string) (api.Process, error) {
var response map[string]api.Process

request := graphql.NewRequest(assets.Read("graphqls/metadata/v2/GetProcess.graphql"))
request.Var("processId", processID)

err := client.ExecuteQuery(cliCtx, request, &response)

return response["result"], err
}

func ServerTimeInfo(cliCtx *cli.Context) (api.TimeInfo, error) {
var response map[string]api.TimeInfo

Expand Down