Skip to content

Commit

Permalink
Allow passing natsOpts from service observations and js advisories (#203
Browse files Browse the repository at this point in the history
)

* allow passing natsOpts from service observations and js advisories

Signed-off-by: Caleb Lloyd <[email protected]>

* Lint fix

---------

Signed-off-by: Caleb Lloyd <[email protected]>
Co-authored-by: Samuel Attwood <[email protected]>
  • Loading branch information
caleblloyd and samuelattwood authored Jun 12, 2024
1 parent e63b6b8 commit 91df8f4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ require (
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
golang.org/x/crypto v0.19.0
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
golang.org/x/sync v0.6.0
)

Expand Down Expand Up @@ -46,6 +45,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
Expand Down
5 changes: 4 additions & 1 deletion surveyor/conn_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type natsContext struct {
TLSCA string `json:"tls_ca"`
TLSCert string `json:"tls_cert"`
TLSKey string `json:"tls_key"`

// only passed programmatically
NatsOpts []nats.Option `json:"-"`
}

func (c *natsContext) copy() *natsContext {
Expand Down Expand Up @@ -199,7 +202,7 @@ func (cp *natsConnPool) getPooledConn(key string, cfg *natsContext) (*pooledNats
}
cp.Unlock()

opts := cp.natsOpts
opts := append(cp.natsOpts, cfg.NatsOpts...)
opts = append(opts, func(options *nats.Options) error {
if cfg.Name != "" {
options.Name = cfg.Name
Expand Down
13 changes: 9 additions & 4 deletions surveyor/jetstream_advisories.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,6 @@ type JSAdvisoryConfig struct {
// account name
AccountName string `json:"name"`

// optional configuration for importing JS metrics and advisories from other accounts
// it can only be set via JSAdvisoryConfig directly (not from config file)
ExternalAccountConfig *JSAdvisoriesExternalAccountConfig `json:"-"`

// connection options
JWT string `json:"jwt"`
Seed string `json:"seed"`
Expand All @@ -250,6 +246,14 @@ type JSAdvisoryConfig struct {
TLSCA string `json:"tls_ca"`
TLSCert string `json:"tls_cert"`
TLSKey string `json:"tls_key"`

// additional opts available via JSAdvisoryConfig directly (not from config file)

// optional configuration for importing JS metrics and advisories from other accounts
ExternalAccountConfig *JSAdvisoriesExternalAccountConfig `json:"-"`

// nats options appended to base surveyor options
NatsOpts []nats.Option `json:"-"`
}

// JSAdvisoriesExternalAccountConfig is used to configure external accounts from which
Expand Down Expand Up @@ -387,6 +391,7 @@ func (o *jsAdvisoryListener) natsContext() *natsContext {
TLSCA: o.config.TLSCA,
TLSCert: o.config.TLSCert,
TLSKey: o.config.TLSKey,
NatsOpts: o.config.NatsOpts,
}

return natsCtx
Expand Down
13 changes: 9 additions & 4 deletions surveyor/observation.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ type ServiceObsConfig struct {
ServiceName string `json:"name"`
Topic string `json:"topic"`

// optional configuration for importing observations from other accounts
// it can only be set via ServiceObsConfig directly (not from config file)
ExternalAccountConfig *ServiceObservationExternalAccountConfig `json:"-"`

// connection options
JWT string `json:"jwt"`
Seed string `json:"seed"`
Expand All @@ -140,6 +136,14 @@ type ServiceObsConfig struct {
TLSCA string `json:"tls_ca"`
TLSCert string `json:"tls_cert"`
TLSKey string `json:"tls_key"`

// additional opts available via ServiceObsConfig directly (not from config file)

// optional configuration for importing observations from other accounts
ExternalAccountConfig *ServiceObservationExternalAccountConfig `json:"-"`

// nats options appended to base surveyor options
NatsOpts []nats.Option `json:"-"`
}

type ServiceObservationExternalAccountConfig struct {
Expand Down Expand Up @@ -262,6 +266,7 @@ func (o *serviceObsListener) natsContext() *natsContext {
TLSCA: o.config.TLSCA,
TLSCert: o.config.TLSCert,
TLSKey: o.config.TLSKey,
NatsOpts: o.config.NatsOpts,
}

// legacy Credentials field
Expand Down
3 changes: 1 addition & 2 deletions surveyor/surveyor.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ func (s *Surveyor) createStatszCollector() error {
}

s.statzC = NewStatzCollector(s.sysAcctPC.nc, s.logger, s.opts.ExpectedServers, s.opts.ServerResponseWait, s.opts.PollTimeout, s.opts.Accounts, s.opts.ConstLabels)
s.promRegistry.MustRegister(s.statzC)
return nil
return s.promRegistry.Register(s.statzC)
}

// generates the TLS config for https
Expand Down

0 comments on commit 91df8f4

Please sign in to comment.