summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorArne Juul <arnej@yahooinc.com>2022-09-21 14:31:24 +0000
committerArne Juul <arnej@yahooinc.com>2022-09-21 14:31:24 +0000
commitac2de34d8db81049a6aeee709ea4cc79bb361d0b (patch)
treeb57be9edccec88c14b55b1818ddcb64c4e30e3a6 /client
parent5e08068fa0c7def183cf94b659e7d6fdb5ec1297 (diff)
move tracing to its own package
Diffstat (limited to 'client')
-rw-r--r--client/go/cmd/clusterstate/cluster_state.go6
-rw-r--r--client/go/cmd/clusterstate/detect_model.go5
-rw-r--r--client/go/cmd/clusterstate/get_cluster_state.go11
-rw-r--r--client/go/cmd/clusterstate/get_node_state.go9
-rw-r--r--client/go/cmd/clusterstate/model_config.go4
-rw-r--r--client/go/cmd/clusterstate/options.go5
-rw-r--r--client/go/cmd/clusterstate/run_cmd.go4
-rw-r--r--client/go/cmd/clusterstate/run_curl.go7
-rw-r--r--client/go/cmd/clusterstate/set_node_state.go3
-rw-r--r--client/go/trace/trace.go (renamed from client/go/cmd/clusterstate/trace.go)15
10 files changed, 42 insertions, 27 deletions
diff --git a/client/go/cmd/clusterstate/cluster_state.go b/client/go/cmd/clusterstate/cluster_state.go
index 5d111942ae6..5f8a1d7079f 100644
--- a/client/go/cmd/clusterstate/cluster_state.go
+++ b/client/go/cmd/clusterstate/cluster_state.go
@@ -9,6 +9,8 @@ import (
"encoding/json"
"fmt"
"strings"
+
+ "github.com/vespa-engine/vespa/client/go/trace"
)
// common struct used various places in the clustercontroller REST api:
@@ -90,7 +92,7 @@ func (model *VespaModelConfig) getClusterState(cluster string) (*ClusterState, *
errs := make([]string, 0, 0)
ccs := model.findClusterControllers()
if len(ccs) == 0 {
- PutTrace("No cluster controllers found in vespa model:", model)
+ trace.Trace("No cluster controllers found in vespa model:", model)
errs = append(errs, "No cluster controllers found in vespa model config")
}
for _, cc := range ccs {
@@ -106,7 +108,7 @@ func (model *VespaModelConfig) getClusterState(cluster string) (*ClusterState, *
var parsedJson ClusterState
err = codec.Decode(&parsedJson)
if err != nil {
- PutTrace("Could not parse JSON >>>", buf.String(), "<<< from", url)
+ trace.Trace("Could not parse JSON >>>", buf.String(), "<<< from", url)
errs = append(errs, "Bad JSON from "+url+" was: "+buf.String())
continue
}
diff --git a/client/go/cmd/clusterstate/detect_model.go b/client/go/cmd/clusterstate/detect_model.go
index 781fa3cfa5e..ff924e5fa83 100644
--- a/client/go/cmd/clusterstate/detect_model.go
+++ b/client/go/cmd/clusterstate/detect_model.go
@@ -8,6 +8,7 @@ import (
"strconv"
"strings"
+ "github.com/vespa-engine/vespa/client/go/trace"
"github.com/vespa-engine/vespa/client/go/vespa"
)
@@ -20,7 +21,7 @@ func getConfigServerHosts(s string) []string {
if err != nil || len(res) < 1 {
panic("bad configservers: " + got)
}
- PutDebug("found", len(res), "configservers:", res)
+ trace.Debug("found", len(res), "configservers:", res)
return res
}
@@ -35,7 +36,7 @@ func getConfigServerPort(i int) int {
if err != nil || i < 1 {
panic("bad configserver_rpc_port: " + got)
}
- PutDebug("found configservers rpc port:", i)
+ trace.Debug("found configservers rpc port:", i)
return i
}
diff --git a/client/go/cmd/clusterstate/get_cluster_state.go b/client/go/cmd/clusterstate/get_cluster_state.go
index 4c380a99986..90e4351e855 100644
--- a/client/go/cmd/clusterstate/get_cluster_state.go
+++ b/client/go/cmd/clusterstate/get_cluster_state.go
@@ -12,6 +12,7 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/build"
+ "github.com/vespa-engine/vespa/client/go/trace"
)
func NewGetClusterStateCmd() *cobra.Command {
@@ -36,21 +37,21 @@ func NewGetClusterStateCmd() *cobra.Command {
func runGetClusterState(opts *Options) {
if opts.Silent {
- currentOutputLevel = levelNone
+ trace.Silent()
}
if opts.NoColors || os.Getenv("TERM") == "" {
color.NoColor = true
}
- PutDebug("run getClusterState with: ", opts)
+ trace.Debug("run getClusterState with: ", opts)
m := detectModel(opts)
- PutDebug("model:", m)
+ trace.Debug("model:", m)
sss := m.findSelectedServices(opts)
clusters := make(map[string]*ClusterState)
for _, s := range sss {
- PutDebug("found service: ", s)
+ trace.Debug("found service: ", s)
if clusters[s.cluster] == nil {
state, _ := m.getClusterState(s.cluster)
- PutDebug("cluster ", s.cluster, state)
+ trace.Debug("cluster ", s.cluster, state)
clusters[s.cluster] = state
}
}
diff --git a/client/go/cmd/clusterstate/get_node_state.go b/client/go/cmd/clusterstate/get_node_state.go
index 3b48d362398..24472042ea8 100644
--- a/client/go/cmd/clusterstate/get_node_state.go
+++ b/client/go/cmd/clusterstate/get_node_state.go
@@ -13,6 +13,7 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/build"
+ "github.com/vespa-engine/vespa/client/go/trace"
)
const (
@@ -54,12 +55,12 @@ func NewGetNodeStateCmd() *cobra.Command {
func runGetNodeState(opts *Options) {
if opts.Silent {
- currentOutputLevel = levelNone
+ trace.Silent()
}
if opts.NoColors || os.Getenv("TERM") == "" {
color.NoColor = true
}
- PutInfo(header)
+ trace.Info(header)
m := detectModel(opts)
sss := m.findSelectedServices(opts)
clusters := make(map[string]*ClusterState)
@@ -70,7 +71,7 @@ func runGetNodeState(opts *Options) {
clusters[s.cluster] = state
}
if state == nil {
- PutWarning("no state for cluster: ", s.cluster)
+ trace.Warning("no state for cluster: ", s.cluster)
continue
}
if nodes, ok := state.Service[s.serviceType]; ok {
@@ -83,7 +84,7 @@ func runGetNodeState(opts *Options) {
}
}
} else {
- PutWarning("no nodes for service type: ", s.serviceType)
+ trace.Warning("no nodes for service type: ", s.serviceType)
continue
}
diff --git a/client/go/cmd/clusterstate/model_config.go b/client/go/cmd/clusterstate/model_config.go
index ce9aa556c8a..9a7510eba79 100644
--- a/client/go/cmd/clusterstate/model_config.go
+++ b/client/go/cmd/clusterstate/model_config.go
@@ -8,6 +8,8 @@ import (
"encoding/json"
"sort"
"strings"
+
+ "github.com/vespa-engine/vespa/client/go/trace"
)
type VespaModelConfig struct {
@@ -63,7 +65,7 @@ func parseModelConfig(input string) *VespaModelConfig {
var parsedJson VespaModelConfig
err := codec.Decode(&parsedJson)
if err != nil {
- PutTrace("could not decode JSON >>>", input, "<<< error:", err)
+ trace.Trace("could not decode JSON >>>", input, "<<< error:", err)
return nil
}
return &parsedJson
diff --git a/client/go/cmd/clusterstate/options.go b/client/go/cmd/clusterstate/options.go
index 1bdb5e22034..b2537a52766 100644
--- a/client/go/cmd/clusterstate/options.go
+++ b/client/go/cmd/clusterstate/options.go
@@ -10,6 +10,7 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"
+ "github.com/vespa-engine/vespa/client/go/trace"
"github.com/vespa-engine/vespa/client/go/vespa"
)
@@ -140,9 +141,9 @@ func addCommonOptions(cmd *cobra.Command, curOptions *Options) {
flag.NoOptDefVal = "true"
cobra.OnInitialize(func() {
if curOptions.Silent {
- AdjustVerbosity(-1)
+ trace.Silent()
} else {
- AdjustVerbosity(curOptions.Verbose)
+ trace.AdjustVerbosity(curOptions.Verbose)
}
})
}
diff --git a/client/go/cmd/clusterstate/run_cmd.go b/client/go/cmd/clusterstate/run_cmd.go
index df7e3a91a0e..4b67ad46a86 100644
--- a/client/go/cmd/clusterstate/run_cmd.go
+++ b/client/go/cmd/clusterstate/run_cmd.go
@@ -9,6 +9,8 @@ import (
"os"
"os/exec"
"strings"
+
+ "github.com/vespa-engine/vespa/client/go/trace"
)
func getOutputFromCmd(program string, args ...string) (string, error) {
@@ -16,7 +18,7 @@ func getOutputFromCmd(program string, args ...string) (string, error) {
var out bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = os.Stderr
- PutDebug("running command:", program, strings.Join(args, " "))
+ trace.Debug("running command:", program, strings.Join(args, " "))
err := cmd.Run()
return out.String(), err
}
diff --git a/client/go/cmd/clusterstate/run_curl.go b/client/go/cmd/clusterstate/run_curl.go
index 981f55c9e13..9275c558c6d 100644
--- a/client/go/cmd/clusterstate/run_curl.go
+++ b/client/go/cmd/clusterstate/run_curl.go
@@ -13,6 +13,7 @@ import (
"strings"
"github.com/vespa-engine/vespa/client/go/curl"
+ "github.com/vespa-engine/vespa/client/go/trace"
"github.com/vespa-engine/vespa/client/go/vespa"
)
@@ -47,7 +48,7 @@ func curlGet(url string, output io.Writer) error {
if err != nil {
return err
}
- PutTrace("running curl:", cmd.String())
+ trace.Trace("running curl:", cmd.String())
err = cmd.Run(output, os.Stderr)
return err
}
@@ -58,8 +59,8 @@ func curlPost(url string, input []byte) (string, error) {
cmd.Header("Content-Type", "application/json")
cmd.WithBodyInput(bytes.NewReader(input))
var out bytes.Buffer
- PutDebug("POST input: " + string(input))
- PutTrace("running curl:", cmd.String())
+ trace.Debug("POST input: " + string(input))
+ trace.Trace("running curl:", cmd.String())
err = cmd.Run(&out, os.Stderr)
if err != nil {
if ee, ok := err.(*exec.ExitError); ok {
diff --git a/client/go/cmd/clusterstate/set_node_state.go b/client/go/cmd/clusterstate/set_node_state.go
index 04e06ff1daf..ad0977d1c4b 100644
--- a/client/go/cmd/clusterstate/set_node_state.go
+++ b/client/go/cmd/clusterstate/set_node_state.go
@@ -14,6 +14,7 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/build"
+ "github.com/vespa-engine/vespa/client/go/trace"
)
const (
@@ -70,7 +71,7 @@ func NewSetNodeStateCmd() *cobra.Command {
func runSetNodeState(opts *Options, args []string) {
if opts.Silent {
- currentOutputLevel = levelNone
+ trace.Silent()
}
if opts.NoColors || os.Getenv("TERM") == "" {
color.NoColor = true
diff --git a/client/go/cmd/clusterstate/trace.go b/client/go/trace/trace.go
index cf268cc6239..9752341a402 100644
--- a/client/go/cmd/clusterstate/trace.go
+++ b/client/go/trace/trace.go
@@ -1,8 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Author: arnej
-// utilities to get and manipulate node states in a storage cluster
-package clusterstate
+package trace
import (
"fmt"
@@ -27,6 +26,10 @@ func AdjustVerbosity(howMuch int) {
currentOutputLevel = (outputLevel)(howMuch + int(currentOutputLevel))
}
+func Silent() {
+ currentOutputLevel = levelNone
+}
+
func outputStderr(l outputLevel, v ...interface{}) {
if l > currentOutputLevel {
return
@@ -34,18 +37,18 @@ func outputStderr(l outputLevel, v ...interface{}) {
fmt.Fprintln(os.Stderr, v...)
}
-func PutInfo(v ...interface{}) {
+func Info(v ...interface{}) {
outputStderr(levelInfo, v...)
}
-func PutTrace(v ...interface{}) {
+func Trace(v ...interface{}) {
outputStderr(levelTrace, v...)
}
-func PutDebug(v ...interface{}) {
+func Debug(v ...interface{}) {
outputStderr(levelDebug, v...)
}
-func PutWarning(v ...interface{}) {
+func Warning(v ...interface{}) {
fmt.Fprintln(os.Stderr, v...)
}