Skip to content

Commit

Permalink
added multi agent support, dynamic ratelimiting depending on amount o…
Browse files Browse the repository at this point in the history
…f nodes
  • Loading branch information
kuzxnia committed Feb 26, 2024
1 parent 8569189 commit 8231c77
Show file tree
Hide file tree
Showing 19 changed files with 474 additions and 257 deletions.
13 changes: 9 additions & 4 deletions cli/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"context"

"github.com/kuzxnia/loadbot/lbot"
"github.com/kuzxnia/loadbot/lbot/agent"
"github.com/samber/lo"
)

// tutaj nie powinno wchodzić proto
func StartAgent(context context.Context, config *lbot.AgentRequest, stdin bool, configFile string) (err error) {
func StartAgent(
context context.Context, config *lbot.AgentRequest, stdin bool, configFile string,
) (err error) {
var requestConfig *lbot.ConfigRequest

if stdin {
Expand Down Expand Up @@ -54,10 +56,13 @@ func StartAgent(context context.Context, config *lbot.AgentRequest, stdin bool,
requestConfig.Agent.MetricsExportPort = config.MetricsExportPort
}

agent := lbot.NewAgent(context)
loadbot := lbot.NewLbot(context)

agent := agent.NewAgent(context, loadbot)
if requestConfig != nil {
agent.ApplyConfig(requestConfig)
}
agent.Listen()
agent.Start()

return nil
}
86 changes: 5 additions & 81 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"time"

"github.com/kuzxnia/loadbot/cli/cluster"
"github.com/kuzxnia/loadbot/cli/workload"
"github.com/kuzxnia/loadbot/lbot"
"github.com/kuzxnia/loadbot/lbot/proto"
Expand All @@ -23,7 +22,6 @@ func New(version string, commit string, date string) *cobra.Command {
cmd.AddCommand(
provideWorkloadCommands(),
provideAgentCommand(),
provideClusterCommands(),
)
cmd.Root().CompletionOptions.HiddenDefaultCmd = true

Expand Down Expand Up @@ -241,7 +239,11 @@ func provideAgentCommand() *cobra.Command {
configFile, _ := flags.GetString(ConfigFile)
stdin, _ := flags.GetBool(StdIn)

return StartAgent(cmd.Context(), agentConfig, stdin, configFile)
return StartAgent(
cmd.Context(), agentConfig, stdin, configFile,
// cluster agrs
// snapshotDir, internalCommunicationPort, nodeID, initCluster,
)
},
}

Expand All @@ -259,79 +261,6 @@ func provideAgentCommand() *cobra.Command {
return &agentRootCommand
}

const (
ClusterRootCommand = "cluster"
// cluster commands
InitClusterCommand = "init"
ConfigClusterCommand = "config"
StatusClusterCommand = "status"
AddAgentToClusterCommand = "add-agent"
RemoveAgentFromClusterCommand = "remove-agent"
)

func provideClusterCommands() *cobra.Command {
clusterRootCommand := cobra.Command{
Use: ClusterRootCommand,
Short: "Cluster Commands",
}

initCommand := cobra.Command{
Use: InitClusterCommand,
Short: "Initialize cluster - transform standalone agents into agentset",
Args: cobra.ExactArgs(installationArgsNum),
RunE: func(cmd *cobra.Command, args []string) (err error) {
// todo: provide config

// or list of ips with ports
// - dummy way,
// because without setting priority, voting
return cluster.InitCluster()
},
}

configCommand := cobra.Command{
Use: ConfigClusterCommand,
Short: "Cluster config",
Args: cobra.ExactArgs(installationArgsNum),
RunE: func(cmd *cobra.Command, args []string) (err error) {
return cluster.InitCluster()
},
}
statusCommand := cobra.Command{
Use: StatusClusterCommand,
Short: "Cluster status",
Args: cobra.ExactArgs(installationArgsNum),
RunE: func(cmd *cobra.Command, args []string) (err error) {
return cluster.InitCluster()
},
}
addAgentCommand := cobra.Command{
Use: AddAgentToClusterCommand,
Short: "Cluster status",
Args: cobra.ExactArgs(installationArgsNum),
RunE: func(cmd *cobra.Command, args []string) (err error) {
return cluster.InitCluster()
},
}
removeAgentCommand := cobra.Command{
Use: RemoveAgentFromClusterCommand,
Short: "Cluster status",
Args: cobra.ExactArgs(installationArgsNum),
RunE: func(cmd *cobra.Command, args []string) (err error) {
return cluster.InitCluster()
},
}
clusterRootCommand.AddCommand(
&initCommand,
&configCommand,
&statusCommand,
&addAgentCommand,
&removeAgentCommand,
)

return &clusterRootCommand
}

const (
CommandInstall = "install"
CommandUnInstall = "uninstall"
Expand Down Expand Up @@ -371,11 +300,6 @@ func provideOrchiestrationCommands() []*cobra.Command {
flags.StringSlice(FlagHelmSetString, nil, "set additional Helm STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
flags.StringSlice(FlagHelmSetFile, nil, "set additional Helm values from respective files specified via the command line (can specify multiple or separate values with commas: key1=path1,key2=path2)")

// if no flags provided, install as local, simply start
// skipCleanup
// helmTimeout
// helmValues

unInstallationCommand := cobra.Command{
// todo: where to keep configuration? there will be couple workloads at the same time
Use: CommandUnInstall,
Expand Down
1 change: 0 additions & 1 deletion cli/cluster/add_agent.go

This file was deleted.

1 change: 0 additions & 1 deletion cli/cluster/config.go

This file was deleted.

8 changes: 0 additions & 8 deletions cli/cluster/init.go

This file was deleted.

1 change: 0 additions & 1 deletion cli/cluster/remove_agent.go

This file was deleted.

11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/docker/docker v25.0.0+incompatible
github.com/go-faker/faker/v4 v4.2.0
github.com/google/uuid v1.3.1
github.com/pkg/errors v0.9.1
github.com/samber/lo v1.39.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
Expand Down Expand Up @@ -35,17 +36,15 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand All @@ -63,14 +62,14 @@ require (
go.opentelemetry.io/otel/trace v1.22.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/tools v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
Expand Down
19 changes: 10 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
Expand All @@ -61,8 +62,8 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.16.0 h1:iULayQNOReoYUe+1qtKOqw9CwJv3aNQu8ivo7lw1HU4=
github.com/klauspost/compress v1.16.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down Expand Up @@ -156,8 +157,8 @@ golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down Expand Up @@ -203,8 +204,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand All @@ -221,8 +222,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
108 changes: 0 additions & 108 deletions lbot/agent.go

This file was deleted.

Loading

0 comments on commit 8231c77

Please sign in to comment.