summaryrefslogtreecommitdiffstats
path: root/client/go
diff options
context:
space:
mode:
authorArne Juul <arnej@yahooinc.com>2022-09-21 14:37:12 +0000
committerArne Juul <arnej@yahooinc.com>2022-09-22 13:51:20 +0000
commit6e2a680f4def36ec530e0c754f9aa8f906ceb32d (patch)
treec3f9be49a07a86f140d2142f65ccd6b3b3019b33 /client/go
parent044b53e197f3f4f15a0a302f137cbacb4acb9385 (diff)
common tracing
Diffstat (limited to 'client/go')
-rw-r--r--client/go/cmd/deploy/cmd.go17
-rw-r--r--client/go/cmd/deploy/curl.go3
-rw-r--r--client/go/cmd/deploy/persist.go7
-rw-r--r--client/go/cmd/deploy/trace.go50
-rw-r--r--client/go/cmd/deploy/upload.go4
-rw-r--r--client/go/cmd/deploy/urls.go5
6 files changed, 21 insertions, 65 deletions
diff --git a/client/go/cmd/deploy/cmd.go b/client/go/cmd/deploy/cmd.go
index 6c1d560fe79..bf21ffce59f 100644
--- a/client/go/cmd/deploy/cmd.go
+++ b/client/go/cmd/deploy/cmd.go
@@ -10,6 +10,7 @@ import (
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/build"
+ "github.com/vespa-engine/vespa/client/go/trace"
"github.com/vespa-engine/vespa/client/go/vespa"
)
@@ -73,9 +74,9 @@ func newUploadCmd(opts *Options) *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
opts.Command = CmdUpload
if opts.Verbose {
- AdjustVerbosity(1)
+ trace.AdjustVerbosity(1)
}
- PutTrace("upload with", opts, args)
+ trace.Trace("upload with", opts, args)
err := RunUpload(opts, args)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
@@ -95,9 +96,9 @@ func newPrepareCmd(opts *Options) *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
opts.Command = CmdPrepare
if opts.Verbose {
- AdjustVerbosity(1)
+ trace.AdjustVerbosity(1)
}
- PutTrace("prepare with", opts, args)
+ trace.Trace("prepare with", opts, args)
err := RunPrepare(opts, args)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
@@ -116,9 +117,9 @@ func newActivateCmd(opts *Options) *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
opts.Command = CmdActivate
if opts.Verbose {
- AdjustVerbosity(1)
+ trace.AdjustVerbosity(1)
}
- PutTrace("activate with", opts, args)
+ trace.Trace("activate with", opts, args)
err := RunActivate(opts, args)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
@@ -137,9 +138,9 @@ func newFetchCmd(opts *Options) *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
opts.Command = CmdFetch
if opts.Verbose {
- AdjustVerbosity(1)
+ trace.AdjustVerbosity(1)
}
- PutTrace("fetch with", opts, args)
+ trace.Trace("fetch with", opts, args)
err := RunFetch(opts, args)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
diff --git a/client/go/cmd/deploy/curl.go b/client/go/cmd/deploy/curl.go
index 6a0a722d502..7b7b478b84b 100644
--- a/client/go/cmd/deploy/curl.go
+++ b/client/go/cmd/deploy/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"
)
@@ -91,7 +92,7 @@ func getOutputFromCmd(program string, args ...string) (string, error) {
}
func runCurl(cmd *curl.Command, stdout io.Writer) error {
- PutTrace("running curl:", cmd.String())
+ trace.Trace("running curl:", cmd.String())
err := cmd.Run(stdout, os.Stderr)
if err != nil {
if ee, ok := err.(*exec.ExitError); ok {
diff --git a/client/go/cmd/deploy/persist.go b/client/go/cmd/deploy/persist.go
index 31423050902..682e7b13674 100644
--- a/client/go/cmd/deploy/persist.go
+++ b/client/go/cmd/deploy/persist.go
@@ -5,9 +5,10 @@
package deploy
import (
- // "fmt"
"os"
"path/filepath"
+
+ "github.com/vespa-engine/vespa/client/go/trace"
)
const (
@@ -67,7 +68,7 @@ func writeSessionIdToFile(tenant, newSessionId string) {
dir := createTenantDir(tenant)
fn := filepath.Join(dir, sessionIdFileName)
os.WriteFile(fn, []byte(newSessionId), 0600)
- PutTrace("wrote", newSessionId, "to", fn)
+ trace.Trace("wrote", newSessionId, "to", fn)
}
}
@@ -76,7 +77,7 @@ func getSessionIdFromFile(tenant string) string {
fn := filepath.Join(dir, sessionIdFileName)
bytes, err := os.ReadFile(fn)
if err == nil {
- PutTrace("Session-id", string(bytes), "found from file", fn)
+ trace.Trace("Session-id", string(bytes), "found from file", fn)
return string(bytes)
}
panic("Could not read session id from file, and no session id supplied as argument. Exiting.")
diff --git a/client/go/cmd/deploy/trace.go b/client/go/cmd/deploy/trace.go
deleted file mode 100644
index ece708d3174..00000000000
--- a/client/go/cmd/deploy/trace.go
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// Author: arnej
-
-package deploy
-
-import (
- "fmt"
- "os"
-)
-
-// handling of informational output
-
-type outputLevel int
-
-const (
- levelNone outputLevel = iota
- levelInfo
- levelTrace
- levelDebug
- levelSpam
-)
-
-var currentOutputLevel outputLevel = levelInfo
-
-func AdjustVerbosity(howMuch int) {
- currentOutputLevel = (outputLevel)(howMuch + int(currentOutputLevel))
-}
-
-func outputStderr(l outputLevel, v ...interface{}) {
- if l > currentOutputLevel {
- return
- }
- fmt.Fprintln(os.Stderr, v...)
-}
-
-func PutInfo(v ...interface{}) {
- outputStderr(levelInfo, v...)
-}
-
-func PutTrace(v ...interface{}) {
- outputStderr(levelTrace, v...)
-}
-
-func PutDebug(v ...interface{}) {
- outputStderr(levelDebug, v...)
-}
-
-func PutWarning(v ...interface{}) {
- fmt.Fprintln(os.Stderr, v...)
-}
diff --git a/client/go/cmd/deploy/upload.go b/client/go/cmd/deploy/upload.go
index 20272a4b2da..9041fbad3f7 100644
--- a/client/go/cmd/deploy/upload.go
+++ b/client/go/cmd/deploy/upload.go
@@ -9,6 +9,8 @@ import (
"os"
"os/exec"
"strings"
+
+ "github.com/vespa-engine/vespa/client/go/trace"
)
// main entry point for vespa-deploy upload
@@ -80,7 +82,7 @@ func uploadFrom(opts *Options, src string) (string, error) {
url := src + pathPrefix(opts)
url = addUrlPropertyFromOption(url, opts.From, "from")
url = addUrlPropertyFromFlag(url, opts.Verbose, "verbose")
- PutTrace("Upload from URL", opts.From, "using", urlWithoutQuery(url))
+ trace.Trace("Upload from URL", opts.From, "using", urlWithoutQuery(url))
output, err := curlPost(url, nil)
return output, err
}
diff --git a/client/go/cmd/deploy/urls.go b/client/go/cmd/deploy/urls.go
index 9c56656ec6b..54b779b6682 100644
--- a/client/go/cmd/deploy/urls.go
+++ b/client/go/cmd/deploy/urls.go
@@ -8,6 +8,7 @@ import (
"fmt"
"strings"
+ "github.com/vespa-engine/vespa/client/go/trace"
"github.com/vespa-engine/vespa/client/go/vespa"
)
@@ -32,12 +33,12 @@ func makeConfigsourceUrls(opts *Options) []string {
if len(colonParts) > 1 {
// XXX overwrites port number from above - is this sensible?
src = fmt.Sprintf("%s:%s:%d", colonParts[0], colonParts[1], opts.PortNumber)
- PutTrace("can use config server at", src)
+ trace.Trace("can use config server at", src)
results = append(results, src)
}
}
if len(results) == 0 {
- PutWarning("Could not get url to config server, make sure that VESPA_CONFIGSERVERS is set")
+ trace.Warning("Could not get url to config server, make sure that VESPA_CONFIGSERVERS is set")
results = append(results, fmt.Sprintf("http://localhost:%d", opts.PortNumber))
}
} else {