Skip to content

Commit

Permalink
Clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed May 6, 2024
1 parent b028395 commit 407b95f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
3 changes: 1 addition & 2 deletions internal/source/ai-brain/assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func newAssistant(cfg *Config, log logrus.FieldLogger, out chan source.Event, ku
tracer := otel.Tracer(serviceName)

kcRunner := NewKubectlRunner(kubeConfigPath, tracer)
bkRunner, err := NewBotkubeRunner(kcRunner, tracer)
bkRunner, err := NewBotkubeRunner(tracer)
if err != nil {
return nil, fmt.Errorf("while creating Botkube runner: %w", err)
}
Expand All @@ -92,7 +92,6 @@ func newAssistant(cfg *Config, log logrus.FieldLogger, out chan source.Event, ku
"kubectlTopNodes": kcRunner.TopNodes,
"kubectlLogs": kcRunner.Logs,
"botkubeGetStartupAgentConfiguration": bkRunner.GetStartupAgentConfiguration,
"botkubeGetCloudAgentConfiguration": bkRunner.GetCloudAgentConfiguration, // TODO: do we need that?
"botkubeGetAgentStatus": bkRunner.GetAgentStatus,
},
}, nil
Expand Down
25 changes: 7 additions & 18 deletions internal/source/ai-brain/botkube_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ type BotkubeRunner struct {
httpCli *http.Client
rawStartupConfig string
startupConfig *ConfigWithDetails
logGetter LogGetter
}

// LogGetter provides ability to get logs.
type LogGetter interface {
Logs(ctx context.Context, rawArgs []byte, _ *Payload) (string, error)
// ConfigWithDetails represents Botkube configuration with additional details.
type ConfigWithDetails struct {
*config.Config `yaml:",inline"`
LoaderValidationWarnings string `yaml:"loaderValidationWarnings"`
IncomingRequestPrompt string `yaml:"incomingRequestPrompt,omitempty"`
}

// NewBotkubeRunner creates new runner instance.
func NewBotkubeRunner(logGetter LogGetter, tracer trace.Tracer) (*BotkubeRunner, error) {
func NewBotkubeRunner(tracer trace.Tracer) (*BotkubeRunner, error) {
cfg, ok := remote.GetConfig()
if !ok {
return nil, fmt.Errorf("cannot get Botkube cloud related environment variables")
Expand All @@ -46,7 +47,6 @@ func NewBotkubeRunner(logGetter LogGetter, tracer trace.Tracer) (*BotkubeRunner,
tracer: tracer,
deployCli: remote.NewDeploymentClient(cfg),
httpCli: httpx.NewHTTPClient(),
logGetter: logGetter,
}

err := r.initStartupConfig()
Expand All @@ -56,18 +56,6 @@ func NewBotkubeRunner(logGetter LogGetter, tracer trace.Tracer) (*BotkubeRunner,
return r, nil
}

type ConfigWithDetails struct {
*config.Config `yaml:",inline"`
LoaderValidationWarnings string `yaml:"loaderValidationWarnings"`
IncomingRequestPrompt string `yaml:"incomingRequestPrompt,omitempty"`
}

// TODO: to remove?
func (r *BotkubeRunner) GetCloudAgentConfiguration(ctx context.Context, _ []byte, _ *Payload) (string, error) {
rawCfg, _, err := r.fetchConfig(ctx)
return rawCfg, err
}

// GetStartupAgentConfiguration returns Botkube startup configuration.
func (r *BotkubeRunner) GetStartupAgentConfiguration(ctx context.Context, _ []byte, p *Payload) (string, error) {
_, span := r.tracer.Start(ctx, "aibrain.BotkubeRunner.GetStartupAgentConfiguration")
Expand All @@ -91,6 +79,7 @@ func (r *BotkubeRunner) GetStartupAgentConfiguration(ctx context.Context, _ []by
return string(raw), nil
}

// GetAgentStatus returns Botkube Agent health status.
func (r *BotkubeRunner) GetAgentStatus(ctx context.Context, _ []byte, _ *Payload) (string, error) {
_, span := r.tracer.Start(ctx, "aibrain.BotkubeRunner.GetAgentStatus")
defer span.End()
Expand Down

0 comments on commit 407b95f

Please sign in to comment.