Skip to content

Commit

Permalink
fix: make rabbitmq connection optional and disable for token generati…
Browse files Browse the repository at this point in the history
…on (#635)
  • Loading branch information
abelanger5 authored Jun 25, 2024
1 parent ff93914 commit 771054a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
7 changes: 6 additions & 1 deletion cmd/hatchet-admin/cli/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/cobra"

"github.com/hatchet-dev/hatchet/pkg/config/loader"
"github.com/hatchet-dev/hatchet/pkg/config/server"
)

var (
Expand Down Expand Up @@ -60,7 +61,11 @@ func runCreateAPIToken() error {
// read in the local config
configLoader := loader.NewConfigLoader(configDirectory)

cleanup, serverConf, err := configLoader.LoadServerConfig()
cleanup, serverConf, err := configLoader.LoadServerConfig(func(scf *server.ServerConfigFile) {
// disable rabbitmq since it's not needed to create the api token
scf.MessageQueue.Enabled = false
})

if err != nil {
return err
}
Expand Down
46 changes: 31 additions & 15 deletions pkg/config/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/hatchet-dev/hatchet/internal/integrations/email/postmark"
"github.com/hatchet-dev/hatchet/internal/integrations/vcs"
"github.com/hatchet-dev/hatchet/internal/integrations/vcs/github"
"github.com/hatchet-dev/hatchet/internal/msgqueue"
"github.com/hatchet-dev/hatchet/internal/msgqueue/rabbitmq"
"github.com/hatchet-dev/hatchet/internal/services/ingestor"
"github.com/hatchet-dev/hatchet/pkg/analytics"
Expand Down Expand Up @@ -97,8 +98,10 @@ func (c *ConfigLoader) LoadDatabaseConfig() (res *database.Config, err error) {
return GetDatabaseConfigFromConfigFile(cf, &scf.Runtime)
}

type ServerConfigFileOverride func(*server.ServerConfigFile)

// LoadServerConfig loads the server configuration
func (c *ConfigLoader) LoadServerConfig() (cleanup func() error, res *server.ServerConfig, err error) {
func (c *ConfigLoader) LoadServerConfig(overrides ...ServerConfigFileOverride) (cleanup func() error, res *server.ServerConfig, err error) {
log.Printf("Loading server config from %s", c.directory)
sharedFilePath := filepath.Join(c.directory, "server.yaml")
log.Printf("Shared file path: %s", sharedFilePath)
Expand All @@ -118,6 +121,10 @@ func (c *ConfigLoader) LoadServerConfig() (cleanup func() error, res *server.Ser
return nil, nil, err
}

for _, override := range overrides {
override(cf)
}

return GetServerConfigFromConfigfile(dc, cf)
}

Expand Down Expand Up @@ -206,21 +213,30 @@ func GetServerConfigFromConfigfile(dc *database.Config, cf *server.ServerConfigF
return nil, nil, fmt.Errorf("could not create session store: %w", err)
}

cleanup1, mq := rabbitmq.New(
rabbitmq.WithURL(cf.MessageQueue.RabbitMQ.URL),
rabbitmq.WithLogger(&l),
)
var mq msgqueue.MessageQueue
cleanup1 := func() error {
return nil
}

ingestor, err := ingestor.NewIngestor(
ingestor.WithEventRepository(dc.EngineRepository.Event()),
ingestor.WithStreamEventsRepository(dc.EngineRepository.StreamEvent()),
ingestor.WithLogRepository(dc.EngineRepository.Log()),
ingestor.WithMessageQueue(mq),
ingestor.WithEntitlementsRepository(dc.EntitlementRepository),
)
var ing ingestor.Ingestor

if err != nil {
return nil, nil, fmt.Errorf("could not create ingestor: %w", err)
if cf.MessageQueue.Enabled {
cleanup1, mq = rabbitmq.New(
rabbitmq.WithURL(cf.MessageQueue.RabbitMQ.URL),
rabbitmq.WithLogger(&l),
)

ing, err = ingestor.NewIngestor(
ingestor.WithEventRepository(dc.EngineRepository.Event()),
ingestor.WithStreamEventsRepository(dc.EngineRepository.StreamEvent()),
ingestor.WithLogRepository(dc.EngineRepository.Log()),
ingestor.WithMessageQueue(mq),
ingestor.WithEntitlementsRepository(dc.EntitlementRepository),
)

if err != nil {
return nil, nil, fmt.Errorf("could not create ingestor: %w", err)
}
}

var alerter errors.Alerter
Expand Down Expand Up @@ -439,7 +455,7 @@ func GetServerConfigFromConfigfile(dc *database.Config, cf *server.ServerConfigF
TLSConfig: tls,
SessionStore: ss,
Validator: validator.NewDefaultValidator(),
Ingestor: ingestor,
Ingestor: ing,
OpenTelemetry: cf.OpenTelemetry,
VCSProviders: vcsProviders,
InternalClient: internalClient,
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ type ConfigFileAuthCookie struct {
}

type MessageQueueConfigFile struct {
Enabled bool `mapstructure:"enabled" json:"enabled,omitempty" default:"true"`

Kind string `mapstructure:"kind" json:"kind,omitempty" validate:"required"`

RabbitMQ RabbitMQConfigFile `mapstructure:"rabbitmq" json:"rabbitmq,omitempty" validate:"required"`
Expand Down

0 comments on commit 771054a

Please sign in to comment.