You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2019/11/09 14:12:54 UTC

[skywalking-cli] branch master updated (5d95a06 -> 6562efe)

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

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


    from 5d95a06  Merge pull request #4 from apache/fix/license
     new 298aff8  Motivation:
     new 8244ed8  Merge remote-tracking branch 'apache/master' into feature/graphql-client
     new 5223581  Remove stale files
     new f7f9910  Rename
     new 8d4c95f  Set up CI flow
     new d30b61d  Set up test coverage
     new b31dc3d  Redesign start end time when absent and present
     new 364978c  Redesign start end time when absent and present
     new 32df178  Polish comments of duration
     new 5535cc7  Polish if-else branches
     new c8eb90b  Fix typo
     new 6562efe  Merge pull request #6 from kezhenxu94/feature/graphql-client

The 25 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .asf.yaml                                          |  17 +
 .github/workflows/go.yml                           |  48 +-
 Makefile                                           |   5 +-
 commands/interceptor/duration.go                   | 130 ++++
 commands/interceptor/duration_test.go              | 150 +++++
 .../interceptor/interceptor.go                     |  27 +-
 swctl/service/service.go => commands/model/step.go |  38 +-
 commands/service/list.go                           |  75 +++
 {swctl => commands}/service/service.go             |  24 +-
 swctl/service/list.go => config/config.go          |   8 +-
 go.mod                                             |   4 +-
 go.sum                                             |   5 +
 cmd/main.go => graphql/client/client.go            |  47 +-
 graphql/schema/schema.go                           | 750 +++++++++++++++++++++
 logger/log.go                                      |   4 +-
 scripts/build                                      |   2 +-
 swctl/main.go                                      |  86 +++
 cmd/main.go => util/io.go                          |  40 +-
 18 files changed, 1339 insertions(+), 121 deletions(-)
 create mode 100644 commands/interceptor/duration.go
 create mode 100644 commands/interceptor/duration_test.go
 rename cmd/service.go => commands/interceptor/interceptor.go (71%)
 copy swctl/service/service.go => commands/model/step.go (53%)
 create mode 100644 commands/service/list.go
 rename {swctl => commands}/service/service.go (77%)
 rename swctl/service/list.go => config/config.go (89%)
 copy cmd/main.go => graphql/client/client.go (55%)
 create mode 100644 graphql/schema/schema.go
 create mode 100644 swctl/main.go
 rename cmd/main.go => util/io.go (61%)


[skywalking-cli] 06/25: Update go.yml

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 69cf83391952067f57e954c808d38c4a05a246fe
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Wed Nov 6 21:52:04 2019 +0800

    Update go.yml
---
 .github/workflows/go.yml | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 62aa1dd..a3a570e 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -1,3 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 name: Go
 on: [push, pull_request]
 jobs:


[skywalking-cli] 23/25: Polish if-else branches

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5535cc7de9241090d86a817d2f4ea0c6081aafb9
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Sat Nov 9 21:58:53 2019 +0800

    Polish if-else branches
---
 commands/interceptor/duration.go | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/commands/interceptor/duration.go b/commands/interceptor/duration.go
index def8e20..4207011 100644
--- a/commands/interceptor/duration.go
+++ b/commands/interceptor/duration.go
@@ -104,27 +104,17 @@ func ParseDuration(start string, end string) (time.Time, time.Time, schema.Step)
 		}
 
 		return startTime, endTime, step
-	}
-
-	// end is absent
-	if len(end) == 0 {
+	} else if len(end) <= 0 { // end is absent
 		if step, startTime, err = tryParseTime(start); err != nil {
 			logger.Log.Fatalln("Unsupported time format:", start, err)
 		}
 		return startTime, startTime.Add(30 * stepDuration[step]), step
-	}
-
-	// start is present
-	if len(start) == 0 {
+	} else { // start is present
 		if step, endTime, err = tryParseTime(end); err != nil {
 			logger.Log.Fatalln("Unsupported time format:", end, err)
 		}
 		return endTime.Add(-30 * stepDuration[step]), endTime, step
 	}
-
-	logger.Log.Fatalln("Should never happen")
-
-	return startTime, endTime, step
 }
 
 // AlignPrecision aligns the two time strings to same precision


[skywalking-cli] 03/25: Create NOTICE

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9cbbdffe423d59880b9236af7cfa7389f4592af9
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Wed Nov 6 21:48:52 2019 +0800

    Create NOTICE
---
 NOTICE | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..9617f83
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,5 @@
+Apache SkyWalking
+Copyright 2017-2019 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).


[skywalking-cli] 13/25: Merge pull request #4 from apache/fix/license

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5d95a06488ac455aa2cb6c0d191daf93961d23f4
Merge: f60a826 d74e098
Author: 吴晟 Wu Sheng <wu...@foxmail.com>
AuthorDate: Thu Nov 7 08:41:22 2019 +0800

    Merge pull request #4 from apache/fix/license
    
    Add missing license header

 Makefile                 | 19 ++++++++++++++++---
 cmd/main.go              | 18 ++++++++++++++++++
 cmd/service.go           | 18 ++++++++++++++++++
 logger/log.go            | 18 ++++++++++++++++++
 scripts/build            | 17 +++++++++++++++++
 swctl/service/list.go    | 18 ++++++++++++++++++
 swctl/service/service.go | 18 ++++++++++++++++++
 7 files changed, 123 insertions(+), 3 deletions(-)


[skywalking-cli] 08/25: Merge pull request #2 from apache/kezhenxu94-patch-2

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 265b188aeb22583ab4467069095455e586bda68b
Merge: 4e660c9 c23eea0
Author: 吴晟 Wu Sheng <wu...@foxmail.com>
AuthorDate: Wed Nov 6 22:13:09 2019 +0800

    Merge pull request #2 from apache/kezhenxu94-patch-2
    
    Set up GitHub Action for PR and push

 .github/workflows/go.yml | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)


[skywalking-cli] 12/25: Merge pull request #5 from apache/kezhenxu94-patch-1

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f60a82629bf00a46b527b794384f0f95d97dbb9b
Merge: d7789a9 8e8de7a
Author: 吴晟 Wu Sheng <wu...@foxmail.com>
AuthorDate: Wed Nov 6 23:43:01 2019 +0800

    Merge pull request #5 from apache/kezhenxu94-patch-1
    
    Create .asf.yaml

 .asf.yaml | 9 +++++++++
 1 file changed, 9 insertions(+)


[skywalking-cli] 20/25: Redesign start end time when absent and present

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit b31dc3d60fcdd49394bb278d1dddd1a6582579ce
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Sat Nov 9 20:02:42 2019 +0800

    Redesign start end time when absent and present
---
 commands/interceptor/duration.go      | 97 +++++++++++++++++++++--------------
 commands/interceptor/duration_test.go | 64 ++++++++++++++++++++---
 2 files changed, 116 insertions(+), 45 deletions(-)

diff --git a/commands/interceptor/duration.go b/commands/interceptor/duration.go
index 55c4b86..1be9974 100644
--- a/commands/interceptor/duration.go
+++ b/commands/interceptor/duration.go
@@ -26,32 +26,31 @@ import (
 )
 
 var stepFormats = map[schema.Step]string{
-	schema.StepSecond: "2006-01-02 1504",
+	schema.StepSecond: "2006-01-02 150400",
 	schema.StepMinute: "2006-01-02 1504",
 	schema.StepHour:   "2006-01-02 15",
 	schema.StepDay:    "2006-01-02",
-	schema.StepMonth:  "2006-01-02",
+	schema.StepMonth:  "2006-01",
 }
 
-var supportedTimeLayouts = []string{
-	"2006-01-02 150400",
-	"2006-01-02 1504",
-	"2006-01-02 15",
-	"2006-01-02",
-	"2006-01",
+var stepDuration = map[schema.Step]time.Duration{
+	schema.StepSecond: time.Second,
+	schema.StepMinute: time.Minute,
+	schema.StepHour:   time.Hour,
+	schema.StepDay:    time.Hour * 24,
+	schema.StepMonth:  time.Hour * 24 * 30,
 }
 
-func tryParseTime(unparsed string, parsed *time.Time) error {
+func tryParseTime(unparsed string) (schema.Step, time.Time, error) {
 	var possibleError error = nil
-	for _, layout := range supportedTimeLayouts {
+	for step, layout := range stepFormats {
 		t, err := time.Parse(layout, unparsed)
 		if err == nil {
-			*parsed = t
-			return nil
+			return step, t, nil
 		}
 		possibleError = err
 	}
-	return possibleError
+	return schema.StepSecond, time.Time{}, possibleError
 }
 
 // DurationInterceptor sets the duration if absent, and formats it accordingly,
@@ -80,42 +79,62 @@ func DurationInterceptor(ctx *cli.Context) error {
 // in the format, (e.g. 2019-11-09 1001), so they'll be considered as UTC-based,
 // and generate the missing `start`(`end`) based on the same timezone, UTC
 func ParseDuration(start string, end string) (time.Time, time.Time, schema.Step) {
+	logger.Log.Debugln("Start time:", start, "end time:", end)
+
 	now := time.Now().UTC()
 
-	startTime := now
-	endTime := now
-	logger.Log.Debugln("Start time:", start, "end time:", end)
-	if len(start) == 0 && len(end) == 0 { // both absent
-		startTime = now.Add(-30 * time.Minute)
-		endTime = now
-	} else if len(end) == 0 { // start is present
-		if err := tryParseTime(start, &startTime); err != nil {
+	// both are absent
+	if len(start) == 0 && len(end) == 0 {
+		return now.Add(-30 * time.Minute), now, schema.StepMinute
+	}
+
+	var startTime, endTime time.Time
+	var step schema.Step
+	var err error
+
+	// both are present
+	if len(start) > 0 && len(end) > 0 {
+		start, end = AlignPrecision(start, end)
+
+		if step, startTime, err = tryParseTime(start); err != nil {
 			logger.Log.Fatalln("Unsupported time format:", start, err)
 		}
-	} else if len(start) == 0 { // end is present
-		if err := tryParseTime(end, &endTime); err != nil {
+		if step, endTime, err = tryParseTime(end); err != nil {
 			logger.Log.Fatalln("Unsupported time format:", end, err)
 		}
-	} else { // both are present
-		if err := tryParseTime(start, &startTime); err != nil {
+
+		return startTime, endTime, step
+	}
+
+	// end is absent
+	if len(end) == 0 {
+		if step, startTime, err = tryParseTime(start); err != nil {
 			logger.Log.Fatalln("Unsupported time format:", start, err)
 		}
-		if err := tryParseTime(end, &endTime); err != nil {
+		return startTime, startTime.Add(30 * stepDuration[step]), step
+	}
+
+	// start is present
+	if len(start) == 0 {
+		if step, endTime, err = tryParseTime(end); err != nil {
 			logger.Log.Fatalln("Unsupported time format:", end, err)
 		}
+		return endTime.Add(-30 * stepDuration[step]), endTime, step
 	}
-	duration := endTime.Sub(startTime)
-	step := schema.StepSecond
-	if duration.Hours() >= 24*30 { // time range > 1 month
-		step = schema.StepMonth
-	} else if duration.Hours() > 24 { // time range > 1 day
-		step = schema.StepDay
-	} else if duration.Minutes() > 60 { // time range > 1 hour
-		step = schema.StepHour
-	} else if duration.Seconds() > 60 { // time range > 1 minute
-		step = schema.StepMinute
-	} else if duration.Seconds() <= 0 { // illegal
-		logger.Log.Fatalln("end time must be later than start time, end time:", endTime, ", start time:", startTime)
-	}
+
+	logger.Log.Fatalln("Should never happen")
+
 	return startTime, endTime, step
 }
+
+// AlignPrecision aligns the two time strings to same precision
+// by truncating the more precise one
+func AlignPrecision(start string, end string) (string, string) {
+	if len(start) < len(end) {
+		return start, end[0:len(start)]
+	}
+	if len(start) > len(end) {
+		return start[0:len(end)], end
+	}
+	return start, end
+}
diff --git a/commands/interceptor/duration_test.go b/commands/interceptor/duration_test.go
index 7879cfd..c9b587d 100644
--- a/commands/interceptor/duration_test.go
+++ b/commands/interceptor/duration_test.go
@@ -44,20 +44,20 @@ func TestParseDuration(t *testing.T) {
 			name: "Should set current time if start is absent",
 			args: args{
 				start: "",
-				end:   now.Add(10 * time.Minute).Format(timeFormat),
+				end:   now.Format(timeFormat),
 			},
-			wantedStartTime: now,
-			wantedEndTime:   now.Add(10 * time.Minute),
+			wantedStartTime: now.Add(-30 * time.Minute),
+			wantedEndTime:   now,
 			wantedStep:      schema.StepMinute,
 		},
 		{
 			name: "Should set current time if end is absent",
 			args: args{
-				start: now.Add(-10 * time.Minute).Format(timeFormat),
+				start: now.Format(timeFormat),
 				end:   "",
 			},
-			wantedStartTime: now.Add(-10 * time.Minute),
-			wantedEndTime:   now,
+			wantedStartTime: now,
+			wantedEndTime:   now.Add(30 * time.Minute),
 			wantedStep:      schema.StepMinute,
 		},
 		{
@@ -96,3 +96,55 @@ func TestParseDuration(t *testing.T) {
 		})
 	}
 }
+
+func TestAlignPrecision(t *testing.T) {
+	type args struct {
+		start string
+		end   string
+	}
+	tests := []struct {
+		name        string
+		args        args
+		wantedStart string
+		wantedEnd   string
+	}{
+		{
+			name: "Should keep both when same precision",
+			args: args{
+				start: "2019-01-01",
+				end:   "2019-01-01",
+			},
+			wantedStart: "2019-01-01",
+			wantedEnd:   "2019-01-01",
+		},
+		{
+			name: "Should truncate start when it's less precise",
+			args: args{
+				start: "2019-01-01 1200",
+				end:   "2019-01-01",
+			},
+			wantedStart: "2019-01-01",
+			wantedEnd:   "2019-01-01",
+		},
+		{
+			name: "Should truncate end when it's less precise",
+			args: args{
+				start: "2019-01-01",
+				end:   "2019-01-01 1200",
+			},
+			wantedStart: "2019-01-01",
+			wantedEnd:   "2019-01-01",
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			gotStart, gotEnd := AlignPrecision(tt.args.start, tt.args.end)
+			if gotStart != tt.wantedStart {
+				t.Errorf("AlignPrecision() gotStart = %v, wantedStart %v", gotStart, tt.wantedStart)
+			}
+			if gotEnd != tt.wantedEnd {
+				t.Errorf("AlignPrecision() gotEnd = %v, wantedStart %v", gotEnd, tt.wantedEnd)
+			}
+		})
+	}
+}


[skywalking-cli] 11/25: Create .asf.yaml

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8e8de7a15e3b681484a7311c8432552fe5338876
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Wed Nov 6 23:23:31 2019 +0800

    Create .asf.yaml
---
 .asf.yaml | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/.asf.yaml b/.asf.yaml
new file mode 100644
index 0000000..3f2645a
--- /dev/null
+++ b/.asf.yaml
@@ -0,0 +1,9 @@
+github:
+  description: Apache SkyWalking CLI
+  homepage: https://skywalking.apache.org/
+  labels:
+    - skywalking
+    - observability
+    - apm
+    - distributed-tracing
+    - cli


[skywalking-cli] 02/25: Add license file

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 866e17f0f611c3540724fce31b3b1fdd62e19598
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Wed Nov 6 21:43:56 2019 +0800

    Add license file
---
 LICENSE | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 201 insertions(+)

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..79342a6
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright {yyyy} {name of copyright owner}
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.


[skywalking-cli] 22/25: Polish comments of duration

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 32df1785d83c7e103dfb4a03ac820a816fd7e1e4
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Sat Nov 9 20:57:57 2019 +0800

    Polish comments of duration
---
 commands/interceptor/duration.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/commands/interceptor/duration.go b/commands/interceptor/duration.go
index 88468ec..def8e20 100644
--- a/commands/interceptor/duration.go
+++ b/commands/interceptor/duration.go
@@ -73,8 +73,8 @@ func DurationInterceptor(ctx *cli.Context) error {
 
 // ParseDuration parses the `start` and `end` to a triplet, (startTime, endTime, step)
 // if --start and --end are both absent, then: start := now - 30min; end := now
-// if --start is given, --end is absent, then: end := now
-// if --start is absent, --end is given, then: start := end - 30min
+// if --start is given, --end is absent, 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 unis, where unit is the precision of `end`, (hours, minutes, etc.)
 // NOTE that when either(both) `start` or `end` is(are) given, there is no timezone info
 // in the format, (e.g. 2019-11-09 1001), so they'll be considered as UTC-based,
 // and generate the missing `start`(`end`) based on the same timezone, UTC


[skywalking-cli] 17/25: Rename

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f7f99100250e7aaf4b4376ca91eaa032167f8714
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Thu Nov 7 21:54:51 2019 +0800

    Rename
---
 graphql/client/client.go | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/graphql/client/client.go b/graphql/client/client.go
index 10a680a..0b050e3 100644
--- a/graphql/client/client.go
+++ b/graphql/client/client.go
@@ -33,7 +33,7 @@ func Services(duration schema.Duration) []schema.Service {
 		logger.Log.Debugln(msg)
 	}
 
-	var services map[string][]schema.Service
+	var response map[string][]schema.Service
 	request := graphql.NewRequest(`
 		query ($duration: Duration!) {
 			services: getAllServices(duration: $duration) {
@@ -42,10 +42,10 @@ func Services(duration schema.Duration) []schema.Service {
 		}
 	`)
 	request.Var("duration", duration)
-	if err := client.Run(ctx, request, &services); err != nil {
+	if err := client.Run(ctx, request, &response); err != nil {
 		logger.Log.Fatalln(err)
 		panic(err)
 	}
 
-	return services["services"]
+	return response["services"]
 }


[skywalking-cli] 25/25: Merge pull request #6 from kezhenxu94/feature/graphql-client

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 6562efe2fe837cd574e2ee622bbc4a04c5cd5301
Merge: 5d95a06 c8eb90b
Author: 吴晟 Wu Sheng <wu...@foxmail.com>
AuthorDate: Sat Nov 9 22:12:49 2019 +0800

    Merge pull request #6 from kezhenxu94/feature/graphql-client
    
    [Feature] Set GraphQL client and add service ls command

 .asf.yaml                                          |  17 +
 .github/workflows/go.yml                           |  48 +-
 Makefile                                           |   5 +-
 commands/interceptor/duration.go                   | 130 ++++
 commands/interceptor/duration_test.go              | 150 +++++
 .../interceptor/interceptor.go                     |  27 +-
 swctl/service/service.go => commands/model/step.go |  38 +-
 commands/service/list.go                           |  75 +++
 {swctl => commands}/service/service.go             |  24 +-
 swctl/service/list.go => config/config.go          |   8 +-
 go.mod                                             |   4 +-
 go.sum                                             |   5 +
 cmd/main.go => graphql/client/client.go            |  47 +-
 graphql/schema/schema.go                           | 750 +++++++++++++++++++++
 logger/log.go                                      |   4 +-
 scripts/build                                      |   2 +-
 swctl/main.go                                      |  86 +++
 cmd/main.go => util/io.go                          |  40 +-
 18 files changed, 1339 insertions(+), 121 deletions(-)


[skywalking-cli] 15/25: Merge remote-tracking branch 'apache/master' into feature/graphql-client

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8244ed863e4dfc791c5c79b2d7ae469a1efdbbf1
Merge: 298aff8 5d95a06
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Thu Nov 7 19:06:44 2019 +0800

    Merge remote-tracking branch 'apache/master' into feature/graphql-client

 cmd/main.go              | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
 cmd/service.go           | 42 ++++++++++++++++++++++++++++++++++++++++
 swctl/service/list.go    | 23 ++++++++++++++++++++++
 swctl/service/service.go | 42 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 157 insertions(+)


[skywalking-cli] 24/25: Fix typo

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit c8eb90b64f2765cd13ea84b6932c5f3c571f58ba
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Sat Nov 9 21:59:31 2019 +0800

    Fix typo
---
 commands/interceptor/duration.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/interceptor/duration.go b/commands/interceptor/duration.go
index 4207011..acd1d67 100644
--- a/commands/interceptor/duration.go
+++ b/commands/interceptor/duration.go
@@ -109,7 +109,7 @@ func ParseDuration(start string, end string) (time.Time, time.Time, schema.Step)
 			logger.Log.Fatalln("Unsupported time format:", start, err)
 		}
 		return startTime, startTime.Add(30 * stepDuration[step]), step
-	} else { // start is present
+	} else { // start is absent
 		if step, endTime, err = tryParseTime(end); err != nil {
 			logger.Log.Fatalln("Unsupported time format:", end, err)
 		}


[skywalking-cli] 18/25: Set up CI flow

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8d4c95f758cf7cce163119cb2656b04ad5849824
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Sat Nov 9 12:34:35 2019 +0800

    Set up CI flow
---
 .github/workflows/go.yml                           |  12 +-
 commands/interceptor.go                            |  71 ------------
 commands/interceptor/duration.go                   | 121 +++++++++++++++++++++
 commands/interceptor/duration_test.go              |  98 +++++++++++++++++
 .../log.go => commands/interceptor/interceptor.go  |  25 ++---
 commands/{model.go => model/step.go}               |   5 +-
 commands/service/list.go                           |  24 ++--
 config/config.go                                   |   2 +-
 go.mod                                             |   1 +
 graphql/client/client.go                           |   2 +-
 logger/log.go                                      |   4 +-
 swctl/main.go                                      |  14 +--
 commands/model.go => util/io.go                    |  39 +++----
 13 files changed, 287 insertions(+), 131 deletions(-)

diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 1abc12e..de9ad27 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -40,5 +40,15 @@ jobs:
               dep ensure
           fi
 
+      - name: Lint
+        run: |
+          curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.21.0
+          $(go env GOPATH)/bin/golangci-lint run -v ./...
+
+      - name: Test
+        run: |
+          go test ./... -coverprofile=coverage.txt -covermode=atomic
+          bash <(curl -s https://codecov.io/bash)
+
       - name: Build
-        run: make
+        run: make clean && make
diff --git a/commands/interceptor.go b/commands/interceptor.go
deleted file mode 100644
index 6837529..0000000
--- a/commands/interceptor.go
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package commands
-
-import (
-	"github.com/apache/skywalking-cli/graphql/schema"
-	"github.com/apache/skywalking-cli/logger"
-	"github.com/urfave/cli"
-	"time"
-)
-
-// Convenient function to chain up multiple cli.BeforeFunc
-func BeforeChain(beforeFunctions []cli.BeforeFunc) cli.BeforeFunc {
-	return func(ctx *cli.Context) error {
-		for _, beforeFunc := range beforeFunctions {
-			if err := beforeFunc(ctx); err != nil {
-				return err
-			}
-		}
-		return nil
-	}
-}
-
-var StepFormats = map[schema.Step]string{
-	schema.StepMonth:  "2006-01-02",
-	schema.StepDay:    "2006-01-02",
-	schema.StepHour:   "2006-01-02 15",
-	schema.StepMinute: "2006-01-02 1504",
-	schema.StepSecond: "2006-01-02 1504",
-}
-
-// Set the duration if not set, and format it according to
-// the given step
-func SetUpDuration(ctx *cli.Context) error {
-	step := ctx.Generic("step").(*StepEnumValue).Selected
-	end := ctx.String("end")
-	if len(end) == 0 {
-		end = time.Now().Format(StepFormats[step])
-		logger.Log.Debugln("Missing --end, defaults to", end)
-		if err := ctx.Set("end", end); err != nil {
-			return err
-		}
-	}
-
-	start := ctx.String("start")
-	if len(start) == 0 {
-		start = time.Now().Add(-15 * time.Minute).Format(StepFormats[step])
-		logger.Log.Debugln("Missing --start, defaults to", start)
-		if err := ctx.Set("start", start); err != nil {
-			return err
-		}
-	}
-
-	return nil
-}
diff --git a/commands/interceptor/duration.go b/commands/interceptor/duration.go
new file mode 100644
index 0000000..55c4b86
--- /dev/null
+++ b/commands/interceptor/duration.go
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package interceptor
+
+import (
+	"github.com/apache/skywalking-cli/graphql/schema"
+	"github.com/apache/skywalking-cli/logger"
+	"github.com/urfave/cli"
+	"time"
+)
+
+var stepFormats = map[schema.Step]string{
+	schema.StepSecond: "2006-01-02 1504",
+	schema.StepMinute: "2006-01-02 1504",
+	schema.StepHour:   "2006-01-02 15",
+	schema.StepDay:    "2006-01-02",
+	schema.StepMonth:  "2006-01-02",
+}
+
+var supportedTimeLayouts = []string{
+	"2006-01-02 150400",
+	"2006-01-02 1504",
+	"2006-01-02 15",
+	"2006-01-02",
+	"2006-01",
+}
+
+func tryParseTime(unparsed string, parsed *time.Time) error {
+	var possibleError error = nil
+	for _, layout := range supportedTimeLayouts {
+		t, err := time.Parse(layout, unparsed)
+		if err == nil {
+			*parsed = t
+			return nil
+		}
+		possibleError = err
+	}
+	return possibleError
+}
+
+// DurationInterceptor sets the duration if absent, and formats it accordingly,
+// see ParseDuration
+func DurationInterceptor(ctx *cli.Context) error {
+	start := ctx.String("start")
+	end := ctx.String("end")
+
+	startTime, endTime, step := ParseDuration(start, end)
+
+	if err := ctx.Set("start", startTime.Format(stepFormats[step])); err != nil {
+		return err
+	} else if err := ctx.Set("end", endTime.Format(stepFormats[step])); err != nil {
+		return err
+	} else if err := ctx.Set("step", step.String()); err != nil {
+		return err
+	}
+	return nil
+}
+
+// ParseDuration parses the `start` and `end` to a triplet, (startTime, endTime, step)
+// if --start and --end are both absent, then: start := now - 30min; end := now
+// if --start is given, --end is absent, then: end := now
+// if --start is absent, --end is given, then: start := end - 30min
+// NOTE that when either(both) `start` or `end` is(are) given, there is no timezone info
+// in the format, (e.g. 2019-11-09 1001), so they'll be considered as UTC-based,
+// and generate the missing `start`(`end`) based on the same timezone, UTC
+func ParseDuration(start string, end string) (time.Time, time.Time, schema.Step) {
+	now := time.Now().UTC()
+
+	startTime := now
+	endTime := now
+	logger.Log.Debugln("Start time:", start, "end time:", end)
+	if len(start) == 0 && len(end) == 0 { // both absent
+		startTime = now.Add(-30 * time.Minute)
+		endTime = now
+	} else if len(end) == 0 { // start is present
+		if err := tryParseTime(start, &startTime); err != nil {
+			logger.Log.Fatalln("Unsupported time format:", start, err)
+		}
+	} else if len(start) == 0 { // end is present
+		if err := tryParseTime(end, &endTime); err != nil {
+			logger.Log.Fatalln("Unsupported time format:", end, err)
+		}
+	} else { // both are present
+		if err := tryParseTime(start, &startTime); err != nil {
+			logger.Log.Fatalln("Unsupported time format:", start, err)
+		}
+		if err := tryParseTime(end, &endTime); err != nil {
+			logger.Log.Fatalln("Unsupported time format:", end, err)
+		}
+	}
+	duration := endTime.Sub(startTime)
+	step := schema.StepSecond
+	if duration.Hours() >= 24*30 { // time range > 1 month
+		step = schema.StepMonth
+	} else if duration.Hours() > 24 { // time range > 1 day
+		step = schema.StepDay
+	} else if duration.Minutes() > 60 { // time range > 1 hour
+		step = schema.StepHour
+	} else if duration.Seconds() > 60 { // time range > 1 minute
+		step = schema.StepMinute
+	} else if duration.Seconds() <= 0 { // illegal
+		logger.Log.Fatalln("end time must be later than start time, end time:", endTime, ", start time:", startTime)
+	}
+	return startTime, endTime, step
+}
diff --git a/commands/interceptor/duration_test.go b/commands/interceptor/duration_test.go
new file mode 100644
index 0000000..7879cfd
--- /dev/null
+++ b/commands/interceptor/duration_test.go
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package interceptor
+
+import (
+	"github.com/apache/skywalking-cli/graphql/schema"
+	"reflect"
+	"testing"
+	"time"
+)
+
+func TestParseDuration(t *testing.T) {
+	now := time.Now().UTC()
+
+	type args struct {
+		start string
+		end   string
+	}
+	timeFormat := "2006-01-02 1504"
+	tests := []struct {
+		name            string
+		args            args
+		wantedStartTime time.Time
+		wantedEndTime   time.Time
+		wantedStep      schema.Step
+	}{
+		{
+			name: "Should set current time if start is absent",
+			args: args{
+				start: "",
+				end:   now.Add(10 * time.Minute).Format(timeFormat),
+			},
+			wantedStartTime: now,
+			wantedEndTime:   now.Add(10 * time.Minute),
+			wantedStep:      schema.StepMinute,
+		},
+		{
+			name: "Should set current time if end is absent",
+			args: args{
+				start: now.Add(-10 * time.Minute).Format(timeFormat),
+				end:   "",
+			},
+			wantedStartTime: now.Add(-10 * time.Minute),
+			wantedEndTime:   now,
+			wantedStep:      schema.StepMinute,
+		},
+		{
+			name: "Should keep both if both are present",
+			args: args{
+				start: now.Add(-10 * time.Minute).Format(timeFormat),
+				end:   now.Add(10 * time.Minute).Format(timeFormat),
+			},
+			wantedStartTime: now.Add(-10 * time.Minute),
+			wantedEndTime:   now.Add(10 * time.Minute),
+			wantedStep:      schema.StepMinute,
+		},
+		{
+			name: "Should set both if both are absent",
+			args: args{
+				start: "",
+				end:   "",
+			},
+			wantedStartTime: now.Add(-30 * time.Minute),
+			wantedEndTime:   now,
+			wantedStep:      schema.StepMinute,
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			gotStartTime, gotEndTime, gotStep := ParseDuration(tt.args.start, tt.args.end)
+			if !reflect.DeepEqual(gotStartTime.Truncate(time.Minute), tt.wantedStartTime.Truncate(time.Minute)) {
+				t.Errorf("ParseDuration() got start time = %v, wanted start time %v", gotStartTime.Truncate(time.Minute), tt.wantedStartTime.Truncate(time.Minute))
+			}
+			if !reflect.DeepEqual(gotEndTime.Truncate(time.Minute), tt.wantedEndTime.Truncate(time.Minute)) {
+				t.Errorf("ParseDuration() got end time = %v, wanted end time %v", gotEndTime.Truncate(time.Minute), tt.wantedEndTime.Truncate(time.Minute))
+			}
+			if gotStep != tt.wantedStep {
+				t.Errorf("ParseDuration() got step = %v, wanted step %v", gotStep, tt.wantedStep)
+			}
+		})
+	}
+}
diff --git a/logger/log.go b/commands/interceptor/interceptor.go
similarity index 69%
copy from logger/log.go
copy to commands/interceptor/interceptor.go
index 4a5d482..111b73b 100644
--- a/logger/log.go
+++ b/commands/interceptor/interceptor.go
@@ -16,23 +16,20 @@
  *
  */
 
-package logger
+package interceptor
 
 import (
-	"os"
-
-	"github.com/sirupsen/logrus"
+	"github.com/urfave/cli"
 )
 
-var Log *logrus.Logger
-
-func init() {
-	if Log == nil {
-		Log = logrus.New()
+// BeforeChain is a convenient function to chain up multiple cli.BeforeFunc
+func BeforeChain(beforeFunctions []cli.BeforeFunc) cli.BeforeFunc {
+	return func(ctx *cli.Context) error {
+		for _, beforeFunc := range beforeFunctions {
+			if err := beforeFunc(ctx); err != nil {
+				return err
+			}
+		}
+		return nil
 	}
-	Log.SetOutput(os.Stdout)
-	Log.SetFormatter(&logrus.TextFormatter{
-		FullTimestamp:   true,
-		TimestampFormat: "2006-01-02 15:04:05",
-	})
 }
diff --git a/commands/model.go b/commands/model/step.go
similarity index 89%
copy from commands/model.go
copy to commands/model/step.go
index 9da2fba..eed3b3f 100644
--- a/commands/model.go
+++ b/commands/model/step.go
@@ -16,7 +16,7 @@
  *
  */
 
-package commands
+package model
 
 import (
 	"fmt"
@@ -24,12 +24,14 @@ import (
 	"strings"
 )
 
+// StepEnumValue defines the values domain of --step option
 type StepEnumValue struct {
 	Enum     []schema.Step
 	Default  schema.Step
 	Selected schema.Step
 }
 
+// Set the --step value, from raw string to StepEnumValue
 func (s *StepEnumValue) Set(value string) error {
 	for _, enum := range s.Enum {
 		if enum.String() == value {
@@ -44,6 +46,7 @@ func (s *StepEnumValue) Set(value string) error {
 	return fmt.Errorf("allowed steps are %s", strings.Join(steps, ", "))
 }
 
+// String representation of the step
 func (s StepEnumValue) String() string {
 	return s.Selected.String()
 }
diff --git a/commands/service/list.go b/commands/service/list.go
index e2c91af..257bc3a 100644
--- a/commands/service/list.go
+++ b/commands/service/list.go
@@ -21,7 +21,8 @@ package service
 import (
 	"encoding/json"
 	"fmt"
-	"github.com/apache/skywalking-cli/commands"
+	"github.com/apache/skywalking-cli/commands/interceptor"
+	"github.com/apache/skywalking-cli/commands/model"
 	"github.com/apache/skywalking-cli/graphql/client"
 	"github.com/apache/skywalking-cli/graphql/schema"
 	"github.com/urfave/cli"
@@ -34,23 +35,24 @@ var ListCommand = cli.Command{
 	Flags: []cli.Flag{
 		cli.StringFlag{
 			Name:  "start",
-			Usage: "Query start time",
+			Usage: "query start `TIME`",
 		},
 		cli.StringFlag{
 			Name:  "end",
-			Usage: "Query end time",
+			Usage: "query end `TIME`",
 		},
 		cli.GenericFlag{
-			Name: "step",
-			Value: &commands.StepEnumValue{
+			Name:   "step",
+			Hidden: true,
+			Value: &model.StepEnumValue{
 				Enum:     schema.AllStep,
 				Default:  schema.StepMinute,
 				Selected: schema.StepMinute,
 			},
 		},
 	},
-	Before: commands.BeforeChain([]cli.BeforeFunc{
-		commands.SetUpDuration,
+	Before: interceptor.BeforeChain([]cli.BeforeFunc{
+		interceptor.DurationInterceptor,
 	}),
 	Action: func(ctx *cli.Context) error {
 		end := ctx.String("end")
@@ -59,13 +61,13 @@ var ListCommand = cli.Command{
 		services := client.Services(schema.Duration{
 			Start: start,
 			End:   end,
-			Step:  step.(*commands.StepEnumValue).Selected,
+			Step:  step.(*model.StepEnumValue).Selected,
 		})
 
-		if bytes, e := json.Marshal(services); e != nil {
-			return e
-		} else {
+		if bytes, e := json.Marshal(services); e == nil {
 			fmt.Printf("%v\n", string(bytes))
+		} else {
+			return e
 		}
 
 		return nil
diff --git a/config/config.go b/config/config.go
index bc33da2..0565fee 100644
--- a/config/config.go
+++ b/config/config.go
@@ -20,6 +20,6 @@ package config
 
 var Config struct {
 	Global struct {
-		BaseUrl string `yaml:"base-url"`
+		BaseURL string `yaml:"base-url"`
 	}
 }
diff --git a/go.mod b/go.mod
index 062d750..ad56fce 100644
--- a/go.mod
+++ b/go.mod
@@ -7,4 +7,5 @@ require (
 	github.com/pkg/errors v0.8.1 // indirect
 	github.com/sirupsen/logrus v1.4.2
 	github.com/urfave/cli v1.22.1
+	gopkg.in/yaml.v2 v2.2.2
 )
diff --git a/graphql/client/client.go b/graphql/client/client.go
index 0b050e3..d74f5c3 100644
--- a/graphql/client/client.go
+++ b/graphql/client/client.go
@@ -28,7 +28,7 @@ import (
 
 func Services(duration schema.Duration) []schema.Service {
 	ctx := context.Background()
-	client := graphql.NewClient(config.Config.Global.BaseUrl)
+	client := graphql.NewClient(config.Config.Global.BaseURL)
 	client.Log = func(msg string) {
 		logger.Log.Debugln(msg)
 	}
diff --git a/logger/log.go b/logger/log.go
index 4a5d482..ce1cda7 100644
--- a/logger/log.go
+++ b/logger/log.go
@@ -32,7 +32,7 @@ func init() {
 	}
 	Log.SetOutput(os.Stdout)
 	Log.SetFormatter(&logrus.TextFormatter{
-		FullTimestamp:   true,
-		TimestampFormat: "2006-01-02 15:04:05",
+		DisableTimestamp:       true,
+		DisableLevelTruncation: true,
 	})
 }
diff --git a/swctl/main.go b/swctl/main.go
index 5619a28..2f3f967 100644
--- a/swctl/main.go
+++ b/swctl/main.go
@@ -22,13 +22,13 @@ import (
 	"encoding/json"
 	"github.com/apache/skywalking-cli/commands/service"
 	"github.com/apache/skywalking-cli/config"
+	"github.com/apache/skywalking-cli/logger"
+	"github.com/apache/skywalking-cli/util"
 	"github.com/sirupsen/logrus"
 	"github.com/urfave/cli"
 	"gopkg.in/yaml.v2"
 	"io/ioutil"
 	"os"
-
-	"github.com/apache/skywalking-cli/logger"
 )
 
 var log *logrus.Logger
@@ -43,8 +43,8 @@ func main() {
 	app.Flags = []cli.Flag{
 		cli.StringFlag{
 			Name:  "config",
-			Value: "./settings.yml",
-			Usage: "load configuration `FILE`, default to ./settings.yml",
+			Value: "~/.skywalking.yml",
+			Usage: "load configuration `FILE`",
 		},
 		cli.BoolFlag{
 			Name:     "debug",
@@ -56,20 +56,20 @@ func main() {
 		service.Command,
 	}
 
-	app.Before = BeforeCommand
+	app.Before = beforeCommand
 
 	if err := app.Run(os.Args); err != nil {
 		log.Fatalln(err)
 	}
 }
 
-func BeforeCommand(c *cli.Context) error {
+func beforeCommand(c *cli.Context) error {
 	if c.Bool("debug") {
 		log.SetLevel(logrus.DebugLevel)
 		log.Debugln("Debug mode is enabled")
 	}
 
-	configFile := c.String("config")
+	configFile := util.ExpandFilePath(c.String("config"))
 	log.Debugln("Using configuration file:", configFile)
 
 	if bytes, err := ioutil.ReadFile(configFile); err != nil {
diff --git a/commands/model.go b/util/io.go
similarity index 59%
rename from commands/model.go
rename to util/io.go
index 9da2fba..5156856 100644
--- a/commands/model.go
+++ b/util/io.go
@@ -16,34 +16,29 @@
  *
  */
 
-package commands
+package util
 
 import (
-	"fmt"
-	"github.com/apache/skywalking-cli/graphql/schema"
+	"github.com/apache/skywalking-cli/logger"
+	"os/user"
 	"strings"
 )
 
-type StepEnumValue struct {
-	Enum     []schema.Step
-	Default  schema.Step
-	Selected schema.Step
-}
-
-func (s *StepEnumValue) Set(value string) error {
-	for _, enum := range s.Enum {
-		if enum.String() == value {
-			s.Selected = enum
-			return nil
-		}
+// UserHomeDir returns the current user's home directory absolute path,
+// which is usually represented as `~` in most shells
+func UserHomeDir() string {
+	if currentUser, err := user.Current(); err != nil {
+		logger.Log.Warnln("Cannot obtain user home directory")
+	} else {
+		return currentUser.HomeDir
 	}
-	steps := make([]string, len(schema.AllStep))
-	for i, step := range schema.AllStep {
-		steps[i] = step.String()
-	}
-	return fmt.Errorf("allowed steps are %s", strings.Join(steps, ", "))
+	return ""
 }
 
-func (s StepEnumValue) String() string {
-	return s.Selected.String()
+// ExpandFilePath expands the leading `~` to absolute path
+func ExpandFilePath(path string) string {
+	if strings.HasPrefix(path, "~") {
+		return strings.Replace(path, "~", UserHomeDir(), 1)
+	}
+	return path
 }


[skywalking-cli] 09/25: Update README.md (#3)

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d7789a9eb1c6e557764aa162769036a8fd856f1e
Author: 吴晟 Wu Sheng <wu...@foxmail.com>
AuthorDate: Wed Nov 6 22:18:26 2019 +0800

    Update README.md (#3)
---
 README.md | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index eaf2c6a..2e110f2 100644
--- a/README.md
+++ b/README.md
@@ -3,4 +3,16 @@ Apache SkyWalking CLI
 
 <img src="http://skywalking.apache.org/assets/logo.svg" alt="Sky Walking logo" height="90px" align="right" />
 
-The CLI for [Apache SkyWalking](https://github.com/apache/skywalking).
\ No newline at end of file
+The CLI (Command Line Interface) for [Apache SkyWalking](https://github.com/apache/skywalking).
+
+SkyWalking CLI is a command interaction tool for the SkyWalking user or OPS team, as an alternative besides using browser GUI.
+It is based on SkyWalking [GraphQL query protocol](https://github.com/apache/skywalking-query-protocol), same as GUI.
+
+# Commands
+TODO
+
+# Compiling project
+TODO
+
+# License
+[Apache 2.0 License.](/LICENSE)


[skywalking-cli] 05/25: Set up GitHub Action for PR and push

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a2ca521cf7eb6844a5e8ed9e9fb21f89a518246b
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Wed Nov 6 21:51:14 2019 +0800

    Set up GitHub Action for PR and push
---
 .github/workflows/go.yml | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
new file mode 100644
index 0000000..62aa1dd
--- /dev/null
+++ b/.github/workflows/go.yml
@@ -0,0 +1,28 @@
+name: Go
+on: [push, pull_request]
+jobs:
+
+  build:
+    name: Build
+    runs-on: ubuntu-latest
+    steps:
+
+    - name: Set up Go 1.13
+      uses: actions/setup-go@v1
+      with:
+        go-version: 1.13
+      id: go
+
+    - name: Check out code into the Go module directory
+      uses: actions/checkout@v1
+
+    - name: Get dependencies
+      run: |
+        go get -v -t -d ./...
+        if [ -f Gopkg.toml ]; then
+            curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
+            dep ensure
+        fi
+
+    - name: Build
+      run: go build -v .


[skywalking-cli] 07/25: Update go.yml

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit c23eea01828c7594931af87c5db3f563347ed7b9
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Wed Nov 6 21:55:37 2019 +0800

    Update go.yml
---
 .github/workflows/go.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index a3a570e..bdc008c 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -41,4 +41,4 @@ jobs:
         fi
 
     - name: Build
-      run: go build -v .
+      run: make


[skywalking-cli] 01/25: Initialization project

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a289a59a2f3b62cbfe3e084f16081bec5b1a7090
Author: heyanlong <ya...@gmail.com>
AuthorDate: Wed Nov 6 12:05:58 2019 +0800

    Initialization project
---
 .gitignore               |  2 ++
 Makefile                 |  9 +++++++++
 README.md                |  6 ++++++
 cmd/main.go              | 32 ++++++++++++++++++++++++++++++++
 cmd/service.go           | 24 ++++++++++++++++++++++++
 go.mod                   |  9 +++++++++
 go.sum                   | 22 ++++++++++++++++++++++
 logger/log.go            | 20 ++++++++++++++++++++
 scripts/build            | 11 +++++++++++
 swctl/service/list.go    |  5 +++++
 swctl/service/service.go | 24 ++++++++++++++++++++++++
 11 files changed, 164 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..25c3120
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+.idea
+bin
\ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..aa368e7
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,9 @@
+# Example:
+#   make build
+#   make install
+
+.PHONY: build install
+
+build:
+	GO_BUILD_FLAGS="-v" ./scripts/build
+	./bin/swctl --version
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..eaf2c6a
--- /dev/null
+++ b/README.md
@@ -0,0 +1,6 @@
+Apache SkyWalking CLI
+===============
+
+<img src="http://skywalking.apache.org/assets/logo.svg" alt="Sky Walking logo" height="90px" align="right" />
+
+The CLI for [Apache SkyWalking](https://github.com/apache/skywalking).
\ No newline at end of file
diff --git a/cmd/main.go b/cmd/main.go
new file mode 100644
index 0000000..e4969db
--- /dev/null
+++ b/cmd/main.go
@@ -0,0 +1,32 @@
+package main
+
+import (
+	"os"
+
+	"github.com/sirupsen/logrus"
+	"github.com/urfave/cli"
+
+	"github.com/apache/skywalking-cli/logger"
+)
+
+var log *logrus.Logger
+
+func init() {
+	log = logger.Log
+}
+
+func main() {
+	app := cli.NewApp()
+	app.Flags = []cli.Flag{
+		cli.StringFlag{
+			Name:  "config, c",
+			Usage: "path of settings.yml config. Use the file in the same folder as default.",
+		},
+	}
+	app.Commands = []cli.Command{serviceCmd}
+
+	err := app.Run(os.Args)
+	if err != nil {
+		log.Fatal(err)
+	}
+}
diff --git a/cmd/service.go b/cmd/service.go
new file mode 100644
index 0000000..36c9e5e
--- /dev/null
+++ b/cmd/service.go
@@ -0,0 +1,24 @@
+package main
+
+import (
+	"github.com/apache/skywalking-cli/swctl/service"
+	"github.com/urfave/cli"
+)
+
+var serviceCmd = cli.Command{
+	Name: "service",
+	Flags: []cli.Flag{
+		cli.BoolFlag{
+			Name:  "list",
+			Usage: "list all available services.",
+		},
+	},
+	Action: func(c *cli.Context) {
+		ctl := service.NewService(c)
+
+		err := ctl.Exec()
+		if err != nil {
+			log.Fatal(err)
+		}
+	},
+}
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..8d79e73
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,9 @@
+module github.com/apache/skywalking-cli
+
+go 1.13
+
+require (
+	github.com/lytics/logrus v0.0.0-20170528191427-4389a17ed024 // indirect
+	github.com/sirupsen/logrus v1.4.2
+	github.com/urfave/cli v1.22.1
+)
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..7860264
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,22 @@
+github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
+github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
+github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
+github.com/lytics/logrus v0.0.0-20170528191427-4389a17ed024 h1:QaKVrqyQRNPbdBNCpiU0Ei3iDQko3qoiUUXMiTWhzZM=
+github.com/lytics/logrus v0.0.0-20170528191427-4389a17ed024/go.mod h1:SkQviJ2s7rFyzyuxdVp6osZceHOabU91ZhKsEXF0RWg=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
+github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
+github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
+github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
+github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
+github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
+github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
+github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY=
+github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
+golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
+golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/logger/log.go b/logger/log.go
new file mode 100644
index 0000000..039bdec
--- /dev/null
+++ b/logger/log.go
@@ -0,0 +1,20 @@
+package logger
+
+import (
+	"os"
+
+	"github.com/sirupsen/logrus"
+)
+
+var Log *logrus.Logger
+
+func init() {
+	if Log == nil {
+		Log = logrus.New()
+	}
+	Log.SetOutput(os.Stdout)
+	Log.SetFormatter(&logrus.TextFormatter{
+		FullTimestamp:   true,
+		TimestampFormat: "2006-01-02 15:04:05",
+	})
+}
diff --git a/scripts/build b/scripts/build
new file mode 100755
index 0000000..a60a9cf
--- /dev/null
+++ b/scripts/build
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+cli_build() {
+  out="bin"
+  CGO_ENABLED=0 go build $GO_BUILD_FLAGS \
+  -o "${out}/swctl" cmd/* || return
+}
+
+if echo "$0" | grep "build$" > /dev/null; then
+  cli_build
+fi
\ No newline at end of file
diff --git a/swctl/service/list.go b/swctl/service/list.go
new file mode 100644
index 0000000..73784f5
--- /dev/null
+++ b/swctl/service/list.go
@@ -0,0 +1,5 @@
+package service
+
+func (s *service) showList() error {
+	return nil
+}
diff --git a/swctl/service/service.go b/swctl/service/service.go
new file mode 100644
index 0000000..f67edf5
--- /dev/null
+++ b/swctl/service/service.go
@@ -0,0 +1,24 @@
+package service
+
+import (
+	"github.com/urfave/cli"
+)
+
+type service struct {
+	flag *cli.Context
+	list bool
+}
+
+func NewService(flag *cli.Context) *service {
+	return &service{
+		flag: flag,
+		list: flag.Bool("list"),
+	}
+}
+
+func (s *service) Exec() (err error) {
+	if s.list {
+		err = s.showList()
+	}
+	return
+}


[skywalking-cli] 19/25: Set up test coverage

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d30b61df54c3229cbe3c385d946451deded0839e
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Sat Nov 9 12:55:16 2019 +0800

    Set up test coverage
---
 .github/workflows/go.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index de9ad27..a8677f8 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -48,7 +48,7 @@ jobs:
       - name: Test
         run: |
           go test ./... -coverprofile=coverage.txt -covermode=atomic
-          bash <(curl -s https://codecov.io/bash)
+          CODECOV_TOKEN="a5af28a3-92a2-4b35-9a77-54ad99b1ae00" bash <(curl -s https://codecov.io/bash)
 
       - name: Build
         run: make clean && make


[skywalking-cli] 04/25: Merge pull request #1 from apache/kezhenxu94-patch-1

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4e660c9744fcb7d6fde60521d2eff629d20515be
Merge: a289a59 9cbbdff
Author: 吴晟 Wu Sheng <wu...@foxmail.com>
AuthorDate: Wed Nov 6 21:49:33 2019 +0800

    Merge pull request #1 from apache/kezhenxu94-patch-1
    
    Add license file

 LICENSE | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 NOTICE  |   5 ++
 2 files changed, 206 insertions(+)


[skywalking-cli] 14/25: Motivation:

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 298aff8b4cd0fe3d3c432d569eb29c47a8da2a6e
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Thu Nov 7 19:05:13 2019 +0800

    Motivation:
    
    Set up the graphql client, schema and implement a service command
    for reference
    
    Modifications:
    
    - Set up GraphQL client
    - Implement service ls command
    
    Result:
    
    GraphQL client can be reused by other commands
---
 .asf.yaml                   |  17 +
 .github/workflows/go.yml    |  32 +-
 Makefile                    |  24 +-
 cmd/main.go                 |  32 --
 cmd/service.go              |  24 --
 commands/interceptor.go     |  71 +++++
 commands/model.go           |  49 +++
 commands/service/list.go    |  73 +++++
 commands/service/service.go |  32 ++
 config/config.go            |  25 ++
 go.mod                      |   3 +-
 go.sum                      |   5 +
 graphql/client/client.go    |  51 +++
 graphql/schema/schema.go    | 750 ++++++++++++++++++++++++++++++++++++++++++++
 logger/log.go               |  18 ++
 scripts/build               |  19 +-
 swctl/main.go               |  86 +++++
 swctl/service/list.go       |   5 -
 swctl/service/service.go    |  24 --
 19 files changed, 1233 insertions(+), 107 deletions(-)

diff --git a/.asf.yaml b/.asf.yaml
index 3f2645a..c1f6dfa 100644
--- a/.asf.yaml
+++ b/.asf.yaml
@@ -1,3 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
 github:
   description: Apache SkyWalking CLI
   homepage: https://skywalking.apache.org/
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index bdc008c..1abc12e 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -23,22 +23,22 @@ jobs:
     runs-on: ubuntu-latest
     steps:
 
-    - name: Set up Go 1.13
-      uses: actions/setup-go@v1
-      with:
-        go-version: 1.13
-      id: go
+      - name: Set up Go 1.13
+        uses: actions/setup-go@v1
+        with:
+          go-version: 1.13
+        id: go
 
-    - name: Check out code into the Go module directory
-      uses: actions/checkout@v1
+      - name: Check out code into the Go module directory
+        uses: actions/checkout@v1
 
-    - name: Get dependencies
-      run: |
-        go get -v -t -d ./...
-        if [ -f Gopkg.toml ]; then
-            curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
-            dep ensure
-        fi
+      - name: Get dependencies
+        run: |
+          go get -v -t -d ./...
+          if [ -f Gopkg.toml ]; then
+              curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
+              dep ensure
+          fi
 
-    - name: Build
-      run: make
+      - name: Build
+        run: make
diff --git a/Makefile b/Makefile
index aa368e7..3273175 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,25 @@
-# Example:
-#   make build
-#   make install
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 
 .PHONY: build install
 
 build:
 	GO_BUILD_FLAGS="-v" ./scripts/build
-	./bin/swctl --version
\ No newline at end of file
+	./bin/swctl --version
+
+clean:
+	-rm -rf ./bin
\ No newline at end of file
diff --git a/cmd/main.go b/cmd/main.go
deleted file mode 100644
index e4969db..0000000
--- a/cmd/main.go
+++ /dev/null
@@ -1,32 +0,0 @@
-package main
-
-import (
-	"os"
-
-	"github.com/sirupsen/logrus"
-	"github.com/urfave/cli"
-
-	"github.com/apache/skywalking-cli/logger"
-)
-
-var log *logrus.Logger
-
-func init() {
-	log = logger.Log
-}
-
-func main() {
-	app := cli.NewApp()
-	app.Flags = []cli.Flag{
-		cli.StringFlag{
-			Name:  "config, c",
-			Usage: "path of settings.yml config. Use the file in the same folder as default.",
-		},
-	}
-	app.Commands = []cli.Command{serviceCmd}
-
-	err := app.Run(os.Args)
-	if err != nil {
-		log.Fatal(err)
-	}
-}
diff --git a/cmd/service.go b/cmd/service.go
deleted file mode 100644
index 36c9e5e..0000000
--- a/cmd/service.go
+++ /dev/null
@@ -1,24 +0,0 @@
-package main
-
-import (
-	"github.com/apache/skywalking-cli/swctl/service"
-	"github.com/urfave/cli"
-)
-
-var serviceCmd = cli.Command{
-	Name: "service",
-	Flags: []cli.Flag{
-		cli.BoolFlag{
-			Name:  "list",
-			Usage: "list all available services.",
-		},
-	},
-	Action: func(c *cli.Context) {
-		ctl := service.NewService(c)
-
-		err := ctl.Exec()
-		if err != nil {
-			log.Fatal(err)
-		}
-	},
-}
diff --git a/commands/interceptor.go b/commands/interceptor.go
new file mode 100644
index 0000000..6837529
--- /dev/null
+++ b/commands/interceptor.go
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package commands
+
+import (
+	"github.com/apache/skywalking-cli/graphql/schema"
+	"github.com/apache/skywalking-cli/logger"
+	"github.com/urfave/cli"
+	"time"
+)
+
+// Convenient function to chain up multiple cli.BeforeFunc
+func BeforeChain(beforeFunctions []cli.BeforeFunc) cli.BeforeFunc {
+	return func(ctx *cli.Context) error {
+		for _, beforeFunc := range beforeFunctions {
+			if err := beforeFunc(ctx); err != nil {
+				return err
+			}
+		}
+		return nil
+	}
+}
+
+var StepFormats = map[schema.Step]string{
+	schema.StepMonth:  "2006-01-02",
+	schema.StepDay:    "2006-01-02",
+	schema.StepHour:   "2006-01-02 15",
+	schema.StepMinute: "2006-01-02 1504",
+	schema.StepSecond: "2006-01-02 1504",
+}
+
+// Set the duration if not set, and format it according to
+// the given step
+func SetUpDuration(ctx *cli.Context) error {
+	step := ctx.Generic("step").(*StepEnumValue).Selected
+	end := ctx.String("end")
+	if len(end) == 0 {
+		end = time.Now().Format(StepFormats[step])
+		logger.Log.Debugln("Missing --end, defaults to", end)
+		if err := ctx.Set("end", end); err != nil {
+			return err
+		}
+	}
+
+	start := ctx.String("start")
+	if len(start) == 0 {
+		start = time.Now().Add(-15 * time.Minute).Format(StepFormats[step])
+		logger.Log.Debugln("Missing --start, defaults to", start)
+		if err := ctx.Set("start", start); err != nil {
+			return err
+		}
+	}
+
+	return nil
+}
diff --git a/commands/model.go b/commands/model.go
new file mode 100644
index 0000000..9da2fba
--- /dev/null
+++ b/commands/model.go
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package commands
+
+import (
+	"fmt"
+	"github.com/apache/skywalking-cli/graphql/schema"
+	"strings"
+)
+
+type StepEnumValue struct {
+	Enum     []schema.Step
+	Default  schema.Step
+	Selected schema.Step
+}
+
+func (s *StepEnumValue) Set(value string) error {
+	for _, enum := range s.Enum {
+		if enum.String() == value {
+			s.Selected = enum
+			return nil
+		}
+	}
+	steps := make([]string, len(schema.AllStep))
+	for i, step := range schema.AllStep {
+		steps[i] = step.String()
+	}
+	return fmt.Errorf("allowed steps are %s", strings.Join(steps, ", "))
+}
+
+func (s StepEnumValue) String() string {
+	return s.Selected.String()
+}
diff --git a/commands/service/list.go b/commands/service/list.go
new file mode 100644
index 0000000..e2c91af
--- /dev/null
+++ b/commands/service/list.go
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package service
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/apache/skywalking-cli/commands"
+	"github.com/apache/skywalking-cli/graphql/client"
+	"github.com/apache/skywalking-cli/graphql/schema"
+	"github.com/urfave/cli"
+)
+
+var ListCommand = cli.Command{
+	Name:      "list",
+	ShortName: "ls",
+	Usage:     "List all available services",
+	Flags: []cli.Flag{
+		cli.StringFlag{
+			Name:  "start",
+			Usage: "Query start time",
+		},
+		cli.StringFlag{
+			Name:  "end",
+			Usage: "Query end time",
+		},
+		cli.GenericFlag{
+			Name: "step",
+			Value: &commands.StepEnumValue{
+				Enum:     schema.AllStep,
+				Default:  schema.StepMinute,
+				Selected: schema.StepMinute,
+			},
+		},
+	},
+	Before: commands.BeforeChain([]cli.BeforeFunc{
+		commands.SetUpDuration,
+	}),
+	Action: func(ctx *cli.Context) error {
+		end := ctx.String("end")
+		start := ctx.String("start")
+		step := ctx.Generic("step")
+		services := client.Services(schema.Duration{
+			Start: start,
+			End:   end,
+			Step:  step.(*commands.StepEnumValue).Selected,
+		})
+
+		if bytes, e := json.Marshal(services); e != nil {
+			return e
+		} else {
+			fmt.Printf("%v\n", string(bytes))
+		}
+
+		return nil
+	},
+}
diff --git a/commands/service/service.go b/commands/service/service.go
new file mode 100644
index 0000000..5760adf
--- /dev/null
+++ b/commands/service/service.go
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package service
+
+import (
+	"github.com/urfave/cli"
+)
+
+var Command = cli.Command{
+	Name:      "service",
+	ShortName: "s",
+	Usage:     "Service related sub-command",
+	Subcommands: cli.Commands{
+		ListCommand,
+	},
+}
diff --git a/config/config.go b/config/config.go
new file mode 100644
index 0000000..bc33da2
--- /dev/null
+++ b/config/config.go
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package config
+
+var Config struct {
+	Global struct {
+		BaseUrl string `yaml:"base-url"`
+	}
+}
diff --git a/go.mod b/go.mod
index 8d79e73..062d750 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,8 @@ module github.com/apache/skywalking-cli
 go 1.13
 
 require (
-	github.com/lytics/logrus v0.0.0-20170528191427-4389a17ed024 // indirect
+	github.com/machinebox/graphql v0.2.2
+	github.com/pkg/errors v0.8.1 // indirect
 	github.com/sirupsen/logrus v1.4.2
 	github.com/urfave/cli v1.22.1
 )
diff --git a/go.sum b/go.sum
index 7860264..7627702 100644
--- a/go.sum
+++ b/go.sum
@@ -5,6 +5,10 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
 github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
 github.com/lytics/logrus v0.0.0-20170528191427-4389a17ed024 h1:QaKVrqyQRNPbdBNCpiU0Ei3iDQko3qoiUUXMiTWhzZM=
 github.com/lytics/logrus v0.0.0-20170528191427-4389a17ed024/go.mod h1:SkQviJ2s7rFyzyuxdVp6osZceHOabU91ZhKsEXF0RWg=
+github.com/machinebox/graphql v0.2.2 h1:dWKpJligYKhYKO5A2gvNhkJdQMNZeChZYyBbrZkBZfo=
+github.com/machinebox/graphql v0.2.2/go.mod h1:F+kbVMHuwrQ5tYgU9JXlnskM8nOaFxCAEolaQybkjWA=
+github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
+github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
@@ -19,4 +23,5 @@ github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX
 golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
 golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/graphql/client/client.go b/graphql/client/client.go
new file mode 100644
index 0000000..10a680a
--- /dev/null
+++ b/graphql/client/client.go
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package client
+
+import (
+	"context"
+	"github.com/apache/skywalking-cli/config"
+	"github.com/apache/skywalking-cli/graphql/schema"
+	"github.com/apache/skywalking-cli/logger"
+	"github.com/machinebox/graphql"
+)
+
+func Services(duration schema.Duration) []schema.Service {
+	ctx := context.Background()
+	client := graphql.NewClient(config.Config.Global.BaseUrl)
+	client.Log = func(msg string) {
+		logger.Log.Debugln(msg)
+	}
+
+	var services map[string][]schema.Service
+	request := graphql.NewRequest(`
+		query ($duration: Duration!) {
+			services: getAllServices(duration: $duration) {
+				id name
+			}
+		}
+	`)
+	request.Var("duration", duration)
+	if err := client.Run(ctx, request, &services); err != nil {
+		logger.Log.Fatalln(err)
+		panic(err)
+	}
+
+	return services["services"]
+}
diff --git a/graphql/schema/schema.go b/graphql/schema/schema.go
new file mode 100644
index 0000000..d3848d5
--- /dev/null
+++ b/graphql/schema/schema.go
@@ -0,0 +1,750 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package schema
+
+import (
+	"fmt"
+	"io"
+	"strconv"
+)
+
+type AlarmMessage struct {
+	StartTime int64  `json:"startTime"`
+	Scope     *Scope `json:"scope"`
+	ID        string `json:"id"`
+	Message   string `json:"message"`
+}
+
+type AlarmTrend struct {
+	NumOfAlarm []*int `json:"numOfAlarm"`
+}
+
+type Alarms struct {
+	Msgs  []*AlarmMessage `json:"msgs"`
+	Total int             `json:"total"`
+}
+
+type Attribute struct {
+	Name  string `json:"name"`
+	Value string `json:"value"`
+}
+
+type BasicTrace struct {
+	SegmentID     string   `json:"segmentId"`
+	EndpointNames []string `json:"endpointNames"`
+	Duration      int      `json:"duration"`
+	Start         string   `json:"start"`
+	IsError       *bool    `json:"isError"`
+	TraceIds      []string `json:"traceIds"`
+}
+
+type BatchMetricConditions struct {
+	Name string   `json:"name"`
+	Ids  []string `json:"ids"`
+}
+
+type Call struct {
+	Source           string        `json:"source"`
+	SourceComponents []string      `json:"sourceComponents"`
+	Target           string        `json:"target"`
+	TargetComponents []string      `json:"targetComponents"`
+	ID               string        `json:"id"`
+	DetectPoints     []DetectPoint `json:"detectPoints"`
+}
+
+type ClusterBrief struct {
+	NumOfService  int `json:"numOfService"`
+	NumOfEndpoint int `json:"numOfEndpoint"`
+	NumOfDatabase int `json:"numOfDatabase"`
+	NumOfCache    int `json:"numOfCache"`
+	NumOfMq       int `json:"numOfMQ"`
+}
+
+type Database struct {
+	ID   string `json:"id"`
+	Name string `json:"name"`
+	Type string `json:"type"`
+}
+
+type Duration struct {
+	Start string `json:"start"`
+	End   string `json:"end"`
+	Step  Step   `json:"step"`
+}
+
+type Endpoint struct {
+	ID   string `json:"id"`
+	Name string `json:"name"`
+}
+
+type EndpointInfo struct {
+	ID          string `json:"id"`
+	Name        string `json:"name"`
+	ServiceID   string `json:"serviceId"`
+	ServiceName string `json:"serviceName"`
+}
+
+type IntValues struct {
+	Values []*KVInt `json:"values"`
+}
+
+type KVInt struct {
+	ID    string `json:"id"`
+	Value int64  `json:"value"`
+}
+
+type KeyValue struct {
+	Key   string  `json:"key"`
+	Value *string `json:"value"`
+}
+
+type Log struct {
+	ServiceName         *string     `json:"serviceName"`
+	ServiceID           *string     `json:"serviceId"`
+	ServiceInstanceName *string     `json:"serviceInstanceName"`
+	ServiceInstanceID   *string     `json:"serviceInstanceId"`
+	EndpointName        *string     `json:"endpointName"`
+	EndpointID          *string     `json:"endpointId"`
+	TraceID             *string     `json:"traceId"`
+	Timestamp           string      `json:"timestamp"`
+	IsError             *bool       `json:"isError"`
+	StatusCode          *string     `json:"statusCode"`
+	ContentType         ContentType `json:"contentType"`
+	Content             *string     `json:"content"`
+}
+
+type LogEntity struct {
+	Time int64       `json:"time"`
+	Data []*KeyValue `json:"data"`
+}
+
+type LogQueryCondition struct {
+	MetricName        *string     `json:"metricName"`
+	ServiceID         *string     `json:"serviceId"`
+	ServiceInstanceID *string     `json:"serviceInstanceId"`
+	EndpointID        *string     `json:"endpointId"`
+	TraceID           *string     `json:"traceId"`
+	QueryDuration     *Duration   `json:"queryDuration"`
+	State             LogState    `json:"state"`
+	StateCode         *string     `json:"stateCode"`
+	Paging            *Pagination `json:"paging"`
+}
+
+type Logs struct {
+	Logs  []*Log `json:"logs"`
+	Total int    `json:"total"`
+}
+
+type MetricCondition struct {
+	Name string  `json:"name"`
+	ID   *string `json:"id"`
+}
+
+type Node struct {
+	ID     string  `json:"id"`
+	Name   string  `json:"name"`
+	Type   *string `json:"type"`
+	IsReal bool    `json:"isReal"`
+}
+
+type Pagination struct {
+	PageNum   *int  `json:"pageNum"`
+	PageSize  int   `json:"pageSize"`
+	NeedTotal *bool `json:"needTotal"`
+}
+
+type Ref struct {
+	TraceID         string  `json:"traceId"`
+	ParentSegmentID string  `json:"parentSegmentId"`
+	ParentSpanID    int     `json:"parentSpanId"`
+	Type            RefType `json:"type"`
+}
+
+type Service struct {
+	ID   string `json:"id"`
+	Name string `json:"name"`
+}
+
+type ServiceInstance struct {
+	ID           string       `json:"id"`
+	Name         string       `json:"name"`
+	Attributes   []*Attribute `json:"attributes"`
+	Language     Language     `json:"language"`
+	InstanceUUID string       `json:"instanceUUID"`
+}
+
+type Span struct {
+	TraceID      string       `json:"traceId"`
+	SegmentID    string       `json:"segmentId"`
+	SpanID       int          `json:"spanId"`
+	ParentSpanID int          `json:"parentSpanId"`
+	Refs         []*Ref       `json:"refs"`
+	ServiceCode  string       `json:"serviceCode"`
+	StartTime    int64        `json:"startTime"`
+	EndTime      int64        `json:"endTime"`
+	EndpointName *string      `json:"endpointName"`
+	Type         string       `json:"type"`
+	Peer         *string      `json:"peer"`
+	Component    *string      `json:"component"`
+	IsError      *bool        `json:"isError"`
+	Layer        *string      `json:"layer"`
+	Tags         []*KeyValue  `json:"tags"`
+	Logs         []*LogEntity `json:"logs"`
+}
+
+type Thermodynamic struct {
+	Nodes     [][]*int `json:"nodes"`
+	AxisYStep int      `json:"axisYStep"`
+}
+
+type TimeInfo struct {
+	Timezone         *string `json:"timezone"`
+	CurrentTimestamp *int64  `json:"currentTimestamp"`
+}
+
+type TopNEntity struct {
+	Name  string `json:"name"`
+	ID    string `json:"id"`
+	Value int64  `json:"value"`
+}
+
+type TopNRecord struct {
+	Statement *string `json:"statement"`
+	Latency   int64   `json:"latency"`
+	TraceID   *string `json:"traceId"`
+}
+
+type TopNRecordsCondition struct {
+	ServiceID  string    `json:"serviceId"`
+	MetricName string    `json:"metricName"`
+	TopN       int       `json:"topN"`
+	Order      Order     `json:"order"`
+	Duration   *Duration `json:"duration"`
+}
+
+type Topology struct {
+	Nodes []*Node `json:"nodes"`
+	Calls []*Call `json:"calls"`
+}
+
+type Trace struct {
+	Spans []*Span `json:"spans"`
+}
+
+type TraceBrief struct {
+	Traces []*BasicTrace `json:"traces"`
+	Total  int           `json:"total"`
+}
+
+type TraceQueryCondition struct {
+	ServiceID         *string     `json:"serviceId"`
+	ServiceInstanceID *string     `json:"serviceInstanceId"`
+	TraceID           *string     `json:"traceId"`
+	EndpointID        *string     `json:"endpointId"`
+	EndpointName      *string     `json:"endpointName"`
+	QueryDuration     *Duration   `json:"queryDuration"`
+	MinTraceDuration  *int        `json:"minTraceDuration"`
+	MaxTraceDuration  *int        `json:"maxTraceDuration"`
+	TraceState        TraceState  `json:"traceState"`
+	QueryOrder        QueryOrder  `json:"queryOrder"`
+	Paging            *Pagination `json:"paging"`
+}
+
+type ContentType string
+
+const (
+	ContentTypeText ContentType = "TEXT"
+	ContentTypeJSON ContentType = "JSON"
+	ContentTypeNone ContentType = "NONE"
+)
+
+var AllContentType = []ContentType{
+	ContentTypeText,
+	ContentTypeJSON,
+	ContentTypeNone,
+}
+
+func (e ContentType) IsValid() bool {
+	switch e {
+	case ContentTypeText, ContentTypeJSON, ContentTypeNone:
+		return true
+	}
+	return false
+}
+
+func (e ContentType) String() string {
+	return string(e)
+}
+
+func (e *ContentType) UnmarshalGQL(v interface{}) error {
+	str, ok := v.(string)
+	if !ok {
+		return fmt.Errorf("enums must be strings")
+	}
+
+	*e = ContentType(str)
+	if !e.IsValid() {
+		return fmt.Errorf("%s is not a valid ContentType", str)
+	}
+	return nil
+}
+
+func (e ContentType) MarshalGQL(w io.Writer) {
+	fmt.Fprint(w, strconv.Quote(e.String()))
+}
+
+type DetectPoint string
+
+const (
+	DetectPointClient DetectPoint = "CLIENT"
+	DetectPointServer DetectPoint = "SERVER"
+	DetectPointProxy  DetectPoint = "PROXY"
+)
+
+var AllDetectPoint = []DetectPoint{
+	DetectPointClient,
+	DetectPointServer,
+	DetectPointProxy,
+}
+
+func (e DetectPoint) IsValid() bool {
+	switch e {
+	case DetectPointClient, DetectPointServer, DetectPointProxy:
+		return true
+	}
+	return false
+}
+
+func (e DetectPoint) String() string {
+	return string(e)
+}
+
+func (e *DetectPoint) UnmarshalGQL(v interface{}) error {
+	str, ok := v.(string)
+	if !ok {
+		return fmt.Errorf("enums must be strings")
+	}
+
+	*e = DetectPoint(str)
+	if !e.IsValid() {
+		return fmt.Errorf("%s is not a valid DetectPoint", str)
+	}
+	return nil
+}
+
+func (e DetectPoint) MarshalGQL(w io.Writer) {
+	fmt.Fprint(w, strconv.Quote(e.String()))
+}
+
+type Language string
+
+const (
+	LanguageUnknown Language = "UNKNOWN"
+	LanguageJava    Language = "JAVA"
+	LanguageDotnet  Language = "DOTNET"
+	LanguageNodejs  Language = "NODEJS"
+	LanguagePython  Language = "PYTHON"
+	LanguageRuby    Language = "RUBY"
+)
+
+var AllLanguage = []Language{
+	LanguageUnknown,
+	LanguageJava,
+	LanguageDotnet,
+	LanguageNodejs,
+	LanguagePython,
+	LanguageRuby,
+}
+
+func (e Language) IsValid() bool {
+	switch e {
+	case LanguageUnknown, LanguageJava, LanguageDotnet, LanguageNodejs, LanguagePython, LanguageRuby:
+		return true
+	}
+	return false
+}
+
+func (e Language) String() string {
+	return string(e)
+}
+
+func (e *Language) UnmarshalGQL(v interface{}) error {
+	str, ok := v.(string)
+	if !ok {
+		return fmt.Errorf("enums must be strings")
+	}
+
+	*e = Language(str)
+	if !e.IsValid() {
+		return fmt.Errorf("%s is not a valid Language", str)
+	}
+	return nil
+}
+
+func (e Language) MarshalGQL(w io.Writer) {
+	fmt.Fprint(w, strconv.Quote(e.String()))
+}
+
+type LogState string
+
+const (
+	LogStateAll     LogState = "ALL"
+	LogStateSuccess LogState = "SUCCESS"
+	LogStateError   LogState = "ERROR"
+)
+
+var AllLogState = []LogState{
+	LogStateAll,
+	LogStateSuccess,
+	LogStateError,
+}
+
+func (e LogState) IsValid() bool {
+	switch e {
+	case LogStateAll, LogStateSuccess, LogStateError:
+		return true
+	}
+	return false
+}
+
+func (e LogState) String() string {
+	return string(e)
+}
+
+func (e *LogState) UnmarshalGQL(v interface{}) error {
+	str, ok := v.(string)
+	if !ok {
+		return fmt.Errorf("enums must be strings")
+	}
+
+	*e = LogState(str)
+	if !e.IsValid() {
+		return fmt.Errorf("%s is not a valid LogState", str)
+	}
+	return nil
+}
+
+func (e LogState) MarshalGQL(w io.Writer) {
+	fmt.Fprint(w, strconv.Quote(e.String()))
+}
+
+type NodeType string
+
+const (
+	NodeTypeService  NodeType = "SERVICE"
+	NodeTypeEndpoint NodeType = "ENDPOINT"
+	NodeTypeUser     NodeType = "USER"
+)
+
+var AllNodeType = []NodeType{
+	NodeTypeService,
+	NodeTypeEndpoint,
+	NodeTypeUser,
+}
+
+func (e NodeType) IsValid() bool {
+	switch e {
+	case NodeTypeService, NodeTypeEndpoint, NodeTypeUser:
+		return true
+	}
+	return false
+}
+
+func (e NodeType) String() string {
+	return string(e)
+}
+
+func (e *NodeType) UnmarshalGQL(v interface{}) error {
+	str, ok := v.(string)
+	if !ok {
+		return fmt.Errorf("enums must be strings")
+	}
+
+	*e = NodeType(str)
+	if !e.IsValid() {
+		return fmt.Errorf("%s is not a valid NodeType", str)
+	}
+	return nil
+}
+
+func (e NodeType) MarshalGQL(w io.Writer) {
+	fmt.Fprint(w, strconv.Quote(e.String()))
+}
+
+type Order string
+
+const (
+	OrderAsc Order = "ASC"
+	OrderDes Order = "DES"
+)
+
+var AllOrder = []Order{
+	OrderAsc,
+	OrderDes,
+}
+
+func (e Order) IsValid() bool {
+	switch e {
+	case OrderAsc, OrderDes:
+		return true
+	}
+	return false
+}
+
+func (e Order) String() string {
+	return string(e)
+}
+
+func (e *Order) UnmarshalGQL(v interface{}) error {
+	str, ok := v.(string)
+	if !ok {
+		return fmt.Errorf("enums must be strings")
+	}
+
+	*e = Order(str)
+	if !e.IsValid() {
+		return fmt.Errorf("%s is not a valid Order", str)
+	}
+	return nil
+}
+
+func (e Order) MarshalGQL(w io.Writer) {
+	fmt.Fprint(w, strconv.Quote(e.String()))
+}
+
+type QueryOrder string
+
+const (
+	QueryOrderByStartTime QueryOrder = "BY_START_TIME"
+	QueryOrderByDuration  QueryOrder = "BY_DURATION"
+)
+
+var AllQueryOrder = []QueryOrder{
+	QueryOrderByStartTime,
+	QueryOrderByDuration,
+}
+
+func (e QueryOrder) IsValid() bool {
+	switch e {
+	case QueryOrderByStartTime, QueryOrderByDuration:
+		return true
+	}
+	return false
+}
+
+func (e QueryOrder) String() string {
+	return string(e)
+}
+
+func (e *QueryOrder) UnmarshalGQL(v interface{}) error {
+	str, ok := v.(string)
+	if !ok {
+		return fmt.Errorf("enums must be strings")
+	}
+
+	*e = QueryOrder(str)
+	if !e.IsValid() {
+		return fmt.Errorf("%s is not a valid QueryOrder", str)
+	}
+	return nil
+}
+
+func (e QueryOrder) MarshalGQL(w io.Writer) {
+	fmt.Fprint(w, strconv.Quote(e.String()))
+}
+
+type RefType string
+
+const (
+	RefTypeCrossProcess RefType = "CROSS_PROCESS"
+	RefTypeCrossThread  RefType = "CROSS_THREAD"
+)
+
+var AllRefType = []RefType{
+	RefTypeCrossProcess,
+	RefTypeCrossThread,
+}
+
+func (e RefType) IsValid() bool {
+	switch e {
+	case RefTypeCrossProcess, RefTypeCrossThread:
+		return true
+	}
+	return false
+}
+
+func (e RefType) String() string {
+	return string(e)
+}
+
+func (e *RefType) UnmarshalGQL(v interface{}) error {
+	str, ok := v.(string)
+	if !ok {
+		return fmt.Errorf("enums must be strings")
+	}
+
+	*e = RefType(str)
+	if !e.IsValid() {
+		return fmt.Errorf("%s is not a valid RefType", str)
+	}
+	return nil
+}
+
+func (e RefType) MarshalGQL(w io.Writer) {
+	fmt.Fprint(w, strconv.Quote(e.String()))
+}
+
+type Scope string
+
+const (
+	ScopeService                 Scope = "Service"
+	ScopeServiceInstance         Scope = "ServiceInstance"
+	ScopeEndpoint                Scope = "Endpoint"
+	ScopeServiceRelation         Scope = "ServiceRelation"
+	ScopeServiceInstanceRelation Scope = "ServiceInstanceRelation"
+	ScopeEndpointRelation        Scope = "EndpointRelation"
+)
+
+var AllScope = []Scope{
+	ScopeService,
+	ScopeServiceInstance,
+	ScopeEndpoint,
+	ScopeServiceRelation,
+	ScopeServiceInstanceRelation,
+	ScopeEndpointRelation,
+}
+
+func (e Scope) IsValid() bool {
+	switch e {
+	case ScopeService, ScopeServiceInstance, ScopeEndpoint, ScopeServiceRelation, ScopeServiceInstanceRelation, ScopeEndpointRelation:
+		return true
+	}
+	return false
+}
+
+func (e Scope) String() string {
+	return string(e)
+}
+
+func (e *Scope) UnmarshalGQL(v interface{}) error {
+	str, ok := v.(string)
+	if !ok {
+		return fmt.Errorf("enums must be strings")
+	}
+
+	*e = Scope(str)
+	if !e.IsValid() {
+		return fmt.Errorf("%s is not a valid Scope", str)
+	}
+	return nil
+}
+
+func (e Scope) MarshalGQL(w io.Writer) {
+	fmt.Fprint(w, strconv.Quote(e.String()))
+}
+
+type Step string
+
+const (
+	StepMonth  Step = "MONTH"
+	StepDay    Step = "DAY"
+	StepHour   Step = "HOUR"
+	StepMinute Step = "MINUTE"
+	StepSecond Step = "SECOND"
+)
+
+var AllStep = []Step{
+	StepMonth,
+	StepDay,
+	StepHour,
+	StepMinute,
+	StepSecond,
+}
+
+func (e Step) IsValid() bool {
+	switch e {
+	case StepMonth, StepDay, StepHour, StepMinute, StepSecond:
+		return true
+	}
+	return false
+}
+
+func (e Step) String() string {
+	return string(e)
+}
+
+func (e *Step) UnmarshalGQL(v interface{}) error {
+	str, ok := v.(string)
+	if !ok {
+		return fmt.Errorf("enums must be strings")
+	}
+
+	*e = Step(str)
+	if !e.IsValid() {
+		return fmt.Errorf("%s is not a valid Step", str)
+	}
+	return nil
+}
+
+func (e Step) MarshalGQL(w io.Writer) {
+	fmt.Fprint(w, strconv.Quote(e.String()))
+}
+
+type TraceState string
+
+const (
+	TraceStateAll     TraceState = "ALL"
+	TraceStateSuccess TraceState = "SUCCESS"
+	TraceStateError   TraceState = "ERROR"
+)
+
+var AllTraceState = []TraceState{
+	TraceStateAll,
+	TraceStateSuccess,
+	TraceStateError,
+}
+
+func (e TraceState) IsValid() bool {
+	switch e {
+	case TraceStateAll, TraceStateSuccess, TraceStateError:
+		return true
+	}
+	return false
+}
+
+func (e TraceState) String() string {
+	return string(e)
+}
+
+func (e *TraceState) UnmarshalGQL(v interface{}) error {
+	str, ok := v.(string)
+	if !ok {
+		return fmt.Errorf("enums must be strings")
+	}
+
+	*e = TraceState(str)
+	if !e.IsValid() {
+		return fmt.Errorf("%s is not a valid TraceState", str)
+	}
+	return nil
+}
+
+func (e TraceState) MarshalGQL(w io.Writer) {
+	fmt.Fprint(w, strconv.Quote(e.String()))
+}
diff --git a/logger/log.go b/logger/log.go
index 039bdec..4a5d482 100644
--- a/logger/log.go
+++ b/logger/log.go
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
 package logger
 
 import (
diff --git a/scripts/build b/scripts/build
index a60a9cf..7a20563 100755
--- a/scripts/build
+++ b/scripts/build
@@ -1,9 +1,26 @@
 #!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
 
 cli_build() {
   out="bin"
   CGO_ENABLED=0 go build $GO_BUILD_FLAGS \
-  -o "${out}/swctl" cmd/* || return
+  -o "${out}/swctl" swctl/* || return
 }
 
 if echo "$0" | grep "build$" > /dev/null; then
diff --git a/swctl/main.go b/swctl/main.go
new file mode 100644
index 0000000..5619a28
--- /dev/null
+++ b/swctl/main.go
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package main
+
+import (
+	"encoding/json"
+	"github.com/apache/skywalking-cli/commands/service"
+	"github.com/apache/skywalking-cli/config"
+	"github.com/sirupsen/logrus"
+	"github.com/urfave/cli"
+	"gopkg.in/yaml.v2"
+	"io/ioutil"
+	"os"
+
+	"github.com/apache/skywalking-cli/logger"
+)
+
+var log *logrus.Logger
+
+func init() {
+	log = logger.Log
+}
+
+func main() {
+	app := cli.NewApp()
+	app.Usage = "The CLI (Command Line Interface) for Apache SkyWalking."
+	app.Flags = []cli.Flag{
+		cli.StringFlag{
+			Name:  "config",
+			Value: "./settings.yml",
+			Usage: "load configuration `FILE`, default to ./settings.yml",
+		},
+		cli.BoolFlag{
+			Name:     "debug",
+			Required: false,
+			Usage:    "enable debug mode, will print more detailed logs",
+		},
+	}
+	app.Commands = []cli.Command{
+		service.Command,
+	}
+
+	app.Before = BeforeCommand
+
+	if err := app.Run(os.Args); err != nil {
+		log.Fatalln(err)
+	}
+}
+
+func BeforeCommand(c *cli.Context) error {
+	if c.Bool("debug") {
+		log.SetLevel(logrus.DebugLevel)
+		log.Debugln("Debug mode is enabled")
+	}
+
+	configFile := c.String("config")
+	log.Debugln("Using configuration file:", configFile)
+
+	if bytes, err := ioutil.ReadFile(configFile); err != nil {
+		return err
+	} else if err := yaml.Unmarshal(bytes, &config.Config); err != nil {
+		return err
+	}
+
+	if bytes, err := json.Marshal(config.Config); err == nil {
+		log.Debugln("Configurations: ", string(bytes))
+	}
+
+	return nil
+}
diff --git a/swctl/service/list.go b/swctl/service/list.go
deleted file mode 100644
index 73784f5..0000000
--- a/swctl/service/list.go
+++ /dev/null
@@ -1,5 +0,0 @@
-package service
-
-func (s *service) showList() error {
-	return nil
-}
diff --git a/swctl/service/service.go b/swctl/service/service.go
deleted file mode 100644
index f67edf5..0000000
--- a/swctl/service/service.go
+++ /dev/null
@@ -1,24 +0,0 @@
-package service
-
-import (
-	"github.com/urfave/cli"
-)
-
-type service struct {
-	flag *cli.Context
-	list bool
-}
-
-func NewService(flag *cli.Context) *service {
-	return &service{
-		flag: flag,
-		list: flag.Bool("list"),
-	}
-}
-
-func (s *service) Exec() (err error) {
-	if s.list {
-		err = s.showList()
-	}
-	return
-}


[skywalking-cli] 10/25: Add missing license headers

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d74e098eb1ef7f4dd1ca1e3d63f85c3fad030e87
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Wed Nov 6 22:38:03 2019 +0800

    Add missing license headers
---
 Makefile                 | 19 ++++++++++++++++---
 cmd/main.go              | 18 ++++++++++++++++++
 cmd/service.go           | 18 ++++++++++++++++++
 logger/log.go            | 18 ++++++++++++++++++
 scripts/build            | 17 +++++++++++++++++
 swctl/service/list.go    | 18 ++++++++++++++++++
 swctl/service/service.go | 18 ++++++++++++++++++
 7 files changed, 123 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index aa368e7..03d2d59 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,19 @@
-# Example:
-#   make build
-#   make install
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 
 .PHONY: build install
 
diff --git a/cmd/main.go b/cmd/main.go
index e4969db..08e105d 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
 package main
 
 import (
diff --git a/cmd/service.go b/cmd/service.go
index 36c9e5e..8513965 100644
--- a/cmd/service.go
+++ b/cmd/service.go
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
 package main
 
 import (
diff --git a/logger/log.go b/logger/log.go
index 039bdec..4a5d482 100644
--- a/logger/log.go
+++ b/logger/log.go
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
 package logger
 
 import (
diff --git a/scripts/build b/scripts/build
index a60a9cf..2e48690 100755
--- a/scripts/build
+++ b/scripts/build
@@ -1,4 +1,21 @@
 #!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
 
 cli_build() {
   out="bin"
diff --git a/swctl/service/list.go b/swctl/service/list.go
index 73784f5..431032f 100644
--- a/swctl/service/list.go
+++ b/swctl/service/list.go
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
 package service
 
 func (s *service) showList() error {
diff --git a/swctl/service/service.go b/swctl/service/service.go
index f67edf5..bb2986a 100644
--- a/swctl/service/service.go
+++ b/swctl/service/service.go
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
 package service
 
 import (


[skywalking-cli] 21/25: Redesign start end time when absent and present

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 364978c8845371241f1823ecc6ae9f14220d94b0
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Sat Nov 9 20:24:28 2019 +0800

    Redesign start end time when absent and present
---
 commands/interceptor/duration.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/interceptor/duration.go b/commands/interceptor/duration.go
index 1be9974..88468ec 100644
--- a/commands/interceptor/duration.go
+++ b/commands/interceptor/duration.go
@@ -96,7 +96,7 @@ func ParseDuration(start string, end string) (time.Time, time.Time, schema.Step)
 	if len(start) > 0 && len(end) > 0 {
 		start, end = AlignPrecision(start, end)
 
-		if step, startTime, err = tryParseTime(start); err != nil {
+		if _, startTime, err = tryParseTime(start); err != nil {
 			logger.Log.Fatalln("Unsupported time format:", start, err)
 		}
 		if step, endTime, err = tryParseTime(end); err != nil {


[skywalking-cli] 16/25: Remove stale files

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5223581e0fdcc973b46efa18f6628f9c72024ee6
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Thu Nov 7 19:11:15 2019 +0800

    Remove stale files
---
 cmd/main.go              | 50 ------------------------------------------------
 cmd/service.go           | 42 ----------------------------------------
 swctl/service/list.go    | 23 ----------------------
 swctl/service/service.go | 42 ----------------------------------------
 4 files changed, 157 deletions(-)

diff --git a/cmd/main.go b/cmd/main.go
deleted file mode 100644
index 08e105d..0000000
--- a/cmd/main.go
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package main
-
-import (
-	"os"
-
-	"github.com/sirupsen/logrus"
-	"github.com/urfave/cli"
-
-	"github.com/apache/skywalking-cli/logger"
-)
-
-var log *logrus.Logger
-
-func init() {
-	log = logger.Log
-}
-
-func main() {
-	app := cli.NewApp()
-	app.Flags = []cli.Flag{
-		cli.StringFlag{
-			Name:  "config, c",
-			Usage: "path of settings.yml config. Use the file in the same folder as default.",
-		},
-	}
-	app.Commands = []cli.Command{serviceCmd}
-
-	err := app.Run(os.Args)
-	if err != nil {
-		log.Fatal(err)
-	}
-}
diff --git a/cmd/service.go b/cmd/service.go
deleted file mode 100644
index 8513965..0000000
--- a/cmd/service.go
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package main
-
-import (
-	"github.com/apache/skywalking-cli/swctl/service"
-	"github.com/urfave/cli"
-)
-
-var serviceCmd = cli.Command{
-	Name: "service",
-	Flags: []cli.Flag{
-		cli.BoolFlag{
-			Name:  "list",
-			Usage: "list all available services.",
-		},
-	},
-	Action: func(c *cli.Context) {
-		ctl := service.NewService(c)
-
-		err := ctl.Exec()
-		if err != nil {
-			log.Fatal(err)
-		}
-	},
-}
diff --git a/swctl/service/list.go b/swctl/service/list.go
deleted file mode 100644
index 431032f..0000000
--- a/swctl/service/list.go
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package service
-
-func (s *service) showList() error {
-	return nil
-}
diff --git a/swctl/service/service.go b/swctl/service/service.go
deleted file mode 100644
index bb2986a..0000000
--- a/swctl/service/service.go
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package service
-
-import (
-	"github.com/urfave/cli"
-)
-
-type service struct {
-	flag *cli.Context
-	list bool
-}
-
-func NewService(flag *cli.Context) *service {
-	return &service{
-		flag: flag,
-		list: flag.Bool("list"),
-	}
-}
-
-func (s *service) Exec() (err error) {
-	if s.list {
-		err = s.showList()
-	}
-	return
-}