2022-05-13 13:30:22 +00:00
|
|
|
package main
|
|
|
|
|
2022-05-14 17:56:09 +00:00
|
|
|
import (
|
2023-09-11 08:18:43 +00:00
|
|
|
"context"
|
2025-02-04 15:25:59 +00:00
|
|
|
"encoding/json"
|
2025-02-03 03:18:38 +00:00
|
|
|
"fmt"
|
2024-07-10 06:38:06 +00:00
|
|
|
"os"
|
2023-09-11 08:18:43 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
"github.com/databricks/cli/cmd"
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/cmd/root"
|
2025-02-03 03:18:38 +00:00
|
|
|
"github.com/databricks/cli/libs/telemetry"
|
2025-02-21 17:05:42 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/logger"
|
2022-05-14 17:56:09 +00:00
|
|
|
)
|
2022-05-13 13:30:22 +00:00
|
|
|
|
|
|
|
func main() {
|
2024-07-10 06:38:06 +00:00
|
|
|
ctx := context.Background()
|
2025-02-03 03:18:38 +00:00
|
|
|
|
2025-02-24 17:09:21 +00:00
|
|
|
// A new process is spawned for uploading telemetry data. We handle this separately
|
2025-02-03 03:18:38 +00:00
|
|
|
// from the rest of the CLI commands.
|
|
|
|
// This is done because [root.Execute] spawns a new process to run the
|
|
|
|
// "telemetry upload" command if there are logs to be uploaded. Having this outside
|
|
|
|
// of [root.Execute] ensures that the telemetry upload process is not spawned
|
|
|
|
// infinitely in a recursive manner.
|
2025-02-03 03:24:09 +00:00
|
|
|
if len(os.Args) == 3 && os.Args[1] == "telemetry" && os.Args[2] == "upload" {
|
2025-02-28 16:52:47 +00:00
|
|
|
// Suppress info logs (and lower) from the SDK. This ensures that INFO / DEBUG logs
|
2025-02-27 11:58:43 +00:00
|
|
|
// from the SDK are not printed to stdout / stderr.
|
2025-02-21 17:05:42 +00:00
|
|
|
logger.DefaultLogger = &logger.SimpleLogger{
|
2025-02-28 16:52:47 +00:00
|
|
|
Level: logger.LevelWarn,
|
2025-02-21 17:05:42 +00:00
|
|
|
}
|
|
|
|
|
2025-02-24 17:05:19 +00:00
|
|
|
resp, err := telemetry.Upload(ctx)
|
2025-02-03 03:18:38 +00:00
|
|
|
if err != nil {
|
2025-02-27 11:47:26 +00:00
|
|
|
fmt.Fprintf(os.Stderr, "error: %s\n", err)
|
2025-02-03 03:18:38 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
2025-02-27 11:47:26 +00:00
|
|
|
fmt.Printf("Telemetry logs uploaded successfully\n")
|
|
|
|
fmt.Println("Response:")
|
2025-02-04 15:25:59 +00:00
|
|
|
b, err := json.Marshal(resp)
|
|
|
|
if err == nil {
|
2025-02-27 11:47:26 +00:00
|
|
|
fmt.Println(string(b))
|
2025-02-04 15:25:59 +00:00
|
|
|
}
|
2025-02-03 03:18:38 +00:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2024-07-10 06:38:06 +00:00
|
|
|
err := root.Execute(ctx, cmd.New(ctx))
|
|
|
|
if err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2022-05-13 13:30:22 +00:00
|
|
|
}
|