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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3932d47  Logs command support (#103)
3932d47 is described below

commit 3932d479a5f93e8980f704c4a68792c7b0256ae7
Author: mrproliu <[email protected]>
AuthorDate: Thu Jul 29 16:30:55 2021 +0800

    Logs command support (#103)
    
    * Add log command support
    
    Co-authored-by: dalekliuhan <[email protected]>
---
 README.md                         |  29 +++++++++
 assets/assets.gen.go              |  60 ++++++++++++++++++
 assets/graphqls/logs/Logs.graphql |  38 ++++++++++++
 cmd/swctl/main.go                 |   2 +
 internal/commands/logs/list.go    | 126 ++++++++++++++++++++++++++++++++++++++
 internal/commands/logs/log.go     |  31 ++++++++++
 pkg/graphql/log/log.go            |  40 ++++++++++++
 7 files changed, 326 insertions(+)

diff --git a/README.md b/README.md
index 168b230..48837c7 100644
--- a/README.md
+++ b/README.md
@@ -400,6 +400,24 @@ You can imitate the content of [the default template 
file](examples/global.yml)
 
 </details>
 
+### `logs`
+
+#### `list`
+
+<details>
+
+<summary>logs list [--service-id=service-id] 
[--service-instance-id=service-instance-id] [--endpoint-id=endpoint-id] 
[--trace-id=trace-id] [--tags=tags] [--start=start-time] [--end=end-time] 
</summary>
+
+| argument | description | default |
+| :--- | :--- | :--- |
+| `service-id` | The service id whose logs are to displayed. |  |
+| `service-instance-id` | The service instance id whose logs are to displayed. 
|  |
+| `endpoint-id` | The service endpoint id whose logs are to displayed. |  |
+| `trace-id` | The trace id whose logs are to displayed. |  |
+| `tags` | Only tags defined in the core/default/searchableLogsTags are 
searchable. Check more details on the Configuration Vocabulary page | See 
[Configuration Vocabulary 
page](https://github.com/apache/skywalking/blob/master/docs/en/setup/backend/configuration-vocabulary.md)
 |
+
+</details>
+
 # Use Cases
 
 <details>
@@ -571,6 +589,17 @@ $ ./bin/swctl --display=graph metrics thermodynamic
 
 <details>
 
+<summary>Query the logs</summary>
+
+```shell
+$ ./bin/swctl logs list
+{"logs":[{"serviceName":"e2e-service-provider","serviceId":"ZTJlLXNlcnZpY2UtcHJvdmlkZXI=.1","serviceInstanceName":"provider1","serviceInstanceId":"ZTJlLXNlcnZpY2UtcHJvdmlkZXI=.1_cHJvdmlkZXIx","endpointName":null,"endpointId":null,"traceId":"ccdb2bb86f834b6699980fad9b2560d6.74.16275170853710001","timestamp":1627517086179,"contentType":"TEXT","content":"2021-07-29
 00:04:46.179 [TID:ccdb2bb86f834b6699980fad9b2560d6.74.16275170853710001] 
[http-nio-9090-exec-9] INFO  o.a.s.e2e.controller.LogC [...]
+```
+
+</details>
+
+<details>
+
 <summary>Display the spans of a trace</summary>
 
 ```shell
diff --git a/assets/assets.gen.go b/assets/assets.gen.go
index 6274929..dca3aab 100644
--- a/assets/assets.gen.go
+++ b/assets/assets.gen.go
@@ -20,6 +20,7 @@
 // cr/oap.yaml (942B)
 // cr/ui.yaml (935B)
 // graphqls/healthcheck/healthcheck.graphql (870B)
+// graphqls/logs/Logs.graphql (1.258kB)
 // graphqls/metadata/AllServices.graphql (911B)
 // graphqls/metadata/Instances.graphql (1.069kB)
 // graphqls/metadata/SearchEndpoints.graphql (975B)
@@ -201,6 +202,61 @@ func graphqlsHealthcheckHealthcheckGraphql() (*asset, 
error) {
        return a, nil
 }
 
+var _graphqlsLogsLogsGraphql = []byte(`# Licensed to Apache Software 
Foundation (ASF) under one or more contributor
+# license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright
+# ownership. Apache Software Foundation (ASF) licenses this file to you under
+# the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+query ($condition: LogQueryCondition!) {
+    result: queryLogs(condition: $condition) {
+        total
+        logs {
+            serviceName
+            serviceId
+            serviceInstanceName
+            serviceInstanceId
+            endpointName
+            endpointId
+            traceId
+            timestamp
+            contentType
+            content
+            tags {
+                key
+                value
+            }
+        }
+    }
+}
+`)
+
+func graphqlsLogsLogsGraphqlBytes() ([]byte, error) {
+       return _graphqlsLogsLogsGraphql, nil
+}
+
+func graphqlsLogsLogsGraphql() (*asset, error) {
+       bytes, err := graphqlsLogsLogsGraphqlBytes()
+       if err != nil {
+               return nil, err
+       }
+
+       info := bindataFileInfo{name: "graphqls/logs/Logs.graphql", size: 0, 
mode: os.FileMode(0), modTime: time.Unix(0, 0)}
+       a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x5, 0xb, 0x5c, 
0x60, 0x9b, 0x18, 0x98, 0xa0, 0xdd, 0x60, 0x42, 0x91, 0x53, 0x25, 0xcd, 0x59, 
0xa5, 0x1c, 0xff, 0xc3, 0xf7, 0xf0, 0x45, 0xb3, 0xf7, 0xcd, 0xd8, 0x63, 0xee, 
0x9f, 0x6a, 0x3a}}
+       return a, nil
+}
+
 var _graphqlsMetadataAllservicesGraphql = []byte(`# Licensed to Apache 
Software Foundation (ASF) under one or more contributor
 # license agreements. See the NOTICE file distributed with
 # this work for additional information regarding copyright
@@ -972,6 +1028,7 @@ var _bindata = map[string]func() (*asset, error){
        "cr/oap.yaml": crOapYaml,
        "cr/ui.yaml":  crUiYaml,
        "graphqls/healthcheck/healthcheck.graphql":      
graphqlsHealthcheckHealthcheckGraphql,
+       "graphqls/logs/Logs.graphql":                    
graphqlsLogsLogsGraphql,
        "graphqls/metadata/AllServices.graphql":         
graphqlsMetadataAllservicesGraphql,
        "graphqls/metadata/Instances.graphql":           
graphqlsMetadataInstancesGraphql,
        "graphqls/metadata/SearchEndpoints.graphql":     
graphqlsMetadataSearchendpointsGraphql,
@@ -1040,6 +1097,9 @@ var _bintree = &bintree{nil, map[string]*bintree{
                "healthcheck": &bintree{nil, map[string]*bintree{
                        "healthcheck.graphql": 
&bintree{graphqlsHealthcheckHealthcheckGraphql, map[string]*bintree{}},
                }},
+               "logs": &bintree{nil, map[string]*bintree{
+                       "Logs.graphql": &bintree{graphqlsLogsLogsGraphql, 
map[string]*bintree{}},
+               }},
                "metadata": &bintree{nil, map[string]*bintree{
                        "AllServices.graphql":     
&bintree{graphqlsMetadataAllservicesGraphql, map[string]*bintree{}},
                        "Instances.graphql":       
&bintree{graphqlsMetadataInstancesGraphql, map[string]*bintree{}},
diff --git a/assets/graphqls/logs/Logs.graphql 
b/assets/graphqls/logs/Logs.graphql
new file mode 100644
index 0000000..75ea577
--- /dev/null
+++ b/assets/graphqls/logs/Logs.graphql
@@ -0,0 +1,38 @@
+# Licensed to Apache Software Foundation (ASF) under one or more contributor
+# license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright
+# ownership. Apache Software Foundation (ASF) licenses this file to you under
+# the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+query ($condition: LogQueryCondition!) {
+    result: queryLogs(condition: $condition) {
+        total
+        logs {
+            serviceName
+            serviceId
+            serviceInstanceName
+            serviceInstanceId
+            endpointName
+            endpointId
+            traceId
+            timestamp
+            contentType
+            content
+            tags {
+                key
+                value
+            }
+        }
+    }
+}
diff --git a/cmd/swctl/main.go b/cmd/swctl/main.go
index 0a51e6d..de5759f 100644
--- a/cmd/swctl/main.go
+++ b/cmd/swctl/main.go
@@ -28,6 +28,7 @@ import (
        "github.com/apache/skywalking-cli/internal/commands/install"
        "github.com/apache/skywalking-cli/internal/commands/instance"
        "github.com/apache/skywalking-cli/internal/commands/interceptor"
+       "github.com/apache/skywalking-cli/internal/commands/logs"
        "github.com/apache/skywalking-cli/internal/commands/metrics"
        "github.com/apache/skywalking-cli/internal/commands/service"
        "github.com/apache/skywalking-cli/internal/commands/trace"
@@ -120,6 +121,7 @@ func main() {
                dashboard.Command,
                install.Command,
                event.Command,
+               logs.Command,
        }
 
        app.Before = interceptor.BeforeChain([]cli.BeforeFunc{
diff --git a/internal/commands/logs/list.go b/internal/commands/logs/list.go
new file mode 100644
index 0000000..9a13881
--- /dev/null
+++ b/internal/commands/logs/list.go
@@ -0,0 +1,126 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package logs
+
+import (
+       "strings"
+
+       api "skywalking.apache.org/repo/goapi/query"
+
+       "github.com/apache/skywalking-cli/internal/commands/interceptor"
+       "github.com/apache/skywalking-cli/internal/flags"
+       "github.com/apache/skywalking-cli/internal/logger"
+       "github.com/apache/skywalking-cli/internal/model"
+       "github.com/apache/skywalking-cli/pkg/display"
+       "github.com/apache/skywalking-cli/pkg/display/displayable"
+       "github.com/apache/skywalking-cli/pkg/graphql/log"
+
+       "github.com/urfave/cli"
+)
+
+const DefaultPageSize = 15
+
+var ListCommand = cli.Command{
+       Name:      "list",
+       ShortName: "ls",
+       Usage:     "List logs",
+       Flags: flags.Flags(
+               flags.DurationFlags,
+               []cli.Flag{
+                       cli.StringFlag{
+                               Name:     "service-id",
+                               Usage:    "service id",
+                               Required: false,
+                       },
+                       cli.StringFlag{
+                               Name:     "service-instance-id",
+                               Usage:    "service instance id",
+                               Required: false,
+                       },
+                       cli.StringFlag{
+                               Name:     "endpoint-id",
+                               Usage:    "endpoint id",
+                               Required: false,
+                       },
+                       cli.StringFlag{
+                               Name:     "trace-id",
+                               Usage:    "relate trace id",
+                               Required: false,
+                       },
+                       cli.StringFlag{
+                               Name:     "tags",
+                               Usage:    "key=value,key=value",
+                               Required: false,
+                       },
+               },
+       ),
+       Before: interceptor.BeforeChain([]cli.BeforeFunc{
+               interceptor.TimezoneInterceptor,
+               interceptor.DurationInterceptor,
+       }),
+       Action: func(ctx *cli.Context) error {
+               start := ctx.String("start")
+               end := ctx.String("end")
+               step := ctx.Generic("step")
+
+               duration := api.Duration{
+                       Start: start,
+                       End:   end,
+                       Step:  step.(*model.StepEnumValue).Selected,
+               }
+               serviceID := ctx.String("service-id")
+               serviceInstanceID := ctx.String("service-instance-id")
+               endpointID := ctx.String("endpoint-id")
+               traceID := ctx.String("trace-id")
+               pageNum := 1
+               needTotal := true
+
+               tagStr := ctx.String("tags")
+               var tags []*api.LogTag = nil
+               if tagStr != "" {
+                       tagArr := strings.Split(tagStr, ",")
+                       for _, tag := range tagArr {
+                               kv := strings.Split(tag, "=")
+                               tags = append(tags, &api.LogTag{Key: kv[0], 
Value: &kv[1]})
+                       }
+               }
+
+               paging := api.Pagination{
+                       PageNum:   &pageNum,
+                       PageSize:  DefaultPageSize,
+                       NeedTotal: &needTotal,
+               }
+
+               condition := &api.LogQueryCondition{
+                       ServiceID:         &serviceID,
+                       ServiceInstanceID: &serviceInstanceID,
+                       EndpointID:        &endpointID,
+                       RelatedTrace:      &api.TraceScopeCondition{TraceID: 
traceID},
+                       Tags:              tags,
+                       QueryDuration:     &duration,
+                       Paging:            &paging,
+               }
+               logs, err := log.Logs(ctx, condition)
+
+               if err != nil {
+                       logger.Log.Fatalln(err)
+               }
+
+               return display.Display(ctx, &displayable.Displayable{Data: 
logs, Condition: condition})
+       },
+}
diff --git a/internal/commands/logs/log.go b/internal/commands/logs/log.go
new file mode 100644
index 0000000..0f02a02
--- /dev/null
+++ b/internal/commands/logs/log.go
@@ -0,0 +1,31 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package logs
+
+import (
+       "github.com/urfave/cli"
+)
+
+var Command = cli.Command{
+       Name:      "logs",
+       ShortName: "l",
+       Usage:     "logs related sub-command",
+       Subcommands: cli.Commands{
+               ListCommand,
+       },
+}
diff --git a/pkg/graphql/log/log.go b/pkg/graphql/log/log.go
new file mode 100644
index 0000000..bd30bba
--- /dev/null
+++ b/pkg/graphql/log/log.go
@@ -0,0 +1,40 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package log
+
+import (
+       "github.com/apache/skywalking-cli/assets"
+       "github.com/apache/skywalking-cli/pkg/graphql/client"
+
+       "github.com/machinebox/graphql"
+
+       "github.com/urfave/cli"
+
+       api "skywalking.apache.org/repo/goapi/query"
+)
+
+func Logs(ctx *cli.Context, condition *api.LogQueryCondition) (api.Logs, 
error) {
+       var response map[string]api.Logs
+
+       request := graphql.NewRequest(assets.Read("graphqls/logs/Logs.graphql"))
+       request.Var("condition", condition)
+
+       err := client.ExecuteQuery(ctx, request, &response)
+
+       return response["result"], err
+}

Reply via email to