This is an automated email from the ASF dual-hosted git repository. kezhenxu94 pushed a commit to branch chore/project-layout in repository https://gitbox.apache.org/repos/asf/skywalking-cli.git
commit 2ed3443179b3995f44d5588c66716fe24b6f0341 Author: kezhenxu94 <[email protected]> AuthorDate: Fri Dec 18 18:42:19 2020 +0800 chore: reorganize the project layout --- CONTRIBUTING.md | 12 +++--- Makefile | 10 ++--- README.md | 4 +- {graphql/schema => api}/schema.go | 2 +- assets/assets.go | 2 +- cmd/{ => swctl}/main.go | 22 +++++----- {example => examples}/global.yml | 0 go.mod | 3 +- go.sum | 33 ++++++++++++++- gqlgen.yml | 6 +-- .../commands}/dashboard/dashboard.go | 2 +- .../commands}/dashboard/global/global.go | 17 ++++---- .../commands}/dashboard/global/metrics.go | 17 ++++---- .../commands}/endpoint/endpoint.go | 0 {commands => internal/commands}/endpoint/list.go | 6 +-- .../commands/healthcheck/healthcheck.go | 10 ++--- .../commands}/instance/instance.go | 4 +- {commands => internal/commands}/instance/list.go | 16 ++++---- {commands => internal/commands}/instance/search.go | 18 ++++---- .../commands}/interceptor/duration.go | 14 +++---- .../commands}/interceptor/duration_test.go | 13 +++--- .../commands}/interceptor/entity.go | 23 +++++------ .../commands}/interceptor/entity_test.go | 35 ++++++++-------- .../commands}/interceptor/interceptor.go | 0 .../commands}/interceptor/timezone.go | 4 +- .../commands}/metrics/aggregation/topn.go | 25 ++++++----- .../commands}/metrics/linear/linear-metrics.go | 20 ++++----- .../metrics/linear/multiple-linear-metrics.go | 22 +++++----- .../commands}/metrics/list/list-metrics.go | 6 +-- {commands => internal/commands}/metrics/metrics.go | 10 ++--- .../commands}/metrics/single/single-metrics.go | 19 ++++----- .../metrics/thermodynamic/thermodynamic.go | 19 ++++----- {commands => internal/commands}/service/list.go | 20 ++++----- {commands => internal/commands}/service/service.go | 0 {commands => internal/commands}/trace/list.go | 28 ++++++------- {commands => internal/commands}/trace/trace.go | 6 +-- {commands => internal}/flags/duration.go | 12 +++--- {commands => internal}/flags/entity.go | 0 {commands => internal}/flags/flags.go | 0 {commands => internal}/flags/instance.go | 0 {commands => internal}/flags/metrics.go | 11 +++-- {commands => internal}/flags/search.go | 0 {logger => internal/logger}/log.go | 0 {commands => internal}/model/order.go | 13 +++--- {commands => internal}/model/scope.go | 13 +++--- {commands => internal}/model/step.go | 13 +++--- {display => pkg/display}/display.go | 10 ++--- .../display}/displayable/displayable.go | 6 ++- {display => pkg/display}/graph/dashboard/global.go | 24 +++++------ {display => pkg/display}/graph/gauge/gauge.go | 14 +++---- {display => pkg/display}/graph/graph.go | 24 +++++------ {display => pkg/display}/graph/heatmap/heatmap.go | 16 ++++---- {display => pkg/display}/graph/linear/linear.go | 0 {display => pkg/display}/graph/tree/adapter.go | 28 ++++++------- {display => pkg/display}/graph/tree/list.go | 22 +++++----- {display => pkg/display}/graph/tree/tree.go | 2 +- {display => pkg/display}/json/json.go | 2 +- {display => pkg/display}/json/json_test.go | 13 +++--- {display => pkg/display}/table/table.go | 4 +- {display => pkg/display}/table/table_test.go | 13 +++--- {display => pkg/display}/yaml/yaml.go | 2 +- {display => pkg/display}/yaml/yaml_test.go | 13 +++--- {graphql => pkg/graphql}/client/client.go | 2 +- {graphql => pkg/graphql}/common/common.go | 10 ++--- {graphql => pkg/graphql}/dashboard/global.go | 48 +++++++++++----------- {graphql => pkg/graphql}/metadata/metadata.go | 26 ++++++------ {graphql => pkg/graphql}/metrics/metrics.go | 27 ++++++------ {graphql => pkg/graphql}/trace/trace.go | 12 +++--- {graphql => pkg/graphql}/utils/adapter.go | 12 +++--- {graphql => pkg/graphql}/utils/adapter_test.go | 17 ++++---- {graphql => pkg/graphql}/utils/constants.go | 23 +++++------ grpc/health.go => pkg/healthcheck/grpc.go | 4 +- {lib => pkg}/heatmap/axes/axes.go | 0 {lib => pkg}/heatmap/axes/label.go | 2 +- {lib => pkg}/heatmap/heatmap.go | 2 +- {lib => pkg}/heatmap/options.go | 0 {util => pkg/util}/io.go | 2 +- {util => pkg/util}/lang.go | 0 {util => pkg/util}/math.go | 0 {hack => scripts}/boilerplate.go.txt | 0 {hack => scripts}/build-header.sh | 0 {test => scripts}/test_commands.sh | 0 82 files changed, 452 insertions(+), 438 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9688f0d..6a9d939 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,17 +47,17 @@ make ``` ## Writing a new command -All commands files locate in directory [`commands`](commands), and an individual directory for each second-level command, -an individual `go` file for each third-level command, for example, there is a directory [`service`](commands/service) for command `swctl service`, -and a [`list.go`](commands/service/list.go) file for `swctl service list` command. +All commands files locate in directory [`commands`](internal/commands), and an individual directory for each second-level command, +an individual `go` file for each third-level command, for example, there is a directory [`service`](internal/commands/service) for command `swctl service`, +and a [`list.go`](internal/commands/service/list.go) file for `swctl service list` command. Determine what entity your command will operate on, and put your command `go` file into that directory, or create one if it doesn't exist, for example, if you want to create a command to `list` all the `instance`s of a service, create a directory `commands/instance`, and a `go` file `commands/instance/list.go`. ## Reusing common options -There're some [common options](#common-options) that can be shared by multiple commands, check [`commands/flags`](commands/flags) -to get all the shared options, and reuse them when possible, an example shares the options is [`commands/service/list.go`](commands/service/list.go#L35) +There're some [common options](#common-options) that can be shared by multiple commands, check [`commands/flags`](internal/flags) +to get all the shared options, and reuse them when possible, an example shares the options is [`commands/service/list.go`](internal/commands/service/list.go#L35) ## Linting your codes We have some rules for the code style and please lint your codes locally before opening a pull request @@ -99,4 +99,4 @@ This section guides committers and PMC members to release SkyWalking CLI in Apac - [Send internal announcement](docs/How-to-release.md#make-the-internal-announcements) - [Wait at least 48 hours for test responses](docs/How-to-release.md#wait-at-least-48-hours-for-test-responses) - [Call for vote](docs/How-to-release.md#call-a-vote-in-dev) -- [Publish release](docs/How-to-release.md#publish-release) \ No newline at end of file +- [Publish release](docs/How-to-release.md#publish-release) diff --git a/Makefile b/Makefile index e8017d5..2f70003 100644 --- a/Makefile +++ b/Makefile @@ -63,14 +63,14 @@ assets: tools cd assets \ && $(GO_BINDATA) --nocompress --nometadata --pkg assets --ignore '.*\.go' \ -o "assets.gen.go" ./... \ - && ../hack/build-header.sh assets.gen.go \ + && ../scripts/build-header.sh assets.gen.go \ && cd .. gqlgen: tools echo 'scalar Long' > query-protocol/schema.graphqls $(GQL_GEN) generate -rm -rf generated.go - -hack/build-header.sh graphql/schema/schema.go + -scripts/build-header.sh api/schema.go -rm query-protocol/schema.graphqls codegen: clean assets gqlgen @@ -79,7 +79,7 @@ codegen: clean assets gqlgen .PHONY: $(PLATFORMS) $(PLATFORMS): mkdir -p $(OUT_DIR) - GOOS=$(os) GOARCH=$(ARCH) $(GO_BUILD) $(GO_BUILD_FLAGS) -ldflags "$(GO_BUILD_LDFLAGS)" -o $(OUT_DIR)/$(BINARY)-$(VERSION)-$(os)-$(ARCH) cmd/main.go + GOOS=$(os) GOARCH=$(ARCH) $(GO_BUILD) $(GO_BUILD_FLAGS) -ldflags "$(GO_BUILD_LDFLAGS)" -o $(OUT_DIR)/$(BINARY)-$(VERSION)-$(os)-$(ARCH) cmd/swctl/main.go .PHONY: lint lint: codegen tools @@ -163,6 +163,6 @@ test-commands: docker container prune -f; \ docker run --name oap -p 12800:12800 -p 11800:11800 -d -e SW_HEALTH_CHECKER=default -e SW_TELEMETRY=prometheus apache/skywalking-oap-server:latest; \ fi - ./test/test_commands.sh + ./scripts/test_commands.sh @docker container stop oap - @docker container prune -f \ No newline at end of file + @docker container prune -f diff --git a/README.md b/README.md index 0c28b09..5a8a915 100644 --- a/README.md +++ b/README.md @@ -322,7 +322,7 @@ Ascii Graph, like coloring in terminal, so please use `json` or `yaml` instead. | `--start` | See [Common options](#common-options) | See [Common options](#common-options) | | `--end` | See [Common options](#common-options) | See [Common options](#common-options) | -You can imitate the content of [the default template file](example/global.yml) to customize the dashboard. +You can imitate the content of [the default template file](examples/global.yml) to customize the dashboard. </details> @@ -341,7 +341,7 @@ You can imitate the content of [the default template file](example/global.yml) t | `--start` | See [Common options](#common-options) | See [Common options](#common-options) | | `--end` | See [Common options](#common-options) | See [Common options](#common-options) | -You can imitate the content of [the default template file](example/global.yml) to customize the dashboard. +You can imitate the content of [the default template file](examples/global.yml) to customize the dashboard. </details> diff --git a/graphql/schema/schema.go b/api/schema.go similarity index 99% rename from graphql/schema/schema.go rename to api/schema.go index 8c0b78c..6b45fac 100644 --- a/graphql/schema/schema.go +++ b/api/schema.go @@ -17,7 +17,7 @@ // Code generated by github.com/99designs/gqlgen, DO NOT EDIT. -package schema +package api import ( "fmt" diff --git a/assets/assets.go b/assets/assets.go index 8983ff9..665e0c3 100644 --- a/assets/assets.go +++ b/assets/assets.go @@ -18,7 +18,7 @@ package assets import ( - "github.com/apache/skywalking-cli/logger" + "github.com/apache/skywalking-cli/internal/logger" ) // Read reads all content from a file under assets, which is packed in to the binary diff --git a/cmd/main.go b/cmd/swctl/main.go similarity index 85% rename from cmd/main.go rename to cmd/swctl/main.go index 189bd5a..46c7acb 100644 --- a/cmd/main.go +++ b/cmd/swctl/main.go @@ -21,24 +21,24 @@ import ( "io/ioutil" "os" - "github.com/apache/skywalking-cli/commands/common" - "github.com/apache/skywalking-cli/commands/trace" + "github.com/apache/skywalking-cli/internal/commands/healthcheck" + "github.com/apache/skywalking-cli/internal/commands/trace" - "github.com/apache/skywalking-cli/commands/dashboard" + "github.com/apache/skywalking-cli/internal/commands/dashboard" - "github.com/apache/skywalking-cli/commands/metrics" + "github.com/apache/skywalking-cli/internal/commands/metrics" - "github.com/apache/skywalking-cli/commands/endpoint" - "github.com/apache/skywalking-cli/commands/instance" + "github.com/apache/skywalking-cli/internal/commands/endpoint" + "github.com/apache/skywalking-cli/internal/commands/instance" "github.com/sirupsen/logrus" "github.com/urfave/cli" "github.com/urfave/cli/altsrc" - "github.com/apache/skywalking-cli/commands/interceptor" - "github.com/apache/skywalking-cli/commands/service" - "github.com/apache/skywalking-cli/logger" - "github.com/apache/skywalking-cli/util" + "github.com/apache/skywalking-cli/internal/commands/interceptor" + "github.com/apache/skywalking-cli/internal/commands/service" + "github.com/apache/skywalking-cli/internal/logger" + "github.com/apache/skywalking-cli/pkg/util" ) var log *logrus.Logger @@ -108,7 +108,7 @@ func main() { service.Command, metrics.Command, trace.Command, - common.Command, + healthcheck.Command, dashboard.Command, } diff --git a/example/global.yml b/examples/global.yml similarity index 100% rename from example/global.yml rename to examples/global.yml diff --git a/go.mod b/go.mod index caf1f12..4dffc4f 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,8 @@ require ( github.com/urfave/cli v1.22.1 golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect - google.golang.org/grpc v1.24.0 + google.golang.org/grpc v1.27.0 + google.golang.org/protobuf v1.25.0 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index e44a9b5..1f05b71 100644 --- a/go.sum +++ b/go.sum @@ -25,6 +25,7 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= @@ -40,6 +41,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -65,10 +68,21 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= @@ -177,6 +191,7 @@ github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= @@ -326,6 +341,8 @@ golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= @@ -346,11 +363,23 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a h1:Ob5/580gVHBJZgXnff1cZDbG+xLtMVE5mDRTe+nIsX4= google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.24.0 h1:vb/1TCsVn3DcJlQ0Gs1yB1pKI6Do2/QNwxdKqmc/b0s= -google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/gqlgen.yml b/gqlgen.yml index 81cf26e..c613e5e 100644 --- a/gqlgen.yml +++ b/gqlgen.yml @@ -20,9 +20,9 @@ schema: skip_validation: true model: - filename: graphql/schema/schema.go - package: schema + filename: api/schema.go + package: api models: Long: - model: github.com/99designs/gqlgen/graphql.Int64 \ No newline at end of file + model: github.com/99designs/gqlgen/graphql.Int64 diff --git a/commands/dashboard/dashboard.go b/internal/commands/dashboard/dashboard.go similarity index 93% rename from commands/dashboard/dashboard.go rename to internal/commands/dashboard/dashboard.go index cb1c7c7..5d270da 100644 --- a/commands/dashboard/dashboard.go +++ b/internal/commands/dashboard/dashboard.go @@ -20,7 +20,7 @@ package dashboard import ( "github.com/urfave/cli" - "github.com/apache/skywalking-cli/commands/dashboard/global" + "github.com/apache/skywalking-cli/internal/commands/dashboard/global" ) var Command = cli.Command{ diff --git a/commands/dashboard/global/global.go b/internal/commands/dashboard/global/global.go similarity index 80% rename from commands/dashboard/global/global.go rename to internal/commands/dashboard/global/global.go index 577abde..b38fe20 100644 --- a/commands/dashboard/global/global.go +++ b/internal/commands/dashboard/global/global.go @@ -18,17 +18,16 @@ package global import ( + "github.com/apache/skywalking-cli/api" "github.com/urfave/cli" - "github.com/apache/skywalking-cli/commands/model" - "github.com/apache/skywalking-cli/graphql/schema" + "github.com/apache/skywalking-cli/internal/model" + "github.com/apache/skywalking-cli/pkg/display/displayable" - "github.com/apache/skywalking-cli/display/displayable" - - "github.com/apache/skywalking-cli/commands/flags" - "github.com/apache/skywalking-cli/commands/interceptor" - "github.com/apache/skywalking-cli/display" - "github.com/apache/skywalking-cli/graphql/dashboard" + "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/graphql/dashboard" ) var GlobalCommand = cli.Command{ @@ -62,7 +61,7 @@ var GlobalCommand = cli.Command{ start := ctx.String("start") step := ctx.Generic("step") - globalData := dashboard.Global(ctx, schema.Duration{ + globalData := dashboard.Global(ctx, api.Duration{ Start: start, End: end, Step: step.(*model.StepEnumValue).Selected, diff --git a/commands/dashboard/global/metrics.go b/internal/commands/dashboard/global/metrics.go similarity index 78% rename from commands/dashboard/global/metrics.go rename to internal/commands/dashboard/global/metrics.go index d5ffa40..87723a0 100644 --- a/commands/dashboard/global/metrics.go +++ b/internal/commands/dashboard/global/metrics.go @@ -18,14 +18,13 @@ package global import ( - "github.com/apache/skywalking-cli/commands/flags" - "github.com/apache/skywalking-cli/commands/interceptor" - "github.com/apache/skywalking-cli/commands/model" - "github.com/apache/skywalking-cli/display" - "github.com/apache/skywalking-cli/display/displayable" - "github.com/apache/skywalking-cli/graphql/dashboard" - "github.com/apache/skywalking-cli/graphql/schema" - + "github.com/apache/skywalking-cli/api" + "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/dashboard" "github.com/urfave/cli" ) @@ -52,7 +51,7 @@ var Metrics = cli.Command{ start := ctx.String("start") step := ctx.Generic("step") - globalMetrics := dashboard.Metrics(ctx, schema.Duration{ + globalMetrics := dashboard.Metrics(ctx, api.Duration{ Start: start, End: end, Step: step.(*model.StepEnumValue).Selected, diff --git a/commands/endpoint/endpoint.go b/internal/commands/endpoint/endpoint.go similarity index 100% rename from commands/endpoint/endpoint.go rename to internal/commands/endpoint/endpoint.go diff --git a/commands/endpoint/list.go b/internal/commands/endpoint/list.go similarity index 91% rename from commands/endpoint/list.go rename to internal/commands/endpoint/list.go index 3c6767b..a1e66e0 100644 --- a/commands/endpoint/list.go +++ b/internal/commands/endpoint/list.go @@ -20,11 +20,11 @@ package endpoint import ( "github.com/urfave/cli" - "github.com/apache/skywalking-cli/display/displayable" + "github.com/apache/skywalking-cli/pkg/display/displayable" - "github.com/apache/skywalking-cli/graphql/metadata" + "github.com/apache/skywalking-cli/pkg/graphql/metadata" - "github.com/apache/skywalking-cli/display" + "github.com/apache/skywalking-cli/pkg/display" ) var ListCommand = cli.Command{ diff --git a/commands/common/common.go b/internal/commands/healthcheck/healthcheck.go similarity index 87% rename from commands/common/common.go rename to internal/commands/healthcheck/healthcheck.go index 7457569..8827557 100644 --- a/commands/common/common.go +++ b/internal/commands/healthcheck/healthcheck.go @@ -15,14 +15,14 @@ // specific language governing permissions and limitations // under the License. -package common +package healthcheck import ( + "github.com/apache/skywalking-cli/pkg/healthcheck" "github.com/urfave/cli" - "github.com/apache/skywalking-cli/graphql/common" - "github.com/apache/skywalking-cli/grpc" - "github.com/apache/skywalking-cli/logger" + "github.com/apache/skywalking-cli/internal/logger" + "github.com/apache/skywalking-cli/pkg/graphql/common" ) var Command = cli.Command{ @@ -56,7 +56,7 @@ var Command = cli.Command{ if !ctx.BoolT("grpc") { return nil } - retCode := grpc.HealthCheck(ctx.String("grpcAddr"), ctx.Bool("grpcTLS")) + retCode := healthcheck.HealthCheck(ctx.String("grpcAddr"), ctx.Bool("grpcTLS")) if retCode != 0 { return cli.NewExitError("gRPC: failed to check health", retCode) } diff --git a/commands/instance/instance.go b/internal/commands/instance/instance.go similarity index 93% rename from commands/instance/instance.go rename to internal/commands/instance/instance.go index 29c86a7..9277086 100644 --- a/commands/instance/instance.go +++ b/internal/commands/instance/instance.go @@ -20,9 +20,9 @@ package instance import ( "github.com/urfave/cli" - "github.com/apache/skywalking-cli/graphql/metadata" + "github.com/apache/skywalking-cli/pkg/graphql/metadata" - "github.com/apache/skywalking-cli/logger" + "github.com/apache/skywalking-cli/internal/logger" ) var Command = cli.Command{ diff --git a/commands/instance/list.go b/internal/commands/instance/list.go similarity index 78% rename from commands/instance/list.go rename to internal/commands/instance/list.go index 1cfcd88..800a7b1 100644 --- a/commands/instance/list.go +++ b/internal/commands/instance/list.go @@ -18,17 +18,17 @@ package instance import ( + "github.com/apache/skywalking-cli/api" "github.com/urfave/cli" - "github.com/apache/skywalking-cli/display/displayable" + "github.com/apache/skywalking-cli/pkg/display/displayable" - "github.com/apache/skywalking-cli/graphql/metadata" + "github.com/apache/skywalking-cli/pkg/graphql/metadata" - "github.com/apache/skywalking-cli/commands/flags" - "github.com/apache/skywalking-cli/commands/interceptor" - "github.com/apache/skywalking-cli/commands/model" - "github.com/apache/skywalking-cli/display" - "github.com/apache/skywalking-cli/graphql/schema" + "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" ) var ListCommand = cli.Command{ @@ -47,7 +47,7 @@ var ListCommand = cli.Command{ start := ctx.String("start") step := ctx.Generic("step") - instances := metadata.Instances(ctx, serviceID, schema.Duration{ + instances := metadata.Instances(ctx, serviceID, api.Duration{ Start: start, End: end, Step: step.(*model.StepEnumValue).Selected, diff --git a/commands/instance/search.go b/internal/commands/instance/search.go similarity index 79% rename from commands/instance/search.go rename to internal/commands/instance/search.go index 548606f..9a3ac62 100644 --- a/commands/instance/search.go +++ b/internal/commands/instance/search.go @@ -18,19 +18,19 @@ package instance import ( + "github.com/apache/skywalking-cli/api" "regexp" - "github.com/apache/skywalking-cli/display/displayable" + "github.com/apache/skywalking-cli/pkg/display/displayable" - "github.com/apache/skywalking-cli/graphql/metadata" + "github.com/apache/skywalking-cli/pkg/graphql/metadata" "github.com/urfave/cli" - "github.com/apache/skywalking-cli/commands/flags" - "github.com/apache/skywalking-cli/commands/interceptor" - "github.com/apache/skywalking-cli/commands/model" - "github.com/apache/skywalking-cli/display" - "github.com/apache/skywalking-cli/graphql/schema" + "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" ) var SearchCommand = cli.Command{ @@ -50,13 +50,13 @@ var SearchCommand = cli.Command{ regex := ctx.String("regex") - instances := metadata.Instances(ctx, serviceID, schema.Duration{ + instances := metadata.Instances(ctx, serviceID, api.Duration{ Start: start, End: end, Step: step.(*model.StepEnumValue).Selected, }) - var result []schema.ServiceInstance + var result []api.ServiceInstance if len(instances) > 0 { for _, instance := range instances { if ok, _ := regexp.Match(regex, []byte(instance.Name)); ok { diff --git a/commands/interceptor/duration.go b/internal/commands/interceptor/duration.go similarity index 91% rename from commands/interceptor/duration.go rename to internal/commands/interceptor/duration.go index 6e382e0..47b2673 100644 --- a/commands/interceptor/duration.go +++ b/internal/commands/interceptor/duration.go @@ -18,18 +18,18 @@ package interceptor import ( + "github.com/apache/skywalking-cli/api" "strconv" "time" - "github.com/apache/skywalking-cli/graphql/utils" + "github.com/apache/skywalking-cli/pkg/graphql/utils" "github.com/urfave/cli" - "github.com/apache/skywalking-cli/graphql/schema" - "github.com/apache/skywalking-cli/logger" + "github.com/apache/skywalking-cli/internal/logger" ) -func TryParseTime(unparsed string) (schema.Step, time.Time, error) { +func TryParseTime(unparsed string) (api.Step, time.Time, error) { var possibleError error = nil for step, layout := range utils.StepFormats { t, err := time.Parse(layout, unparsed) @@ -38,7 +38,7 @@ func TryParseTime(unparsed string) (schema.Step, time.Time, error) { } possibleError = err } - return schema.StepSecond, time.Time{}, possibleError + return api.StepSecond, time.Time{}, possibleError } // DurationInterceptor sets the duration if absent, and formats it accordingly, @@ -70,7 +70,7 @@ func DurationInterceptor(ctx *cli.Context) error { // then: end := now + 30 units, where unit is the precision of `start`, (hours, minutes, etc.) // if --start is absent, --end is given, // then: start := end - 30 units, where unit is the precision of `end`, (hours, minutes, etc.) -func ParseDuration(start, end, timezone string) (startTime, endTime time.Time, step schema.Step, dt utils.DurationType) { +func ParseDuration(start, end, timezone string) (startTime, endTime time.Time, step api.Step, dt utils.DurationType) { logger.Log.Debugln("Start time:", start, "end time:", end, "timezone:", timezone) now := time.Now() @@ -86,7 +86,7 @@ func ParseDuration(start, end, timezone string) (startTime, endTime time.Time, s // both are absent if start == "" && end == "" { - return now.Add(-30 * time.Minute), now, schema.StepMinute, utils.BothAbsent + return now.Add(-30 * time.Minute), now, api.StepMinute, utils.BothAbsent } var err error diff --git a/commands/interceptor/duration_test.go b/internal/commands/interceptor/duration_test.go similarity index 94% rename from commands/interceptor/duration_test.go rename to internal/commands/interceptor/duration_test.go index 10c8de5..b6be6b3 100644 --- a/commands/interceptor/duration_test.go +++ b/internal/commands/interceptor/duration_test.go @@ -18,11 +18,10 @@ package interceptor import ( + "github.com/apache/skywalking-cli/api" "reflect" "testing" "time" - - "github.com/apache/skywalking-cli/graphql/schema" ) func TestParseDuration(t *testing.T) { @@ -37,7 +36,7 @@ func TestParseDuration(t *testing.T) { args args wantedStartTime time.Time wantedEndTime time.Time - wantedStep schema.Step + wantedStep api.Step }{ { name: "Should set current time if start is absent", @@ -47,7 +46,7 @@ func TestParseDuration(t *testing.T) { }, wantedStartTime: now.Add(-30 * time.Minute), wantedEndTime: now, - wantedStep: schema.StepMinute, + wantedStep: api.StepMinute, }, { name: "Should set current time if end is absent", @@ -57,7 +56,7 @@ func TestParseDuration(t *testing.T) { }, wantedStartTime: now, wantedEndTime: now.Add(30 * time.Minute), - wantedStep: schema.StepMinute, + wantedStep: api.StepMinute, }, { name: "Should keep both if both are present", @@ -67,7 +66,7 @@ func TestParseDuration(t *testing.T) { }, wantedStartTime: now.Add(-10 * time.Minute), wantedEndTime: now.Add(10 * time.Minute), - wantedStep: schema.StepMinute, + wantedStep: api.StepMinute, }, { name: "Should set both if both are absent", @@ -77,7 +76,7 @@ func TestParseDuration(t *testing.T) { }, wantedStartTime: now.Add(-30 * time.Minute), wantedEndTime: now, - wantedStep: schema.StepMinute, + wantedStep: api.StepMinute, }, } for _, tt := range tests { diff --git a/commands/interceptor/entity.go b/internal/commands/interceptor/entity.go similarity index 81% rename from commands/interceptor/entity.go rename to internal/commands/interceptor/entity.go index f9544ca..e88cfee 100644 --- a/commands/interceptor/entity.go +++ b/internal/commands/interceptor/entity.go @@ -18,12 +18,11 @@ package interceptor import ( - "github.com/apache/skywalking-cli/graphql/schema" - + "github.com/apache/skywalking-cli/api" "github.com/urfave/cli" ) -func ParseEntity(ctx *cli.Context) *schema.Entity { +func ParseEntity(ctx *cli.Context) *api.Entity { service := ctx.String("service") normal := ctx.BoolT("isNormal") instance := ctx.String("instance") @@ -34,7 +33,7 @@ func ParseEntity(ctx *cli.Context) *schema.Entity { destInstance := ctx.String("destServiceInstance") destEndpoint := ctx.String("destEndpoint") - entity := &schema.Entity{ + entity := &api.Entity{ ServiceName: &service, Normal: &normal, ServiceInstanceName: &instance, @@ -50,21 +49,21 @@ func ParseEntity(ctx *cli.Context) *schema.Entity { } // parseScope defines the scope based on the input parameters. -func parseScope(entity *schema.Entity) schema.Scope { - scope := schema.ScopeAll +func parseScope(entity *api.Entity) api.Scope { + scope := api.ScopeAll if *entity.DestEndpointName != "" { - scope = schema.ScopeEndpointRelation + scope = api.ScopeEndpointRelation } else if *entity.DestServiceInstanceName != "" { - scope = schema.ScopeServiceInstanceRelation + scope = api.ScopeServiceInstanceRelation } else if *entity.DestServiceName != "" { - scope = schema.ScopeServiceRelation + scope = api.ScopeServiceRelation } else if *entity.EndpointName != "" { - scope = schema.ScopeEndpoint + scope = api.ScopeEndpoint } else if *entity.ServiceInstanceName != "" { - scope = schema.ScopeServiceInstance + scope = api.ScopeServiceInstance } else if *entity.ServiceName != "" { - scope = schema.ScopeService + scope = api.ScopeService } return scope diff --git a/commands/interceptor/entity_test.go b/internal/commands/interceptor/entity_test.go similarity index 85% rename from commands/interceptor/entity_test.go rename to internal/commands/interceptor/entity_test.go index da3a03a..ab55aed 100644 --- a/commands/interceptor/entity_test.go +++ b/internal/commands/interceptor/entity_test.go @@ -18,9 +18,8 @@ package interceptor import ( + "github.com/apache/skywalking-cli/api" "testing" - - "github.com/apache/skywalking-cli/graphql/schema" ) func Test_parseScope(t *testing.T) { @@ -28,12 +27,12 @@ func Test_parseScope(t *testing.T) { nonEmpty := "test" tests := []struct { name string - args *schema.Entity - want schema.Scope + args *api.Entity + want api.Scope }{ { name: "all of names are empty", - args: &schema.Entity{ + args: &api.Entity{ ServiceName: &empty, ServiceInstanceName: &empty, EndpointName: &empty, @@ -41,11 +40,11 @@ func Test_parseScope(t *testing.T) { DestServiceInstanceName: &empty, DestEndpointName: &empty, }, - want: schema.ScopeAll, + want: api.ScopeAll, }, { name: "all of names are not empty", - args: &schema.Entity{ + args: &api.Entity{ ServiceName: &nonEmpty, ServiceInstanceName: &nonEmpty, EndpointName: &nonEmpty, @@ -53,11 +52,11 @@ func Test_parseScope(t *testing.T) { DestServiceInstanceName: &nonEmpty, DestEndpointName: &nonEmpty, }, - want: schema.ScopeEndpointRelation, + want: api.ScopeEndpointRelation, }, { name: "only serviceName is not empty", - args: &schema.Entity{ + args: &api.Entity{ ServiceName: &nonEmpty, ServiceInstanceName: &empty, EndpointName: &empty, @@ -65,11 +64,11 @@ func Test_parseScope(t *testing.T) { DestServiceInstanceName: &empty, DestEndpointName: &empty, }, - want: schema.ScopeService, + want: api.ScopeService, }, { name: "instanceName is not empty", - args: &schema.Entity{ + args: &api.Entity{ ServiceName: &nonEmpty, ServiceInstanceName: &nonEmpty, EndpointName: &empty, @@ -77,11 +76,11 @@ func Test_parseScope(t *testing.T) { DestServiceInstanceName: &empty, DestEndpointName: &empty, }, - want: schema.ScopeServiceInstance, + want: api.ScopeServiceInstance, }, { name: "endpointName is not empty", - args: &schema.Entity{ + args: &api.Entity{ ServiceName: &nonEmpty, ServiceInstanceName: &empty, EndpointName: &nonEmpty, @@ -89,11 +88,11 @@ func Test_parseScope(t *testing.T) { DestServiceInstanceName: &empty, DestEndpointName: &empty, }, - want: schema.ScopeEndpoint, + want: api.ScopeEndpoint, }, { name: "destService is not empty", - args: &schema.Entity{ + args: &api.Entity{ ServiceName: &nonEmpty, ServiceInstanceName: &empty, EndpointName: &empty, @@ -101,11 +100,11 @@ func Test_parseScope(t *testing.T) { DestServiceInstanceName: &empty, DestEndpointName: &empty, }, - want: schema.ScopeServiceRelation, + want: api.ScopeServiceRelation, }, { name: "destInstance is not empty", - args: &schema.Entity{ + args: &api.Entity{ ServiceName: &nonEmpty, ServiceInstanceName: &nonEmpty, EndpointName: &empty, @@ -113,7 +112,7 @@ func Test_parseScope(t *testing.T) { DestServiceInstanceName: &nonEmpty, DestEndpointName: &empty, }, - want: schema.ScopeServiceInstanceRelation, + want: api.ScopeServiceInstanceRelation, }, } for _, tt := range tests { diff --git a/commands/interceptor/interceptor.go b/internal/commands/interceptor/interceptor.go similarity index 100% rename from commands/interceptor/interceptor.go rename to internal/commands/interceptor/interceptor.go diff --git a/commands/interceptor/timezone.go b/internal/commands/interceptor/timezone.go similarity index 93% rename from commands/interceptor/timezone.go rename to internal/commands/interceptor/timezone.go index c724276..f75c318 100644 --- a/commands/interceptor/timezone.go +++ b/internal/commands/interceptor/timezone.go @@ -22,8 +22,8 @@ import ( "github.com/urfave/cli" - "github.com/apache/skywalking-cli/graphql/metadata" - "github.com/apache/skywalking-cli/logger" + "github.com/apache/skywalking-cli/internal/logger" + "github.com/apache/skywalking-cli/pkg/graphql/metadata" ) // TimezoneInterceptor sets the server timezone if the server supports the API, diff --git a/commands/metrics/aggregation/topn.go b/internal/commands/metrics/aggregation/topn.go similarity index 80% rename from commands/metrics/aggregation/topn.go rename to internal/commands/metrics/aggregation/topn.go index a3505cf..8c383c3 100644 --- a/commands/metrics/aggregation/topn.go +++ b/internal/commands/metrics/aggregation/topn.go @@ -19,16 +19,15 @@ package aggregation import ( "fmt" + "github.com/apache/skywalking-cli/api" "strconv" - "github.com/apache/skywalking-cli/commands/flags" - "github.com/apache/skywalking-cli/commands/interceptor" - "github.com/apache/skywalking-cli/commands/model" - "github.com/apache/skywalking-cli/display" - "github.com/apache/skywalking-cli/display/displayable" - "github.com/apache/skywalking-cli/graphql/metrics" - "github.com/apache/skywalking-cli/graphql/schema" - + "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/metrics" "github.com/urfave/cli" ) @@ -44,9 +43,9 @@ var TopN = cli.Command{ Name: "order", Usage: "the `order` by which the top entities are sorted", Value: &model.OrderEnumValue{ - Enum: schema.AllOrder, - Default: schema.OrderDes, - Selected: schema.OrderDes, + Enum: api.AllOrder, + Default: api.OrderDes, + Selected: api.OrderDes, }, }, }, @@ -75,13 +74,13 @@ var TopN = cli.Command{ topN = nn } - duration := schema.Duration{ + duration := api.Duration{ Start: start, End: end, Step: step, } - metricsValues := metrics.SortMetrics(ctx, schema.TopNCondition{ + metricsValues := metrics.SortMetrics(ctx, api.TopNCondition{ Name: metricsName, ParentService: &parentService, Normal: &normal, diff --git a/commands/metrics/linear/linear-metrics.go b/internal/commands/metrics/linear/linear-metrics.go similarity index 76% rename from commands/metrics/linear/linear-metrics.go rename to internal/commands/metrics/linear/linear-metrics.go index 717943c..9f0a11f 100644 --- a/commands/metrics/linear/linear-metrics.go +++ b/internal/commands/metrics/linear/linear-metrics.go @@ -18,14 +18,14 @@ package linear import ( - "github.com/apache/skywalking-cli/commands/flags" - "github.com/apache/skywalking-cli/commands/interceptor" - "github.com/apache/skywalking-cli/commands/model" - "github.com/apache/skywalking-cli/display" - "github.com/apache/skywalking-cli/display/displayable" - "github.com/apache/skywalking-cli/graphql/metrics" - "github.com/apache/skywalking-cli/graphql/schema" - "github.com/apache/skywalking-cli/graphql/utils" + "github.com/apache/skywalking-cli/api" + "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/metrics" + "github.com/apache/skywalking-cli/pkg/graphql/utils" "github.com/urfave/cli" ) @@ -50,13 +50,13 @@ var Single = cli.Command{ metricsName := ctx.String("name") entity := interceptor.ParseEntity(ctx) - duration := schema.Duration{ + duration := api.Duration{ Start: start, End: end, Step: step.(*model.StepEnumValue).Selected, } - metricsValues := metrics.LinearIntValues(ctx, schema.MetricsCondition{ + metricsValues := metrics.LinearIntValues(ctx, api.MetricsCondition{ Name: metricsName, Entity: entity, }, duration) diff --git a/commands/metrics/linear/multiple-linear-metrics.go b/internal/commands/metrics/linear/multiple-linear-metrics.go similarity index 77% rename from commands/metrics/linear/multiple-linear-metrics.go rename to internal/commands/metrics/linear/multiple-linear-metrics.go index d5165cf..41d9af5 100644 --- a/commands/metrics/linear/multiple-linear-metrics.go +++ b/internal/commands/metrics/linear/multiple-linear-metrics.go @@ -19,16 +19,16 @@ package linear import ( "fmt" + "github.com/apache/skywalking-cli/api" "strings" - "github.com/apache/skywalking-cli/commands/flags" - "github.com/apache/skywalking-cli/commands/interceptor" - "github.com/apache/skywalking-cli/commands/model" - "github.com/apache/skywalking-cli/display" - "github.com/apache/skywalking-cli/display/displayable" - "github.com/apache/skywalking-cli/graphql/metrics" - "github.com/apache/skywalking-cli/graphql/schema" - "github.com/apache/skywalking-cli/graphql/utils" + "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/metrics" + "github.com/apache/skywalking-cli/pkg/graphql/utils" "github.com/urfave/cli" ) @@ -62,17 +62,17 @@ var Multiple = cli.Command{ labels := ctx.String("labels") entity := interceptor.ParseEntity(ctx) - if *entity.ServiceName == "" && entity.Scope != schema.ScopeAll { + if *entity.ServiceName == "" && entity.Scope != api.ScopeAll { return fmt.Errorf("the name of service should be specified when metrics' scope is not `All`") } - duration := schema.Duration{ + duration := api.Duration{ Start: start, End: end, Step: step.(*model.StepEnumValue).Selected, } - metricsValuesArray := metrics.MultipleLinearIntValues(ctx, schema.MetricsCondition{ + metricsValuesArray := metrics.MultipleLinearIntValues(ctx, api.MetricsCondition{ Name: metricsName, Entity: interceptor.ParseEntity(ctx), }, strings.Split(labels, ","), duration) diff --git a/commands/metrics/list/list-metrics.go b/internal/commands/metrics/list/list-metrics.go similarity index 88% rename from commands/metrics/list/list-metrics.go rename to internal/commands/metrics/list/list-metrics.go index 8b22349..8694b34 100644 --- a/commands/metrics/list/list-metrics.go +++ b/internal/commands/metrics/list/list-metrics.go @@ -20,9 +20,9 @@ package list import ( "github.com/urfave/cli" - "github.com/apache/skywalking-cli/display" - "github.com/apache/skywalking-cli/display/displayable" - "github.com/apache/skywalking-cli/graphql/metrics" + "github.com/apache/skywalking-cli/pkg/display" + "github.com/apache/skywalking-cli/pkg/display/displayable" + "github.com/apache/skywalking-cli/pkg/graphql/metrics" ) var Command = cli.Command{ diff --git a/commands/metrics/metrics.go b/internal/commands/metrics/metrics.go similarity index 75% rename from commands/metrics/metrics.go rename to internal/commands/metrics/metrics.go index 9ba471b..78196d7 100644 --- a/commands/metrics/metrics.go +++ b/internal/commands/metrics/metrics.go @@ -20,13 +20,13 @@ package metrics import ( "github.com/urfave/cli" - "github.com/apache/skywalking-cli/commands/metrics/aggregation" - "github.com/apache/skywalking-cli/commands/metrics/list" + "github.com/apache/skywalking-cli/internal/commands/metrics/aggregation" + "github.com/apache/skywalking-cli/internal/commands/metrics/list" - "github.com/apache/skywalking-cli/commands/metrics/thermodynamic" + "github.com/apache/skywalking-cli/internal/commands/metrics/thermodynamic" - "github.com/apache/skywalking-cli/commands/metrics/linear" - "github.com/apache/skywalking-cli/commands/metrics/single" + "github.com/apache/skywalking-cli/internal/commands/metrics/linear" + "github.com/apache/skywalking-cli/internal/commands/metrics/single" ) var Command = cli.Command{ diff --git a/commands/metrics/single/single-metrics.go b/internal/commands/metrics/single/single-metrics.go similarity index 77% rename from commands/metrics/single/single-metrics.go rename to internal/commands/metrics/single/single-metrics.go index 05469ec..9a1d826 100644 --- a/commands/metrics/single/single-metrics.go +++ b/internal/commands/metrics/single/single-metrics.go @@ -18,14 +18,13 @@ package single import ( - "github.com/apache/skywalking-cli/commands/flags" - "github.com/apache/skywalking-cli/commands/interceptor" - "github.com/apache/skywalking-cli/commands/model" - "github.com/apache/skywalking-cli/display" - "github.com/apache/skywalking-cli/display/displayable" - "github.com/apache/skywalking-cli/graphql/metrics" - "github.com/apache/skywalking-cli/graphql/schema" - + "github.com/apache/skywalking-cli/api" + "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/metrics" "github.com/urfave/cli" ) @@ -49,13 +48,13 @@ var Command = cli.Command{ metricsName := ctx.String("name") entity := interceptor.ParseEntity(ctx) - duration := schema.Duration{ + duration := api.Duration{ Start: start, End: end, Step: step.(*model.StepEnumValue).Selected, } - metricsValue := metrics.IntValues(ctx, schema.MetricsCondition{ + metricsValue := metrics.IntValues(ctx, api.MetricsCondition{ Name: metricsName, Entity: entity, }, duration) diff --git a/commands/metrics/thermodynamic/thermodynamic.go b/internal/commands/metrics/thermodynamic/thermodynamic.go similarity index 78% rename from commands/metrics/thermodynamic/thermodynamic.go rename to internal/commands/metrics/thermodynamic/thermodynamic.go index 63d3f94..6d1f5d9 100644 --- a/commands/metrics/thermodynamic/thermodynamic.go +++ b/internal/commands/metrics/thermodynamic/thermodynamic.go @@ -18,14 +18,13 @@ package thermodynamic import ( - "github.com/apache/skywalking-cli/commands/flags" - "github.com/apache/skywalking-cli/commands/interceptor" - "github.com/apache/skywalking-cli/commands/model" - "github.com/apache/skywalking-cli/display" - "github.com/apache/skywalking-cli/display/displayable" - "github.com/apache/skywalking-cli/graphql/metrics" - "github.com/apache/skywalking-cli/graphql/schema" - + "github.com/apache/skywalking-cli/api" + "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/metrics" "github.com/urfave/cli" ) @@ -50,13 +49,13 @@ var Command = cli.Command{ metricsName := ctx.String("name") entity := interceptor.ParseEntity(ctx) - duration := schema.Duration{ + duration := api.Duration{ Start: start, End: end, Step: step.(*model.StepEnumValue).Selected, } - metricsValues := metrics.Thermodynamic(ctx, schema.MetricsCondition{ + metricsValues := metrics.Thermodynamic(ctx, api.MetricsCondition{ Name: metricsName, Entity: entity, }, duration) diff --git a/commands/service/list.go b/internal/commands/service/list.go similarity index 77% rename from commands/service/list.go rename to internal/commands/service/list.go index 14e2830..6b3983f 100644 --- a/commands/service/list.go +++ b/internal/commands/service/list.go @@ -18,17 +18,17 @@ package service import ( + "github.com/apache/skywalking-cli/api" "github.com/urfave/cli" - "github.com/apache/skywalking-cli/display/displayable" + "github.com/apache/skywalking-cli/pkg/display/displayable" - "github.com/apache/skywalking-cli/graphql/metadata" + "github.com/apache/skywalking-cli/pkg/graphql/metadata" - "github.com/apache/skywalking-cli/commands/flags" - "github.com/apache/skywalking-cli/commands/interceptor" - "github.com/apache/skywalking-cli/commands/model" - "github.com/apache/skywalking-cli/display" - "github.com/apache/skywalking-cli/graphql/schema" + "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" ) var ListCommand = cli.Command{ @@ -47,17 +47,17 @@ var ListCommand = cli.Command{ start := ctx.String("start") step := ctx.Generic("step") - var services []schema.Service + var services []api.Service if args := ctx.Args(); len(args) == 0 { - services = metadata.AllServices(ctx, schema.Duration{ + services = metadata.AllServices(ctx, api.Duration{ Start: start, End: end, Step: step.(*model.StepEnumValue).Selected, }) } else { service, _ := metadata.SearchService(ctx, args.First()) - services = []schema.Service{service} + services = []api.Service{service} } return display.Display(ctx, &displayable.Displayable{Data: services}) diff --git a/commands/service/service.go b/internal/commands/service/service.go similarity index 100% rename from commands/service/service.go rename to internal/commands/service/service.go diff --git a/commands/trace/list.go b/internal/commands/trace/list.go similarity index 80% rename from commands/trace/list.go rename to internal/commands/trace/list.go index 0d875c7..f472160 100644 --- a/commands/trace/list.go +++ b/internal/commands/trace/list.go @@ -18,20 +18,20 @@ package trace import ( + "github.com/apache/skywalking-cli/api" "strings" - "github.com/apache/skywalking-cli/display/displayable" + "github.com/apache/skywalking-cli/pkg/display/displayable" - "github.com/apache/skywalking-cli/commands/interceptor" + "github.com/apache/skywalking-cli/internal/commands/interceptor" "github.com/urfave/cli" - "github.com/apache/skywalking-cli/commands/flags" - "github.com/apache/skywalking-cli/commands/model" - "github.com/apache/skywalking-cli/display" + "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/graphql/schema" - "github.com/apache/skywalking-cli/graphql/trace" + "github.com/apache/skywalking-cli/pkg/graphql/trace" ) const DefaultPageSize = 15 @@ -75,7 +75,7 @@ var ListCommand = cli.Command{ end := ctx.String("end") step := ctx.Generic("step") - duration := schema.Duration{ + duration := api.Duration{ Start: start, End: end, Step: step.(*model.StepEnumValue).Selected, @@ -84,24 +84,24 @@ var ListCommand = cli.Command{ serviceInstanceID := ctx.String("service-instance-id") traceID := ctx.String("trace-id") tagStr := ctx.String("tags") - var tags []*schema.SpanTag = nil + var tags []*api.SpanTag = nil if tagStr != "" { tagArr := strings.Split(tagStr, ",") for _, tag := range tagArr { kv := strings.Split(tag, "=") - tags = append(tags, &schema.SpanTag{Key: kv[0], Value: &kv[1]}) + tags = append(tags, &api.SpanTag{Key: kv[0], Value: &kv[1]}) } } pageNum := 1 needTotal := true - paging := schema.Pagination{ + paging := api.Pagination{ PageNum: &pageNum, PageSize: DefaultPageSize, NeedTotal: &needTotal, } - condition := &schema.TraceQueryCondition{ + condition := &api.TraceQueryCondition{ ServiceID: &serviceID, ServiceInstanceID: &serviceInstanceID, TraceID: &traceID, @@ -110,8 +110,8 @@ var ListCommand = cli.Command{ QueryDuration: &duration, MinTraceDuration: nil, MaxTraceDuration: nil, - TraceState: schema.TraceStateAll, - QueryOrder: schema.QueryOrderByDuration, + TraceState: api.TraceStateAll, + QueryOrder: api.QueryOrderByDuration, Tags: tags, Paging: &paging, } diff --git a/commands/trace/trace.go b/internal/commands/trace/trace.go similarity index 89% rename from commands/trace/trace.go rename to internal/commands/trace/trace.go index a6dd408..32f4555 100644 --- a/commands/trace/trace.go +++ b/internal/commands/trace/trace.go @@ -22,9 +22,9 @@ import ( "github.com/urfave/cli" - "github.com/apache/skywalking-cli/display" - "github.com/apache/skywalking-cli/display/displayable" - "github.com/apache/skywalking-cli/graphql/trace" + "github.com/apache/skywalking-cli/pkg/display" + "github.com/apache/skywalking-cli/pkg/display/displayable" + "github.com/apache/skywalking-cli/pkg/graphql/trace" ) var Command = cli.Command{ diff --git a/commands/flags/duration.go b/internal/flags/duration.go similarity index 83% rename from commands/flags/duration.go rename to internal/flags/duration.go index 152ba0e..5e6e57c 100644 --- a/commands/flags/duration.go +++ b/internal/flags/duration.go @@ -18,13 +18,13 @@ package flags import ( + "github.com/apache/skywalking-cli/api" "github.com/urfave/cli" - "github.com/apache/skywalking-cli/commands/model" - "github.com/apache/skywalking-cli/graphql/schema" + "github.com/apache/skywalking-cli/internal/model" ) -// DurationFlags are common flags that involves a duration, composed +// DurationFlags are healthcheck flags that involves a duration, composed // by a start time, an end time, and a step, which is commonly used // in most of the commands var DurationFlags = []cli.Flag{ @@ -40,9 +40,9 @@ var DurationFlags = []cli.Flag{ Name: "step", Hidden: true, Value: &model.StepEnumValue{ - Enum: schema.AllStep, - Default: schema.StepMinute, - Selected: schema.StepMinute, + Enum: api.AllStep, + Default: api.StepMinute, + Selected: api.StepMinute, }, }, cli.StringFlag{ diff --git a/commands/flags/entity.go b/internal/flags/entity.go similarity index 100% rename from commands/flags/entity.go rename to internal/flags/entity.go diff --git a/commands/flags/flags.go b/internal/flags/flags.go similarity index 100% rename from commands/flags/flags.go rename to internal/flags/flags.go diff --git a/commands/flags/instance.go b/internal/flags/instance.go similarity index 100% rename from commands/flags/instance.go rename to internal/flags/instance.go diff --git a/commands/flags/metrics.go b/internal/flags/metrics.go similarity index 87% rename from commands/flags/metrics.go rename to internal/flags/metrics.go index cda10a3..cb653ac 100644 --- a/commands/flags/metrics.go +++ b/internal/flags/metrics.go @@ -18,9 +18,8 @@ package flags import ( - "github.com/apache/skywalking-cli/commands/model" - "github.com/apache/skywalking-cli/graphql/schema" - + "github.com/apache/skywalking-cli/api" + "github.com/apache/skywalking-cli/internal/model" "github.com/urfave/cli" ) @@ -46,9 +45,9 @@ var MetricsFlags = []cli.Flag{ Name: "scope", Usage: "the scope of the metrics entity", Value: &model.ScopeEnumValue{ - Enum: schema.AllScope, - Default: schema.ScopeService, - Selected: schema.ScopeService, + Enum: api.AllScope, + Default: api.ScopeService, + Selected: api.ScopeService, }, }, } diff --git a/commands/flags/search.go b/internal/flags/search.go similarity index 100% rename from commands/flags/search.go rename to internal/flags/search.go diff --git a/logger/log.go b/internal/logger/log.go similarity index 100% rename from logger/log.go rename to internal/logger/log.go diff --git a/commands/model/order.go b/internal/model/order.go similarity index 86% rename from commands/model/order.go rename to internal/model/order.go index 77a20ba..cb10ac7 100644 --- a/commands/model/order.go +++ b/internal/model/order.go @@ -19,16 +19,15 @@ package model import ( "fmt" + "github.com/apache/skywalking-cli/api" "strings" - - "github.com/apache/skywalking-cli/graphql/schema" ) // OrderEnumValue defines the values domain of --order option type OrderEnumValue struct { - Enum []schema.Order - Default schema.Order - Selected schema.Order + Enum []api.Order + Default api.Order + Selected api.Order } // Set the --order value, from raw string to OrderEnumValue @@ -39,8 +38,8 @@ func (s *OrderEnumValue) Set(value string) error { return nil } } - orders := make([]string, len(schema.AllOrder)) - for i, order := range schema.AllOrder { + orders := make([]string, len(api.AllOrder)) + for i, order := range api.AllOrder { orders[i] = order.String() } return fmt.Errorf("allowed orders are %s", strings.Join(orders, ", ")) diff --git a/commands/model/scope.go b/internal/model/scope.go similarity index 86% rename from commands/model/scope.go rename to internal/model/scope.go index 7adc5e2..bdf8f1c 100644 --- a/commands/model/scope.go +++ b/internal/model/scope.go @@ -19,16 +19,15 @@ package model import ( "fmt" + "github.com/apache/skywalking-cli/api" "strings" - - "github.com/apache/skywalking-cli/graphql/schema" ) // ScopeEnumValue defines the values domain of --scope option type ScopeEnumValue struct { - Enum []schema.Scope - Default schema.Scope - Selected schema.Scope + Enum []api.Scope + Default api.Scope + Selected api.Scope } // Set the --scope value, from raw string to ScopeEnumValue @@ -39,8 +38,8 @@ func (s *ScopeEnumValue) Set(value string) error { return nil } } - scopes := make([]string, len(schema.AllScope)) - for i, scope := range schema.AllScope { + scopes := make([]string, len(api.AllScope)) + for i, scope := range api.AllScope { scopes[i] = scope.String() } return fmt.Errorf("allowed scopes are %s", strings.Join(scopes, ", ")) diff --git a/commands/model/step.go b/internal/model/step.go similarity index 87% rename from commands/model/step.go rename to internal/model/step.go index 8f363be..9fc8e08 100644 --- a/commands/model/step.go +++ b/internal/model/step.go @@ -19,16 +19,15 @@ package model import ( "fmt" + "github.com/apache/skywalking-cli/api" "strings" - - "github.com/apache/skywalking-cli/graphql/schema" ) // StepEnumValue defines the values domain of --step option type StepEnumValue struct { - Enum []schema.Step - Default schema.Step - Selected schema.Step + Enum []api.Step + Default api.Step + Selected api.Step } // Set the --step value, from raw string to StepEnumValue @@ -39,8 +38,8 @@ func (s *StepEnumValue) Set(value string) error { return nil } } - steps := make([]string, len(schema.AllStep)) - for i, step := range schema.AllStep { + steps := make([]string, len(api.AllStep)) + for i, step := range api.AllStep { steps[i] = step.String() } return fmt.Errorf("allowed steps are %s", strings.Join(steps, ", ")) diff --git a/display/display.go b/pkg/display/display.go similarity index 84% rename from display/display.go rename to pkg/display/display.go index 9e7d132..9dd17b8 100644 --- a/display/display.go +++ b/pkg/display/display.go @@ -21,15 +21,15 @@ import ( "fmt" "strings" - d "github.com/apache/skywalking-cli/display/displayable" + d "github.com/apache/skywalking-cli/pkg/display/displayable" - "github.com/apache/skywalking-cli/display/graph" + "github.com/apache/skywalking-cli/pkg/display/graph" "github.com/urfave/cli" - "github.com/apache/skywalking-cli/display/json" - "github.com/apache/skywalking-cli/display/table" - "github.com/apache/skywalking-cli/display/yaml" + "github.com/apache/skywalking-cli/pkg/display/json" + "github.com/apache/skywalking-cli/pkg/display/table" + "github.com/apache/skywalking-cli/pkg/display/yaml" ) const ( diff --git a/display/displayable/displayable.go b/pkg/display/displayable/displayable.go similarity index 91% rename from display/displayable/displayable.go rename to pkg/display/displayable/displayable.go index d4678f4..eff05d0 100644 --- a/display/displayable/displayable.go +++ b/pkg/display/displayable/displayable.go @@ -17,11 +17,13 @@ package displayable -import "github.com/apache/skywalking-cli/graphql/schema" +import ( + "github.com/apache/skywalking-cli/api" +) type Displayable struct { Data interface{} Condition interface{} - Duration schema.Duration + Duration api.Duration Title string } diff --git a/display/graph/dashboard/global.go b/pkg/display/graph/dashboard/global.go similarity index 93% rename from display/graph/dashboard/global.go rename to pkg/display/graph/dashboard/global.go index 0865a2e..74d1ab9 100644 --- a/display/graph/dashboard/global.go +++ b/pkg/display/graph/dashboard/global.go @@ -20,14 +20,14 @@ package dashboard import ( "context" "fmt" + "github.com/apache/skywalking-cli/api" "math" "strings" "time" - "github.com/apache/skywalking-cli/commands/interceptor" - "github.com/apache/skywalking-cli/graphql/schema" - "github.com/apache/skywalking-cli/graphql/utils" - lib "github.com/apache/skywalking-cli/lib/heatmap" + "github.com/apache/skywalking-cli/internal/commands/interceptor" + "github.com/apache/skywalking-cli/pkg/graphql/utils" + lib "github.com/apache/skywalking-cli/pkg/heatmap" "github.com/mattn/go-runewidth" "github.com/mum4k/termdash" @@ -37,10 +37,10 @@ import ( "github.com/mum4k/termdash/terminal/terminalapi" "github.com/urfave/cli" - "github.com/apache/skywalking-cli/display/graph/gauge" - "github.com/apache/skywalking-cli/display/graph/heatmap" - "github.com/apache/skywalking-cli/display/graph/linear" - "github.com/apache/skywalking-cli/graphql/dashboard" + "github.com/apache/skywalking-cli/pkg/display/graph/gauge" + "github.com/apache/skywalking-cli/pkg/display/graph/heatmap" + "github.com/apache/skywalking-cli/pkg/display/graph/linear" + "github.com/apache/skywalking-cli/pkg/graphql/dashboard" "github.com/mum4k/termdash/cell" "github.com/mum4k/termdash/container" @@ -353,10 +353,10 @@ func refresh(con context.Context, ctx *cli.Context, interval time.Duration) { // updateDuration will check if the duration changes after adding the interval. // If the duration doesn't change, an error will be returned, and the dashboard will not refresh. // Otherwise, a new duration will be returned, which is used to get the latest global data. -func updateDuration(interval time.Duration) (schema.Duration, error) { +func updateDuration(interval time.Duration) (api.Duration, error) { step, _, err := interceptor.TryParseTime(initStartStr) if err != nil { - return schema.Duration{}, err + return api.Duration{}, err } curStartTime = curStartTime.Add(interval) @@ -366,12 +366,12 @@ func updateDuration(interval time.Duration) (schema.Duration, error) { curEndStr := curEndTime.Format(utils.StepFormats[step]) if curStartStr == initStartStr && curEndStr == initEndStr { - return schema.Duration{}, fmt.Errorf("the duration does not update") + return api.Duration{}, fmt.Errorf("the duration does not update") } initStartStr = curStartStr initEndStr = curEndStr - return schema.Duration{ + return api.Duration{ Start: curStartStr, End: curEndStr, Step: step, diff --git a/display/graph/gauge/gauge.go b/pkg/display/graph/gauge/gauge.go similarity index 93% rename from display/graph/gauge/gauge.go rename to pkg/display/graph/gauge/gauge.go index a99234d..510732a 100644 --- a/display/graph/gauge/gauge.go +++ b/pkg/display/graph/gauge/gauge.go @@ -20,15 +20,15 @@ package gauge import ( "context" "fmt" + "github.com/apache/skywalking-cli/api" "math" "strconv" "strings" "github.com/urfave/cli" - "github.com/apache/skywalking-cli/graphql/dashboard" - "github.com/apache/skywalking-cli/graphql/schema" - "github.com/apache/skywalking-cli/util" + "github.com/apache/skywalking-cli/pkg/graphql/dashboard" + "github.com/apache/skywalking-cli/pkg/util" "github.com/mum4k/termdash" "github.com/mum4k/termdash/cell" @@ -50,7 +50,7 @@ type MetricColumn struct { } // Update updates the MetricColumn's `Absolute` and `BorderTitle`. -func (mc *MetricColumn) Update(data []*schema.SelectedRecord) error { +func (mc *MetricColumn) Update(data []*api.SelectedRecord) error { for i, item := range data { // The number of `SelectedRecord` data may exceed the number of gauges in a `MetricColumn`. if i >= len(mc.gauges) { @@ -79,7 +79,7 @@ func (mc *MetricColumn) Update(data []*schema.SelectedRecord) error { return nil } -func NewMetricColumn(column []*schema.SelectedRecord, config *dashboard.MetricTemplate) (*MetricColumn, error) { +func NewMetricColumn(column []*api.SelectedRecord, config *dashboard.MetricTemplate) (*MetricColumn, error) { var ret MetricColumn t, err := text.New() @@ -193,7 +193,7 @@ func layout(columns []grid.Element) ([]container.Option, error) { return gridOpts, nil } -func Display(ctx *cli.Context, metrics [][]*schema.SelectedRecord) error { +func Display(ctx *cli.Context, metrics [][]*api.SelectedRecord) error { t, err := termbox.New() if err != nil { return err @@ -251,7 +251,7 @@ func Display(ctx *cli.Context, metrics [][]*schema.SelectedRecord) error { } // findMaxValue finds the maximum value in the array of `schema.SelectedRecord`. -func findMaxValue(column []*schema.SelectedRecord) (int, error) { +func findMaxValue(column []*api.SelectedRecord) (int, error) { var ret int for _, c := range column { diff --git a/display/graph/graph.go b/pkg/display/graph/graph.go similarity index 79% rename from display/graph/graph.go rename to pkg/display/graph/graph.go index 22aad02..c050cfd 100644 --- a/display/graph/graph.go +++ b/pkg/display/graph/graph.go @@ -19,28 +19,28 @@ package graph import ( "fmt" + "github.com/apache/skywalking-cli/api" "reflect" "strings" "github.com/urfave/cli" - d "github.com/apache/skywalking-cli/display/displayable" - db "github.com/apache/skywalking-cli/display/graph/dashboard" - "github.com/apache/skywalking-cli/display/graph/gauge" - "github.com/apache/skywalking-cli/display/graph/heatmap" - "github.com/apache/skywalking-cli/display/graph/linear" - "github.com/apache/skywalking-cli/display/graph/tree" - "github.com/apache/skywalking-cli/graphql/dashboard" - "github.com/apache/skywalking-cli/graphql/schema" + d "github.com/apache/skywalking-cli/pkg/display/displayable" + db "github.com/apache/skywalking-cli/pkg/display/graph/dashboard" + "github.com/apache/skywalking-cli/pkg/display/graph/gauge" + "github.com/apache/skywalking-cli/pkg/display/graph/heatmap" + "github.com/apache/skywalking-cli/pkg/display/graph/linear" + "github.com/apache/skywalking-cli/pkg/display/graph/tree" + "github.com/apache/skywalking-cli/pkg/graphql/dashboard" ) type ( - Thermodynamic = schema.HeatMap + Thermodynamic = api.HeatMap LinearMetrics = map[string]float64 MultiLinearMetrics = []LinearMetrics - Trace = schema.Trace - TraceBrief = schema.TraceBrief - GlobalMetrics = [][]*schema.SelectedRecord + Trace = api.Trace + TraceBrief = api.TraceBrief + GlobalMetrics = [][]*api.SelectedRecord GlobalData = dashboard.GlobalData ) diff --git a/display/graph/heatmap/heatmap.go b/pkg/display/graph/heatmap/heatmap.go similarity index 86% rename from display/graph/heatmap/heatmap.go rename to pkg/display/graph/heatmap/heatmap.go index 12f64d4..44ab961 100644 --- a/display/graph/heatmap/heatmap.go +++ b/pkg/display/graph/heatmap/heatmap.go @@ -20,6 +20,7 @@ package heatmap import ( "context" "fmt" + "github.com/apache/skywalking-cli/api" "strings" "github.com/mum4k/termdash" @@ -30,15 +31,14 @@ import ( "github.com/mum4k/termdash/terminal/terminalapi" "github.com/mum4k/termdash/widgetapi" - d "github.com/apache/skywalking-cli/display/displayable" - "github.com/apache/skywalking-cli/graphql/schema" - "github.com/apache/skywalking-cli/graphql/utils" - "github.com/apache/skywalking-cli/lib/heatmap" + d "github.com/apache/skywalking-cli/pkg/display/displayable" + "github.com/apache/skywalking-cli/pkg/graphql/utils" + "github.com/apache/skywalking-cli/pkg/heatmap" ) const rootID = "root" -func NewHeatMapWidget(data schema.HeatMap) (hp *heatmap.HeatMap, err error) { +func NewHeatMapWidget(data api.HeatMap) (hp *heatmap.HeatMap, err error) { hp, err = heatmap.NewHeatMap() if err != nil { return hp, err @@ -48,14 +48,14 @@ func NewHeatMapWidget(data schema.HeatMap) (hp *heatmap.HeatMap, err error) { return } -func SetData(hp *heatmap.HeatMap, data schema.HeatMap) { +func SetData(hp *heatmap.HeatMap, data api.HeatMap) { hpColumns, yLabels := processData(data) hp.SetColumns(hpColumns) hp.SetYLabels(yLabels) } // processData converts data into hpColumns and yValues for the heat map. -func processData(data schema.HeatMap) (hpColumns map[string][]int64, yLabels []string) { +func processData(data api.HeatMap) (hpColumns map[string][]int64, yLabels []string) { hpColumns = utils.HeatMapToMap(&data) yLabels = utils.BucketsToStrings(data.Buckets) return @@ -97,7 +97,7 @@ func Display(displayable *d.Displayable) error { return err } - data := displayable.Data.(schema.HeatMap) + data := displayable.Data.(api.HeatMap) hp, err := NewHeatMapWidget(data) if err != nil { return err diff --git a/display/graph/linear/linear.go b/pkg/display/graph/linear/linear.go similarity index 100% rename from display/graph/linear/linear.go rename to pkg/display/graph/linear/linear.go diff --git a/display/graph/tree/adapter.go b/pkg/display/graph/tree/adapter.go similarity index 89% rename from display/graph/tree/adapter.go rename to pkg/display/graph/tree/adapter.go index 895b5fd..bceae0b 100644 --- a/display/graph/tree/adapter.go +++ b/pkg/display/graph/tree/adapter.go @@ -19,13 +19,13 @@ package tree import ( "fmt" + "github.com/apache/skywalking-cli/api" "strings" - "github.com/apache/skywalking-cli/graphql/schema" - "github.com/apache/skywalking-cli/util" + "github.com/apache/skywalking-cli/pkg/util" ) -func Adapt(trace schema.Trace) (roots []*Node, serviceNames []string) { +func Adapt(trace api.Trace) (roots []*Node, serviceNames []string) { all := make(map[string]*Node) set := make(map[string]bool) var traceID string @@ -73,7 +73,7 @@ func Adapt(trace schema.Trace) (roots []*Node, serviceNames []string) { return roots, serviceNames } -func buildTree(all map[string]*Node, seen map[string]bool, trace schema.Trace) { +func buildTree(all map[string]*Node, seen map[string]bool, trace api.Trace) { for len(seen) < len(trace.Spans) { for _, span := range trace.Spans { if seen[id(span)] { @@ -96,13 +96,13 @@ func buildTree(all map[string]*Node, seen map[string]bool, trace schema.Trace) { } } -func virtualSpan(spanID int, ref schema.Ref) *schema.Span { +func virtualSpan(spanID int, ref api.Ref) *api.Span { endpointName := fmt.Sprintf("VNode: %s", ref.ParentSegmentID) component := fmt.Sprintf("VirtualNode: #%d", spanID) peer := "No Peer" fail := true layer := "Broken" - span := schema.Span{ + span := api.Span{ TraceID: ref.TraceID, SegmentID: ref.ParentSegmentID, SpanID: spanID, @@ -120,27 +120,27 @@ func virtualSpan(spanID int, ref schema.Ref) *schema.Span { return &span } -func isRoot(span *schema.Span) bool { +func isRoot(span *api.Span) bool { return span.SpanID == 0 && span.ParentSpanID == -1 && len(span.Refs) == 0 } -func id(span *schema.Span) string { +func id(span *api.Span) string { return fmt.Sprintf("%s:%s:%d", span.TraceID, span.SegmentID, span.SpanID) } -func pid(span *schema.Span) string { +func pid(span *api.Span) string { return fmt.Sprintf("%s:%s:%d", span.TraceID, span.SegmentID, span.ParentSpanID) } -func id0(ref *schema.Ref) string { +func id0(ref *api.Ref) string { return fmt.Sprintf("%s:%s:%d", ref.TraceID, ref.ParentSegmentID, ref.ParentSpanID) } -func id1(ref *schema.Ref) string { +func id1(ref *api.Ref) string { return fmt.Sprintf("%s:%s:%d", ref.TraceID, ref.ParentSegmentID, ref.ParentSpanID-1) } -func node(span *schema.Span) *Node { +func node(span *api.Span) *Node { return &Node{ Children: []*Node{}, Value: util.Stringify{Str: value(span)}, @@ -148,7 +148,7 @@ func node(span *schema.Span) *Node { } } -func value(span *schema.Span) string { +func value(span *api.Span) string { if *span.IsError { return fmt.Sprintf( "[|%s| %s [%s/%s]](mod:bold,fg:white,bg:red)", @@ -161,7 +161,7 @@ func value(span *schema.Span) string { ) } -func detail(span *schema.Span) string { +func detail(span *api.Span) string { var lines []string lines = append(lines, diff --git a/display/graph/tree/list.go b/pkg/display/graph/tree/list.go similarity index 90% rename from display/graph/tree/list.go rename to pkg/display/graph/tree/list.go index 8fa53bc..3b73428 100644 --- a/display/graph/tree/list.go +++ b/pkg/display/graph/tree/list.go @@ -19,17 +19,17 @@ package tree import ( "fmt" + "github.com/apache/skywalking-cli/api" "strings" - d "github.com/apache/skywalking-cli/display/displayable" - "github.com/apache/skywalking-cli/graphql/schema" - "github.com/apache/skywalking-cli/graphql/trace" + d "github.com/apache/skywalking-cli/pkg/display/displayable" + "github.com/apache/skywalking-cli/pkg/graphql/trace" ui "github.com/gizak/termui/v3" "github.com/gizak/termui/v3/widgets" "github.com/urfave/cli" - "github.com/apache/skywalking-cli/logger" + "github.com/apache/skywalking-cli/internal/logger" ) const DefaultPageSize = 15 @@ -38,8 +38,8 @@ const Detail = " Detail " const Quit = "<C-c>" func DisplayList(ctx *cli.Context, displayable *d.Displayable) error { - data := displayable.Data.(schema.TraceBrief) - condition := displayable.Condition.(*schema.TraceQueryCondition) + data := displayable.Data.(api.TraceBrief) + condition := displayable.Condition.(*api.TraceQueryCondition) if err := ui.Init(); err != nil { logger.Log.Fatalf("failed to initialize termui: %v", err) } @@ -89,8 +89,8 @@ func DisplayList(ctx *cli.Context, displayable *d.Displayable) error { return nil } -func draw(list *widgets.List, tree *widgets.Tree, detail, help *widgets.Paragraph, data schema.TraceBrief, - ctx *cli.Context, condition *schema.TraceQueryCondition) { +func draw(list *widgets.List, tree *widgets.Tree, detail, help *widgets.Paragraph, data api.TraceBrief, + ctx *cli.Context, condition *api.TraceQueryCondition) { x, y := ui.TerminalDimensions() if data.Total != 0 { @@ -124,8 +124,8 @@ func totalPages(total int) int { return total/DefaultPageSize + 1 } -func listenTracesKeyboard(list *widgets.List, tree *widgets.Tree, data schema.TraceBrief, ctx *cli.Context, - detail, help *widgets.Paragraph, condition *schema.TraceQueryCondition) { +func listenTracesKeyboard(list *widgets.List, tree *widgets.Tree, data api.TraceBrief, ctx *cli.Context, + detail, help *widgets.Paragraph, condition *api.TraceQueryCondition) { uiEvents := ui.PollEvents() listActive := true for { @@ -214,7 +214,7 @@ func getNodeData(ctx *cli.Context, traceID string) (nodes []*widgets.TreeNode, s return nodes, serviceNames } -func rows(data schema.TraceBrief, subLen int) []string { +func rows(data api.TraceBrief, subLen int) []string { var rows []string for _, t := range data.Traces { diff --git a/display/graph/tree/tree.go b/pkg/display/graph/tree/tree.go similarity index 99% rename from display/graph/tree/tree.go rename to pkg/display/graph/tree/tree.go index ee0e168..916c94c 100644 --- a/display/graph/tree/tree.go +++ b/pkg/display/graph/tree/tree.go @@ -24,7 +24,7 @@ import ( ui "github.com/gizak/termui/v3" "github.com/gizak/termui/v3/widgets" - "github.com/apache/skywalking-cli/logger" + "github.com/apache/skywalking-cli/internal/logger" ) type Node struct { diff --git a/display/json/json.go b/pkg/display/json/json.go similarity index 94% rename from display/json/json.go rename to pkg/display/json/json.go index 12a506f..e3f2cf8 100644 --- a/display/json/json.go +++ b/pkg/display/json/json.go @@ -21,7 +21,7 @@ import ( "encoding/json" "fmt" - d "github.com/apache/skywalking-cli/display/displayable" + d "github.com/apache/skywalking-cli/pkg/display/displayable" ) func Display(displayable *d.Displayable) error { diff --git a/display/json/json_test.go b/pkg/display/json/json_test.go similarity index 79% rename from display/json/json_test.go rename to pkg/display/json/json_test.go index 9d8ead4..fca6ec3 100644 --- a/display/json/json_test.go +++ b/pkg/display/json/json_test.go @@ -18,26 +18,25 @@ package json import ( + "github.com/apache/skywalking-cli/api" "testing" - d "github.com/apache/skywalking-cli/display/displayable" - - "github.com/apache/skywalking-cli/graphql/schema" + d "github.com/apache/skywalking-cli/pkg/display/displayable" ) func TestJsonDisplay(t *testing.T) { - var result []schema.Service + var result []api.Service display(t, result) - result = make([]schema.Service, 0) + result = make([]api.Service, 0) display(t, result) - result = append(result, schema.Service{ + result = append(result, api.Service{ ID: "1", Name: "json", }) display(t, result) } -func display(t *testing.T, result []schema.Service) { +func display(t *testing.T, result []api.Service) { if err := Display(&d.Displayable{Data: result}); err != nil { t.Error(err) } diff --git a/display/table/table.go b/pkg/display/table/table.go similarity index 93% rename from display/table/table.go rename to pkg/display/table/table.go index 8e2227d..0c82376 100644 --- a/display/table/table.go +++ b/pkg/display/table/table.go @@ -21,9 +21,9 @@ import ( "encoding/json" "os" - d "github.com/apache/skywalking-cli/display/displayable" + d "github.com/apache/skywalking-cli/pkg/display/displayable" - "github.com/apache/skywalking-cli/logger" + "github.com/apache/skywalking-cli/internal/logger" "github.com/olekukonko/tablewriter" ) diff --git a/display/table/table_test.go b/pkg/display/table/table_test.go similarity index 80% rename from display/table/table_test.go rename to pkg/display/table/table_test.go index ec2b265..ce7728b 100644 --- a/display/table/table_test.go +++ b/pkg/display/table/table_test.go @@ -18,26 +18,25 @@ package table import ( + "github.com/apache/skywalking-cli/api" "testing" - "github.com/apache/skywalking-cli/display/displayable" - - "github.com/apache/skywalking-cli/graphql/schema" + "github.com/apache/skywalking-cli/pkg/display/displayable" ) func TestTableDisplay(t *testing.T) { - var result []schema.Service + var result []api.Service display(t, result) - result = make([]schema.Service, 0) + result = make([]api.Service, 0) display(t, result) - result = append(result, schema.Service{ + result = append(result, api.Service{ ID: "1", Name: "table", }) display(t, result) } -func display(t *testing.T, result []schema.Service) { +func display(t *testing.T, result []api.Service) { if err := Display(&displayable.Displayable{Data: result}); err != nil { t.Error(err) } diff --git a/display/yaml/yaml.go b/pkg/display/yaml/yaml.go similarity index 94% rename from display/yaml/yaml.go rename to pkg/display/yaml/yaml.go index 3f3c98b..4cfe9af 100644 --- a/display/yaml/yaml.go +++ b/pkg/display/yaml/yaml.go @@ -20,7 +20,7 @@ package yaml import ( "fmt" - d "github.com/apache/skywalking-cli/display/displayable" + d "github.com/apache/skywalking-cli/pkg/display/displayable" "gopkg.in/yaml.v2" ) diff --git a/display/yaml/yaml_test.go b/pkg/display/yaml/yaml_test.go similarity index 80% rename from display/yaml/yaml_test.go rename to pkg/display/yaml/yaml_test.go index aaada3a..e7d1fcb 100644 --- a/display/yaml/yaml_test.go +++ b/pkg/display/yaml/yaml_test.go @@ -18,26 +18,25 @@ package yaml import ( + "github.com/apache/skywalking-cli/api" "testing" - "github.com/apache/skywalking-cli/display/displayable" - - "github.com/apache/skywalking-cli/graphql/schema" + "github.com/apache/skywalking-cli/pkg/display/displayable" ) func TestYamlDisplay(t *testing.T) { - var result []schema.Service + var result []api.Service display(t, result) - result = make([]schema.Service, 0) + result = make([]api.Service, 0) display(t, result) - result = append(result, schema.Service{ + result = append(result, api.Service{ ID: "1", Name: "yaml", }) display(t, result) } -func display(t *testing.T, result []schema.Service) { +func display(t *testing.T, result []api.Service) { if err := Display(&displayable.Displayable{Data: result}); err != nil { t.Error(err) } diff --git a/graphql/client/client.go b/pkg/graphql/client/client.go similarity index 97% rename from graphql/client/client.go rename to pkg/graphql/client/client.go index ebadd9c..846f662 100644 --- a/graphql/client/client.go +++ b/pkg/graphql/client/client.go @@ -24,7 +24,7 @@ import ( "github.com/machinebox/graphql" "github.com/urfave/cli" - "github.com/apache/skywalking-cli/logger" + "github.com/apache/skywalking-cli/internal/logger" ) func newClient(cliCtx *cli.Context) (client *graphql.Client) { diff --git a/graphql/common/common.go b/pkg/graphql/common/common.go similarity index 79% rename from graphql/common/common.go rename to pkg/graphql/common/common.go index 1f1c417..651d81b 100644 --- a/graphql/common/common.go +++ b/pkg/graphql/common/common.go @@ -18,19 +18,19 @@ package common import ( + "github.com/apache/skywalking-cli/api" "github.com/machinebox/graphql" "github.com/urfave/cli" "github.com/apache/skywalking-cli/assets" - "github.com/apache/skywalking-cli/graphql/client" - "github.com/apache/skywalking-cli/graphql/schema" + "github.com/apache/skywalking-cli/pkg/graphql/client" ) // CheckHealth intends to query the health status of OAP server -func CheckHealth(ctx *cli.Context) schema.HealthStatus { - var response map[string]schema.HealthStatus +func CheckHealth(ctx *cli.Context) api.HealthStatus { + var response map[string]api.HealthStatus - request := graphql.NewRequest(assets.Read("graphqls/common/checkHealth.graphql")) + request := graphql.NewRequest(assets.Read("graphqls/healthcheck/checkHealth.graphql")) client.ExecuteQueryOrFail(ctx, request, &response) diff --git a/graphql/dashboard/global.go b/pkg/graphql/dashboard/global.go similarity index 78% rename from graphql/dashboard/global.go rename to pkg/graphql/dashboard/global.go index c004acd..fd9aa48 100644 --- a/graphql/dashboard/global.go +++ b/pkg/graphql/dashboard/global.go @@ -19,6 +19,7 @@ package dashboard import ( "bytes" + "github.com/apache/skywalking-cli/api" "io/ioutil" "strings" "sync" @@ -29,9 +30,8 @@ import ( "gopkg.in/yaml.v2" "github.com/apache/skywalking-cli/assets" - "github.com/apache/skywalking-cli/graphql/metrics" - "github.com/apache/skywalking-cli/graphql/schema" - "github.com/apache/skywalking-cli/graphql/utils" + "github.com/apache/skywalking-cli/pkg/graphql/metrics" + "github.com/apache/skywalking-cli/pkg/graphql/utils" ) type ButtonTemplate struct { @@ -41,18 +41,18 @@ type ButtonTemplate struct { } type MetricTemplate struct { - Condition schema.TopNCondition `mapstructure:"condition"` - Title string `mapstructure:"title"` - Aggregation string `mapstructure:"aggregation"` - AggregationNum string `mapstructure:"aggregationNum"` + Condition api.TopNCondition `mapstructure:"condition"` + Title string `mapstructure:"title"` + Aggregation string `mapstructure:"aggregation"` + AggregationNum string `mapstructure:"aggregationNum"` } type ChartTemplate struct { - Condition schema.MetricsCondition `mapstructure:"condition"` - Title string `mapstructure:"title"` - Unit string `mapstructure:"unit"` - Labels string `mapstructure:"labels"` - LabelsIndex string `mapstructure:"labelsIndex"` + Condition api.MetricsCondition `mapstructure:"condition"` + Title string `mapstructure:"title"` + Unit string `mapstructure:"unit"` + Labels string `mapstructure:"labels"` + LabelsIndex string `mapstructure:"labelsIndex"` } type GlobalTemplate struct { @@ -63,9 +63,9 @@ type GlobalTemplate struct { } type GlobalData struct { - Metrics [][]*schema.SelectedRecord `json:"metrics"` - ResponseLatency []map[string]float64 `json:"responseLatency"` - HeatMap schema.HeatMap `json:"heatMap"` + Metrics [][]*api.SelectedRecord `json:"metrics"` + ResponseLatency []map[string]float64 `json:"responseLatency"` + HeatMap api.HeatMap `json:"heatMap"` } // Use singleton pattern to make sure to load template only once. @@ -138,8 +138,8 @@ func getButtonTexts(byteValue []byte) ([]string, error) { return ret, nil } -func Metrics(ctx *cli.Context, duration schema.Duration) [][]*schema.SelectedRecord { - var ret [][]*schema.SelectedRecord +func Metrics(ctx *cli.Context, duration api.Duration) [][]*api.SelectedRecord { + var ret [][]*api.SelectedRecord template, err := LoadTemplate(ctx.String("template")) if err != nil { @@ -158,7 +158,7 @@ func Metrics(ctx *cli.Context, duration schema.Duration) [][]*schema.SelectedRec return ret } -func responseLatency(ctx *cli.Context, duration schema.Duration) []map[string]float64 { +func responseLatency(ctx *cli.Context, duration api.Duration) []map[string]float64 { template, err := LoadTemplate(ctx.String("template")) if err != nil { return nil @@ -179,21 +179,21 @@ func responseLatency(ctx *cli.Context, duration schema.Duration) []map[string]fl return utils.MetricsValuesArrayToMap(duration, responseLatency) } -func heatMap(ctx *cli.Context, duration schema.Duration) schema.HeatMap { +func heatMap(ctx *cli.Context, duration api.Duration) api.HeatMap { template, err := LoadTemplate(ctx.String("template")) if err != nil { - return schema.HeatMap{} + return api.HeatMap{} } // Check if there is a template of heat map. if template.HeatMap == (ChartTemplate{}) { - return schema.HeatMap{} + return api.HeatMap{} } return metrics.Thermodynamic(ctx, template.HeatMap.Condition, duration) } -func Global(ctx *cli.Context, duration schema.Duration) *GlobalData { +func Global(ctx *cli.Context, duration api.Duration) *GlobalData { // Load template to `globalTemplate`, so the subsequent three calls can ues it directly. _, err := LoadTemplate(ctx.String("template")) if err != nil { @@ -203,7 +203,7 @@ func Global(ctx *cli.Context, duration schema.Duration) *GlobalData { // Use three goroutines to enable concurrent execution of three graphql queries. var wg sync.WaitGroup wg.Add(3) - var m [][]*schema.SelectedRecord + var m [][]*api.SelectedRecord go func() { m = Metrics(ctx, duration) wg.Done() @@ -213,7 +213,7 @@ func Global(ctx *cli.Context, duration schema.Duration) *GlobalData { rl = responseLatency(ctx, duration) wg.Done() }() - var hm schema.HeatMap + var hm api.HeatMap go func() { hm = heatMap(ctx, duration) wg.Done() diff --git a/graphql/metadata/metadata.go b/pkg/graphql/metadata/metadata.go similarity index 77% rename from graphql/metadata/metadata.go rename to pkg/graphql/metadata/metadata.go index 49e88be..3866794 100644 --- a/graphql/metadata/metadata.go +++ b/pkg/graphql/metadata/metadata.go @@ -19,18 +19,18 @@ package metadata import ( "fmt" + "github.com/apache/skywalking-cli/api" "github.com/apache/skywalking-cli/assets" "github.com/machinebox/graphql" "github.com/urfave/cli" - "github.com/apache/skywalking-cli/graphql/client" - "github.com/apache/skywalking-cli/graphql/schema" + "github.com/apache/skywalking-cli/pkg/graphql/client" ) -func AllServices(cliCtx *cli.Context, duration schema.Duration) []schema.Service { - var response map[string][]schema.Service +func AllServices(cliCtx *cli.Context, duration api.Duration) []api.Service { + var response map[string][]api.Service request := graphql.NewRequest(assets.Read("graphqls/metadata/AllServices.graphql")) request.Var("duration", duration) @@ -39,8 +39,8 @@ func AllServices(cliCtx *cli.Context, duration schema.Duration) []schema.Service return response["result"] } -func SearchService(cliCtx *cli.Context, serviceCode string) (service schema.Service, err error) { - var response map[string]schema.Service +func SearchService(cliCtx *cli.Context, serviceCode string) (service api.Service, err error) { + var response map[string]api.Service request := graphql.NewRequest(assets.Read("graphqls/metadata/SearchService.graphql")) request.Var("serviceCode", serviceCode) @@ -56,8 +56,8 @@ func SearchService(cliCtx *cli.Context, serviceCode string) (service schema.Serv return service, nil } -func SearchEndpoints(cliCtx *cli.Context, serviceID, keyword string, limit int) []schema.Endpoint { - var response map[string][]schema.Endpoint +func SearchEndpoints(cliCtx *cli.Context, serviceID, keyword string, limit int) []api.Endpoint { + var response map[string][]api.Endpoint request := graphql.NewRequest(assets.Read("graphqls/metadata/SearchEndpoints.graphql")) request.Var("serviceId", serviceID) @@ -69,8 +69,8 @@ func SearchEndpoints(cliCtx *cli.Context, serviceID, keyword string, limit int) return response["result"] } -func Instances(cliCtx *cli.Context, serviceID string, duration schema.Duration) []schema.ServiceInstance { - var response map[string][]schema.ServiceInstance +func Instances(cliCtx *cli.Context, serviceID string, duration api.Duration) []api.ServiceInstance { + var response map[string][]api.ServiceInstance request := graphql.NewRequest(assets.Read("graphqls/metadata/Instances.graphql")) request.Var("serviceId", serviceID) @@ -81,13 +81,13 @@ func Instances(cliCtx *cli.Context, serviceID string, duration schema.Duration) return response["result"] } -func ServerTimeInfo(cliCtx *cli.Context) (schema.TimeInfo, error) { - var response map[string]schema.TimeInfo +func ServerTimeInfo(cliCtx *cli.Context) (api.TimeInfo, error) { + var response map[string]api.TimeInfo request := graphql.NewRequest(assets.Read("graphqls/metadata/ServerTimeInfo.graphql")) if err := client.ExecuteQuery(cliCtx, request, &response); err != nil { - return schema.TimeInfo{}, err + return api.TimeInfo{}, err } return response["result"], nil diff --git a/graphql/metrics/metrics.go b/pkg/graphql/metrics/metrics.go similarity index 70% rename from graphql/metrics/metrics.go rename to pkg/graphql/metrics/metrics.go index 8a73a58..094c12a 100644 --- a/graphql/metrics/metrics.go +++ b/pkg/graphql/metrics/metrics.go @@ -18,15 +18,14 @@ package metrics import ( + "github.com/apache/skywalking-cli/api" "github.com/apache/skywalking-cli/assets" - "github.com/apache/skywalking-cli/graphql/client" - "github.com/apache/skywalking-cli/graphql/schema" - + "github.com/apache/skywalking-cli/pkg/graphql/client" "github.com/machinebox/graphql" "github.com/urfave/cli" ) -func IntValues(ctx *cli.Context, condition schema.MetricsCondition, duration schema.Duration) int { +func IntValues(ctx *cli.Context, condition api.MetricsCondition, duration api.Duration) int { var response map[string]int request := graphql.NewRequest(assets.Read("graphqls/metrics/MetricsValue.graphql")) @@ -39,8 +38,8 @@ func IntValues(ctx *cli.Context, condition schema.MetricsCondition, duration sch return response["result"] } -func LinearIntValues(ctx *cli.Context, condition schema.MetricsCondition, duration schema.Duration) schema.MetricsValues { - var response map[string]schema.MetricsValues +func LinearIntValues(ctx *cli.Context, condition api.MetricsCondition, duration api.Duration) api.MetricsValues { + var response map[string]api.MetricsValues request := graphql.NewRequest(assets.Read("graphqls/metrics/MetricsValues.graphql")) @@ -52,8 +51,8 @@ func LinearIntValues(ctx *cli.Context, condition schema.MetricsCondition, durati return response["result"] } -func MultipleLinearIntValues(ctx *cli.Context, condition schema.MetricsCondition, labels []string, duration schema.Duration) []schema.MetricsValues { - var response map[string][]schema.MetricsValues +func MultipleLinearIntValues(ctx *cli.Context, condition api.MetricsCondition, labels []string, duration api.Duration) []api.MetricsValues { + var response map[string][]api.MetricsValues request := graphql.NewRequest(assets.Read("graphqls/metrics/LabeledMetricsValues.graphql")) @@ -66,8 +65,8 @@ func MultipleLinearIntValues(ctx *cli.Context, condition schema.MetricsCondition return response["result"] } -func Thermodynamic(ctx *cli.Context, condition schema.MetricsCondition, duration schema.Duration) schema.HeatMap { - var response map[string]schema.HeatMap +func Thermodynamic(ctx *cli.Context, condition api.MetricsCondition, duration api.Duration) api.HeatMap { + var response map[string]api.HeatMap request := graphql.NewRequest(assets.Read("graphqls/metrics/HeatMap.graphql")) @@ -79,8 +78,8 @@ func Thermodynamic(ctx *cli.Context, condition schema.MetricsCondition, duration return response["result"] } -func SortMetrics(ctx *cli.Context, condition schema.TopNCondition, duration schema.Duration) []*schema.SelectedRecord { - var response map[string][]*schema.SelectedRecord +func SortMetrics(ctx *cli.Context, condition api.TopNCondition, duration api.Duration) []*api.SelectedRecord { + var response map[string][]*api.SelectedRecord request := graphql.NewRequest(assets.Read("graphqls/metrics/SortMetrics.graphql")) request.Var("condition", condition) @@ -91,8 +90,8 @@ func SortMetrics(ctx *cli.Context, condition schema.TopNCondition, duration sche return response["result"] } -func ListMetrics(ctx *cli.Context, regex string) []*schema.MetricDefinition { - var response map[string][]*schema.MetricDefinition +func ListMetrics(ctx *cli.Context, regex string) []*api.MetricDefinition { + var response map[string][]*api.MetricDefinition request := graphql.NewRequest(assets.Read("graphqls/metrics/ListMetrics.graphql")) request.Var("regex", regex) diff --git a/graphql/trace/trace.go b/pkg/graphql/trace/trace.go similarity index 80% rename from graphql/trace/trace.go rename to pkg/graphql/trace/trace.go index fab21e7..f4de9f0 100644 --- a/graphql/trace/trace.go +++ b/pkg/graphql/trace/trace.go @@ -18,16 +18,16 @@ package trace import ( + "github.com/apache/skywalking-cli/api" "github.com/machinebox/graphql" "github.com/urfave/cli" "github.com/apache/skywalking-cli/assets" - "github.com/apache/skywalking-cli/graphql/client" - "github.com/apache/skywalking-cli/graphql/schema" + "github.com/apache/skywalking-cli/pkg/graphql/client" ) -func Trace(ctx *cli.Context, traceID string) schema.Trace { - var response map[string]schema.Trace +func Trace(ctx *cli.Context, traceID string) api.Trace { + var response map[string]api.Trace request := graphql.NewRequest(assets.Read("graphqls/trace/Trace.graphql")) request.Var("traceId", traceID) @@ -37,8 +37,8 @@ func Trace(ctx *cli.Context, traceID string) schema.Trace { return response["result"] } -func Traces(ctx *cli.Context, condition *schema.TraceQueryCondition) schema.TraceBrief { - var response map[string]schema.TraceBrief +func Traces(ctx *cli.Context, condition *api.TraceQueryCondition) api.TraceBrief { + var response map[string]api.TraceBrief request := graphql.NewRequest(assets.Read("graphqls/trace/Traces.graphql")) request.Var("condition", condition) diff --git a/graphql/utils/adapter.go b/pkg/graphql/utils/adapter.go similarity index 84% rename from graphql/utils/adapter.go rename to pkg/graphql/utils/adapter.go index 1f5918f..1ada5f0 100644 --- a/graphql/utils/adapter.go +++ b/pkg/graphql/utils/adapter.go @@ -18,16 +18,16 @@ package utils import ( + "github.com/apache/skywalking-cli/api" "strconv" "strings" "time" - "github.com/apache/skywalking-cli/graphql/schema" - "github.com/apache/skywalking-cli/logger" + "github.com/apache/skywalking-cli/internal/logger" ) // MetricsValuesArrayToMap converts Array of MetricsValues into a map that uses time as key. -func MetricsValuesArrayToMap(duration schema.Duration, mvArray []schema.MetricsValues) []map[string]float64 { +func MetricsValuesArrayToMap(duration api.Duration, mvArray []api.MetricsValues) []map[string]float64 { ret := make([]map[string]float64, len(mvArray)) for _, mvs := range mvArray { index, err := strconv.Atoi(strings.TrimSpace(*mvs.Label)) @@ -41,7 +41,7 @@ func MetricsValuesArrayToMap(duration schema.Duration, mvArray []schema.MetricsV } // MetricsValuesToMap converts MetricsValues into a map that uses time as key. -func MetricsValuesToMap(duration schema.Duration, metricsValues schema.MetricsValues) map[string]float64 { +func MetricsValuesToMap(duration api.Duration, metricsValues api.MetricsValues) map[string]float64 { kvInts := metricsValues.Values.Values ret := map[string]float64{} format := StepFormats[duration.Step] @@ -60,7 +60,7 @@ func MetricsValuesToMap(duration schema.Duration, metricsValues schema.MetricsVa } // HeatMapToMap converts a HeatMap into a map that uses time as key. -func HeatMapToMap(hp *schema.HeatMap) map[string][]int64 { +func HeatMapToMap(hp *api.HeatMap) map[string][]int64 { ret := make(map[string][]int64) for _, col := range hp.Values { // col.id is a string represents date, like "202007292131", @@ -78,7 +78,7 @@ func HeatMapToMap(hp *schema.HeatMap) map[string][]int64 { } // BucketsToStrings extracts strings from buckets as a chart's labels. -func BucketsToStrings(buckets []*schema.Bucket) []string { +func BucketsToStrings(buckets []*api.Bucket) []string { var ret []string for _, b := range buckets { ret = append(ret, b.Min) diff --git a/graphql/utils/adapter_test.go b/pkg/graphql/utils/adapter_test.go similarity index 86% rename from graphql/utils/adapter_test.go rename to pkg/graphql/utils/adapter_test.go index 1d8270d..f5d1444 100644 --- a/graphql/utils/adapter_test.go +++ b/pkg/graphql/utils/adapter_test.go @@ -18,16 +18,15 @@ package utils import ( + "github.com/apache/skywalking-cli/api" "reflect" "testing" - - "github.com/apache/skywalking-cli/graphql/schema" ) func TestMetricsToMap(t *testing.T) { type args struct { - duration schema.Duration - metricsValues schema.MetricsValues + duration api.Duration + metricsValues api.MetricsValues } tests := []struct { name string @@ -37,14 +36,14 @@ func TestMetricsToMap(t *testing.T) { { name: "Should convert to map", args: args{ - duration: schema.Duration{ + duration: api.Duration{ Start: "2020-01-01 0000", End: "2020-01-01 0007", - Step: schema.StepMinute, + Step: api.StepMinute, }, - metricsValues: schema.MetricsValues{ - Values: &schema.IntValues{ - Values: []*schema.KVInt{ + metricsValues: api.MetricsValues{ + Values: &api.IntValues{ + Values: []*api.KVInt{ {Value: 0}, {Value: 1}, {Value: 2}, diff --git a/graphql/utils/constants.go b/pkg/graphql/utils/constants.go similarity index 74% rename from graphql/utils/constants.go rename to pkg/graphql/utils/constants.go index 2f527e3..1b81b7a 100644 --- a/graphql/utils/constants.go +++ b/pkg/graphql/utils/constants.go @@ -18,25 +18,24 @@ package utils import ( + "github.com/apache/skywalking-cli/api" "time" - - "github.com/apache/skywalking-cli/graphql/schema" ) // StepFormats is a mapping from schema.Step to its time format -var StepFormats = map[schema.Step]string{ - schema.StepSecond: "2006-01-02 150405", - schema.StepMinute: "2006-01-02 1504", - schema.StepHour: "2006-01-02 15", - schema.StepDay: "2006-01-02", +var StepFormats = map[api.Step]string{ + api.StepSecond: "2006-01-02 150405", + api.StepMinute: "2006-01-02 1504", + api.StepHour: "2006-01-02 15", + api.StepDay: "2006-01-02", } // StepDuration is a mapping from schema.Step to its time.Duration -var StepDuration = map[schema.Step]time.Duration{ - schema.StepSecond: time.Second, - schema.StepMinute: time.Minute, - schema.StepHour: time.Hour, - schema.StepDay: time.Hour * 24, +var StepDuration = map[api.Step]time.Duration{ + api.StepSecond: time.Second, + api.StepMinute: time.Minute, + api.StepHour: time.Hour, + api.StepDay: time.Hour * 24, } type DurationType string diff --git a/grpc/health.go b/pkg/healthcheck/grpc.go similarity index 97% rename from grpc/health.go rename to pkg/healthcheck/grpc.go index 3b83ad2..f4c6357 100644 --- a/grpc/health.go +++ b/pkg/healthcheck/grpc.go @@ -15,14 +15,14 @@ // specific language governing permissions and limitations // under the License. -package grpc +package healthcheck import ( "context" "crypto/tls" "time" - "github.com/apache/skywalking-cli/logger" + "github.com/apache/skywalking-cli/internal/logger" "google.golang.org/grpc" "google.golang.org/grpc/codes" diff --git a/lib/heatmap/axes/axes.go b/pkg/heatmap/axes/axes.go similarity index 100% rename from lib/heatmap/axes/axes.go rename to pkg/heatmap/axes/axes.go diff --git a/lib/heatmap/axes/label.go b/pkg/heatmap/axes/label.go similarity index 97% rename from lib/heatmap/axes/label.go rename to pkg/heatmap/axes/label.go index e797dae..f1d0b53 100644 --- a/lib/heatmap/axes/label.go +++ b/pkg/heatmap/axes/label.go @@ -108,7 +108,7 @@ func xLabels(yEnd image.Point, graphWidth int, stringLabels []string, cellWidth // paddedLabelLength calculates the length of the padded label and // the column index corresponding to the label. -// For example, the longest label's length is 5, like '12:34', and the cell's width is 3. +// For examples, the longest label's length is 5, like '12:34', and the cell's width is 3. // So in order to better display, every three cells will display a label, // the label belongs to the middle column of the three columns, // and the padded length is 3*3, which is 9. diff --git a/lib/heatmap/heatmap.go b/pkg/heatmap/heatmap.go similarity index 99% rename from lib/heatmap/heatmap.go rename to pkg/heatmap/heatmap.go index cdc466f..5c87730 100644 --- a/lib/heatmap/heatmap.go +++ b/pkg/heatmap/heatmap.go @@ -25,7 +25,7 @@ import ( "sort" "sync" - "github.com/apache/skywalking-cli/lib/heatmap/axes" + "github.com/apache/skywalking-cli/pkg/heatmap/axes" "github.com/mum4k/termdash/cell" "github.com/mum4k/termdash/private/area" diff --git a/lib/heatmap/options.go b/pkg/heatmap/options.go similarity index 100% rename from lib/heatmap/options.go rename to pkg/heatmap/options.go diff --git a/util/io.go b/pkg/util/io.go similarity index 96% rename from util/io.go rename to pkg/util/io.go index ee65b8e..3e957f4 100644 --- a/util/io.go +++ b/pkg/util/io.go @@ -21,7 +21,7 @@ import ( "os/user" "strings" - "github.com/apache/skywalking-cli/logger" + "github.com/apache/skywalking-cli/internal/logger" ) // UserHomeDir returns the current user's home directory absolute path, diff --git a/util/lang.go b/pkg/util/lang.go similarity index 100% rename from util/lang.go rename to pkg/util/lang.go diff --git a/util/math.go b/pkg/util/math.go similarity index 100% rename from util/math.go rename to pkg/util/math.go diff --git a/hack/boilerplate.go.txt b/scripts/boilerplate.go.txt similarity index 100% rename from hack/boilerplate.go.txt rename to scripts/boilerplate.go.txt diff --git a/hack/build-header.sh b/scripts/build-header.sh similarity index 100% rename from hack/build-header.sh rename to scripts/build-header.sh diff --git a/test/test_commands.sh b/scripts/test_commands.sh similarity index 100% rename from test/test_commands.sh rename to scripts/test_commands.sh
