Skip to content

Commit

Permalink
Merge branch 'main' of github.com:kubeshop/tracetest into feat/split-…
Browse files Browse the repository at this point in the history
…trigger-queue
  • Loading branch information
mathnogueira committed Sep 5, 2023
2 parents 51346e3 + bdc477b commit 7f24134
Show file tree
Hide file tree
Showing 61 changed files with 1,168 additions and 277 deletions.
7 changes: 6 additions & 1 deletion agent/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var StartCmd = cobra.Command{
Short: "Start the local agent",
Long: "Start the local agent",
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
cfg, err := config.LoadConfig()
if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand All @@ -28,7 +29,11 @@ var StartCmd = cobra.Command{

log.Printf("starting agent [%s] connecting to %s", cfg.Name, cfg.ServerURL)

initialization.Start(cfg)
err = initialization.Start(ctx, cfg)
if err != nil {
fmt.Fprintln(os.Stderr, err)
ExitCLI(1)
}
},
}

Expand Down
10 changes: 5 additions & 5 deletions agent/initialization/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package initialization
import (
"context"
"fmt"
"log"

"github.com/kubeshop/tracetest/agent/client"
"github.com/kubeshop/tracetest/agent/config"
Expand All @@ -12,15 +11,14 @@ import (
)

// Start the agent with given configuration
func Start(config config.Config) {
func Start(ctx context.Context, config config.Config) error {
fmt.Println("Starting agent")
ctx := context.Background()
client, err := client.Connect(ctx, config.ServerURL,
client.WithAPIKey(config.APIKey),
client.WithAgentName(config.Name),
)
if err != nil {
log.Fatal(err)
return err
}

triggerWorker := workers.NewTriggerWorker(client)
Expand All @@ -35,8 +33,10 @@ func Start(config config.Config) {

err = client.Start(ctx)
if err != nil {
log.Fatal(err)
return err
}

fmt.Println("Agent started! Do not close the terminal.")
client.WaitUntilDisconnected()
return nil
}
1 change: 1 addition & 0 deletions agent/workers/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func NewTriggerWorker(client *client.Client) *TriggerWorker {
}

func (w *TriggerWorker) Trigger(ctx context.Context, triggerRequest *proto.TriggerRequest) error {
fmt.Println("Trigger handled by agent")
triggerConfig := convertProtoToTrigger(triggerRequest.Trigger)
triggerer, err := w.registry.Get(triggerConfig.Type)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions api/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ components:
version:
type: string
example: 1.0.0
type:
type: string
enum:
- oss
uiEndpoint:
type: string
agentEndpoint:
type: string
114 changes: 0 additions & 114 deletions cli/actions/configure_action.go

This file was deleted.

13 changes: 7 additions & 6 deletions cli/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import (
"fmt"
"os"

"github.com/kubeshop/tracetest/cli/actions"
"github.com/kubeshop/tracetest/cli/analytics"
"github.com/kubeshop/tracetest/cli/config"
"github.com/kubeshop/tracetest/cli/formatters"
"github.com/kubeshop/tracetest/cli/openapi"
"github.com/kubeshop/tracetest/cli/utils"
"github.com/spf13/cobra"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand All @@ -22,6 +20,9 @@ var (
openapiClient = &openapi.APIClient{}
versionText string
isVersionMatch bool

// only available in dev mode
isCloudEnabled = os.Getenv("TRACETEST_DEV") == "true"
)

type setupConfig struct {
Expand Down Expand Up @@ -75,7 +76,7 @@ func setupCommand(options ...setupOption) func(cmd *cobra.Command, args []string

func overrideConfig() {
if overrideEndpoint != "" {
scheme, endpoint, err := config.ParseServerURL(overrideEndpoint)
scheme, endpoint, _, err := config.ParseServerURL(overrideEndpoint)
if err != nil {
msg := fmt.Sprintf("cannot parse endpoint %s", overrideEndpoint)
cliLogger.Error(msg, zap.Error(err))
Expand All @@ -87,7 +88,7 @@ func overrideConfig() {
}

func setupRunners() {
c := utils.GetAPIClient(cliConfig)
c := config.GetAPIClient(cliConfig)
*openapiClient = *c
}

Expand Down Expand Up @@ -154,10 +155,10 @@ func teardownCommand(cmd *cobra.Command, args []string) {
}

func setupVersion() {
versionText, isVersionMatch = actions.GetVersion(
versionText, isVersionMatch = config.GetVersion(
context.Background(),
cliConfig,
utils.GetAPIClient(cliConfig),
config.GetAPIClient(cliConfig),
)
}

Expand Down
18 changes: 11 additions & 7 deletions cli/cmd/configure_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import (
"context"
"net/url"

"github.com/kubeshop/tracetest/cli/actions"
"github.com/kubeshop/tracetest/cli/config"
"github.com/spf13/cobra"
)

var configParams = &configureParameters{}

var (
configurator = config.NewConfigurator(resources)
)

var configureCmd = &cobra.Command{
GroupID: cmdGroupConfig.ID,
Use: "configure",
Expand All @@ -18,17 +22,17 @@ var configureCmd = &cobra.Command{
PreRun: setupLogger,
Run: WithResultHandler(WithParamsHandler(configParams)(func(cmd *cobra.Command, _ []string) (string, error) {
ctx := context.Background()
action := actions.NewConfigureAction(cliConfig)

actionConfig := actions.ConfigureConfig{
Global: configParams.Global,
flags := config.ConfigFlags{}
config, err := config.LoadConfig("")
if err != nil {
return "", err
}

if flagProvided(cmd, "endpoint") {
actionConfig.SetValues.Endpoint = configParams.Endpoint
flags.Endpoint = configParams.Endpoint
}

err := action.Run(ctx, actionConfig)
err = configurator.Start(ctx, config, flags)
return "", err
})),
PostRun: teardownCommand,
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/legacy_test_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

var testCmd = &cobra.Command{
GroupID: cmdGroupTests.ID,
GroupID: cmdGroupResources.ID,
Use: "test",
Short: "Manage your tracetest tests",
Long: "Manage your tracetest tests",
Expand Down
22 changes: 13 additions & 9 deletions cli/cmd/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@ func WithResultHandler(runFn RunFn) CobraRunFn {
res, err := runFn(cmd, args)

if err != nil {
fmt.Fprintf(os.Stderr, `
Version
%s
An error ocurred when executing the command
%s
`, versionText, err.Error())
ExitCLI(1)
OnError(err)
return
}

Expand All @@ -34,6 +26,18 @@ An error ocurred when executing the command
}
}

func OnError(err error) {
fmt.Fprintf(os.Stderr, `
Version
%s
An error ocurred when executing the command
%s
`, versionText, err.Error())
ExitCLI(1)
}

func WithParamsHandler(validators ...Validator) MiddlewareWrapper {
return func(runFn RunFn) RunFn {
return func(cmd *cobra.Command, args []string) (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/resource_run_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"strings"

"github.com/kubeshop/tracetest/cli/config"
"github.com/kubeshop/tracetest/cli/openapi"
"github.com/kubeshop/tracetest/cli/runner"
"github.com/kubeshop/tracetest/cli/utils"
"github.com/spf13/cobra"
)

Expand All @@ -34,7 +34,7 @@ func init() {

orchestrator := runner.Orchestrator(
cliLogger,
utils.GetAPIClient(cliConfig),
config.GetAPIClient(cliConfig),
variableSetClient,
)

Expand Down
Loading

0 comments on commit 7f24134

Please sign in to comment.