Skip to content

Commit

Permalink
x-pack/filebeat/input/entityanalytics/provider/azuread: fix configura…
Browse files Browse the repository at this point in the history
…tion ordering (#40487)

Previously, the configuration was eager, this caused a panic when the request
trace logging option was turned on since it was started without a context.

Move the construction of components to when we have all the parts we need.
  • Loading branch information
efd6 committed Aug 13, 2024
1 parent 8f1a1cc commit dd73639
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Relax requirements in Okta entity analytics provider user and device profile data shape. {pull}40359[40359]
- Fix bug in Okta entity analytics rate limit logic. {issue}40106[40106] {pull}40267[40267]
- Fix crashes in the journald input. {pull}40061[40061]
- Fix order of configuration for EntraID entity analytics provider. {pull}40487[40487]

*Heartbeat*

Expand Down
26 changes: 15 additions & 11 deletions x-pack/filebeat/input/entityanalytics/provider/azuread/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var _ provider.Provider = &azure{}
type azure struct {
*kvstore.Manager

cfg *config.C
conf conf

metrics *inputMetrics
Expand Down Expand Up @@ -74,8 +75,20 @@ func (p *azure) Test(testCtx v2.TestContext) error {
func (p *azure) Run(inputCtx v2.Context, store *kvstore.Store, client beat.Client) error {
p.logger = inputCtx.Logger.With("tenant_id", p.conf.TenantID, "provider", Name)
p.ctx = inputCtx

var err error
p.auth, err = oauth2.New(p.cfg, p.Manager.Logger)
if err != nil {
return fmt.Errorf("unable to create authenticator: %w", err)
}
p.auth.SetLogger(p.logger)

p.fetcher, err = graph.New(ctxtool.FromCanceller(p.ctx.Cancelation), p.ctx.ID, p.cfg, p.Manager.Logger, p.auth)
if err != nil {
return fmt.Errorf("unable to create fetcher: %w", err)
}
p.fetcher.SetLogger(p.logger)

p.metrics = newMetrics(inputCtx.ID, nil)
defer p.metrics.Close()

Expand Down Expand Up @@ -569,19 +582,10 @@ func (p *azure) publishDevice(d *fetcher.Device, state *stateStore, inputID stri

// configure configures this provider using the given configuration.
func (p *azure) configure(cfg *config.C) (kvstore.Input, error) {
var err error

if err = cfg.Unpack(&p.conf); err != nil {
if err := cfg.Unpack(&p.conf); err != nil {
return nil, fmt.Errorf("unable to unpack %s input config: %w", Name, err)
}

if p.auth, err = oauth2.New(cfg, p.Manager.Logger); err != nil {
return nil, fmt.Errorf("unable to create authenticator: %w", err)
}
if p.fetcher, err = graph.New(ctxtool.FromCanceller(p.ctx.Cancelation), p.ctx.ID, cfg, p.Manager.Logger, p.auth); err != nil {
return nil, fmt.Errorf("unable to create fetcher: %w", err)
}

p.cfg = cfg
return p, nil
}

Expand Down

0 comments on commit dd73639

Please sign in to comment.