Add check health command (#43)
diff --git a/assets/graphqls/common/checkHealth.graphql b/assets/graphqls/common/checkHealth.graphql
new file mode 100644
index 0000000..25297f2
--- /dev/null
+++ b/assets/graphqls/common/checkHealth.graphql
@@ -0,0 +1,23 @@
+# 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 {
+ checkHealth {
+ score
+ details
+ }
+}
diff --git a/cmd/main.go b/cmd/main.go
index 6577b67..74ec77e 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -21,6 +21,7 @@
"io/ioutil"
"os"
+ "github.com/apache/skywalking-cli/commands/common"
"github.com/apache/skywalking-cli/commands/trace"
"github.com/apache/skywalking-cli/commands/metrics"
@@ -87,6 +88,7 @@
service.Command,
metrics.Command,
trace.Command,
+ common.Command,
}
app.Before = interceptor.BeforeChain([]cli.BeforeFunc{
diff --git a/commands/common/common.go b/commands/common/common.go
new file mode 100644
index 0000000..2f8bb06
--- /dev/null
+++ b/commands/common/common.go
@@ -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.
+
+package common
+
+import (
+ "github.com/urfave/cli"
+
+ "github.com/apache/skywalking-cli/display"
+ "github.com/apache/skywalking-cli/display/displayable"
+ "github.com/apache/skywalking-cli/graphql/common"
+)
+
+var Command = cli.Command{
+ Name: "checkHealth",
+ Aliases: []string{"ch"},
+ Usage: "Check the health status of OAP server",
+ Action: func(ctx *cli.Context) error {
+ healthStatus := common.CheckHealth(ctx)
+ return display.Display(ctx, &displayable.Displayable{Data: healthStatus})
+ },
+}
diff --git a/graphql/common/common.go b/graphql/common/common.go
new file mode 100644
index 0000000..1f1c417
--- /dev/null
+++ b/graphql/common/common.go
@@ -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.
+
+package common
+
+import (
+ "github.com/machinebox/graphql"
+ "github.com/urfave/cli"
+
+ "github.com/apache/skywalking-cli/assets"
+ "github.com/apache/skywalking-cli/graphql/client"
+ "github.com/apache/skywalking-cli/graphql/schema"
+)
+
+// CheckHealth intends to query the health status of OAP server
+func CheckHealth(ctx *cli.Context) schema.HealthStatus {
+ var response map[string]schema.HealthStatus
+
+ request := graphql.NewRequest(assets.Read("graphqls/common/checkHealth.graphql"))
+
+ client.ExecuteQueryOrFail(ctx, request, &response)
+
+ return response["checkHealth"]
+}
diff --git a/graphql/utils/constants.go b/graphql/utils/constants.go
index b4f0f3d..4d233e7 100644
--- a/graphql/utils/constants.go
+++ b/graphql/utils/constants.go
@@ -29,7 +29,6 @@
schema.StepMinute: "2006-01-02 1504",
schema.StepHour: "2006-01-02 15",
schema.StepDay: "2006-01-02",
- schema.StepMonth: "2006-01",
}
// StepDuration is a mapping from schema.Step to its time.Duration
@@ -38,5 +37,4 @@
schema.StepMinute: time.Minute,
schema.StepHour: time.Hour,
schema.StepDay: time.Hour * 24,
- schema.StepMonth: time.Hour * 24 * 30,
}
diff --git a/query-protocol b/query-protocol
index 06373bf..563bb51 160000
--- a/query-protocol
+++ b/query-protocol
@@ -1 +1 @@
-Subproject commit 06373bf0d1204b6d3f410c0daf4c7f72529f28a0
+Subproject commit 563bb51c71922f017911345d7cd5c62a7ac8995c