Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions assets/graphqls/logs/BrowserLogs.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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: BrowserErrorLogQueryCondition!) {
result: queryBrowserErrorLogs(condition: $condition) {
total
logs {
service
serviceVersion
time
pagePath
category
grade
message
line
col
stack
errorUrl
firstReportedError
}
}
}
22 changes: 22 additions & 0 deletions assets/graphqls/metadata/AllBrowserServices.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Licensed to Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Apache Software Foundation (ASF) licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

query ($duration: Duration!) {
result: getAllBrowserServices(duration: $duration) {
id name
}
}
22 changes: 22 additions & 0 deletions assets/graphqls/metadata/SearchBrowserService.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Licensed to Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Apache Software Foundation (ASF) licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

query ($serviceCode: String!) {
result: searchBrowserService(serviceCode: $serviceCode) {
id name
}
}
2 changes: 2 additions & 0 deletions cmd/swctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"runtime"

"github.com/apache/skywalking-cli/internal/commands/browser"
"github.com/apache/skywalking-cli/internal/commands/completion"
"github.com/apache/skywalking-cli/internal/commands/dashboard"
"github.com/apache/skywalking-cli/internal/commands/dependency"
Expand Down Expand Up @@ -82,6 +83,7 @@ services, service instances, etc.`
flags := flags()

app.Commands = []*cli.Command{
browser.Command,
endpoint.Command,
instance.Command,
service.Command,
Expand Down
39 changes: 39 additions & 0 deletions internal/commands/browser/browser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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 browser

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

"github.com/apache/skywalking-cli/internal/commands/browser/logs"
"github.com/apache/skywalking-cli/internal/commands/browser/page"
"github.com/apache/skywalking-cli/internal/commands/browser/service"
"github.com/apache/skywalking-cli/internal/commands/browser/version"
)

var Command = &cli.Command{
Name: "browser",
Aliases: []string{"b"},
Usage: "Browser related sub-command",
Subcommands: cli.Commands{
service.Command,
version.Command,
page.Command,
logs.Command,
},
}
92 changes: 92 additions & 0 deletions internal/commands/browser/logs/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// 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/v2"

"github.com/apache/skywalking-cli/internal/commands/interceptor"
"github.com/apache/skywalking-cli/internal/flags"
"github.com/apache/skywalking-cli/internal/model"
"github.com/apache/skywalking-cli/pkg/display"
"github.com/apache/skywalking-cli/pkg/display/displayable"
"github.com/apache/skywalking-cli/pkg/graphql/log"

api "skywalking.apache.org/repo/goapi/query"
)

const DefaultPageSize = 15

var listCommand = &cli.Command{
Name: "list",
Aliases: []string{"ls"},
Usage: "List browser error logs according to the specified options",
UsageText: `List browser error logs according to the specified options.

Examples:
1. Query all logs:
$ swctl browser logs list`,
Flags: flags.Flags(
flags.DurationFlags,
flags.VersionFlags,
flags.PageFlags,
),
Before: interceptor.BeforeChain(
interceptor.DurationInterceptor,
interceptor.ParseVersion(false),
interceptor.ParsePage(false),
),
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")
serviceVersionID := ctx.String("version-id")
pageID := ctx.String("page-id")

pageNum := 1
needTotal := true

paging := api.Pagination{
PageNum: &pageNum,
PageSize: DefaultPageSize,
NeedTotal: &needTotal,
}
condition := &api.BrowserErrorLogQueryCondition{
ServiceID: &serviceID,
ServiceVersionID: &serviceVersionID,
PagePathID: &pageID,
QueryDuration: &duration,
Paging: &paging,
}

logs, err := log.BrowserLogs(ctx, condition)
if err != nil {
return err
}

return display.Display(ctx, &displayable.Displayable{Data: logs, Condition: condition})
},
}
29 changes: 29 additions & 0 deletions internal/commands/browser/logs/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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/v2"

var Command = &cli.Command{
Name: "logs",
Aliases: []string{"l"},
Usage: "Browser error log related sub-command",
Subcommands: cli.Commands{
listCommand,
},
}
69 changes: 69 additions & 0 deletions internal/commands/browser/page/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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 page

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

"github.com/apache/skywalking-cli/internal/commands/interceptor"
"github.com/apache/skywalking-cli/internal/flags"
"github.com/apache/skywalking-cli/pkg/display"
"github.com/apache/skywalking-cli/pkg/display/displayable"
"github.com/apache/skywalking-cli/pkg/graphql/metadata"
)

var listCommand = &cli.Command{
Name: "list",
Aliases: []string{"ls"},
Usage: `list all monitored browser page of the give "--service-id" or "--service-name"`,
UsageText: `This command lists all page of the browser service, via service id or service name.

Examples:
1. List all page of the browser service by service name "test-ui":
$ swctl browser page ls --service-name test-ui

2. List all page of the browser service by service id "dGVzdC11aQ==.1":
$ swctl browser page ls --service-id dGVzdC11aQ==.1`,
Flags: flags.Flags(
flags.ServiceFlags,

[]cli.Flag{
&cli.IntFlag{
Name: "limit",
Usage: "returns at most `<limit>` endpoints",
Required: false,
Value: 100,
},
},
),
Before: interceptor.BeforeChain(
interceptor.ParseBrowserService(true),
),
Action: func(ctx *cli.Context) error {
serviceID := ctx.String("service-id")
limit := ctx.Int("limit")

endpoints, err := metadata.SearchEndpoints(ctx, serviceID, "", limit)

if err != nil {
return err
}

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

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

var Command = &cli.Command{
Name: "page",
Aliases: []string{"p", "endpoint"},
Usage: "Browser page related sub-command",
Subcommands: cli.Commands{
listCommand,
},
}
Loading