forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry-pick elastic#18797 to 7.7: Fix panic on `metricbeat test modul…
…es` (elastic#18853) Since metricbeat light modules support processors (elastic#15923), module initialization requires a publisher in the beat so modules can attach their processors. `metricbeat test modules` is not initializing as normal metricbeat commands, and it is not initializing any output or publisher pipeline, so metricbeat panics when trying to initialize modules with the new method. This change adds a dummy publisher for this case, and fixes also a condition that was adding a `nil` module option, causing additional panics. A test that reproduced the issues is also added. (cherry picked from commit 316793d) Add nil pipeline from elastic#16715, required for the fix. (cherry picked from commit 257fdfc) Co-authored-by: Steffen Siering <[email protected]>
- Loading branch information
Showing
5 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package pipeline | ||
|
||
import "github.com/elastic/beats/v7/libbeat/beat" | ||
|
||
type nilPipeline struct{} | ||
|
||
type nilClient struct { | ||
eventer beat.ClientEventer | ||
ackCount func(int) | ||
ackEvents func([]interface{}) | ||
ackLastEvent func(interface{}) | ||
} | ||
|
||
var _nilPipeline = (*nilPipeline)(nil) | ||
|
||
// NewNilPipeline returns a new pipeline that is compatible with | ||
// beats.PipelineConnector. The pipeline will discard all events that have been | ||
// published. Client ACK handlers will still be executed, but the callbacks | ||
// will be executed immediately when the event is published. | ||
func NewNilPipeline() beat.PipelineConnector { return _nilPipeline } | ||
|
||
func (p *nilPipeline) Connect() (beat.Client, error) { | ||
return p.ConnectWith(beat.ClientConfig{}) | ||
} | ||
|
||
func (p *nilPipeline) ConnectWith(cfg beat.ClientConfig) (beat.Client, error) { | ||
return &nilClient{ | ||
eventer: cfg.Events, | ||
ackCount: cfg.ACKCount, | ||
ackEvents: cfg.ACKEvents, | ||
ackLastEvent: cfg.ACKLastEvent, | ||
}, nil | ||
} | ||
|
||
func (c *nilClient) Publish(event beat.Event) { | ||
c.PublishAll([]beat.Event{event}) | ||
} | ||
|
||
func (c *nilClient) PublishAll(events []beat.Event) { | ||
L := len(events) | ||
if L == 0 { | ||
return | ||
} | ||
|
||
if c.ackLastEvent != nil { | ||
c.ackLastEvent(events[L-1].Private) | ||
} | ||
if c.ackEvents != nil { | ||
tmp := make([]interface{}, L) | ||
for i := range events { | ||
tmp[i] = events[i].Private | ||
} | ||
c.ackEvents(tmp) | ||
} | ||
if c.ackCount != nil { | ||
c.ackCount(L) | ||
} | ||
} | ||
|
||
func (c *nilClient) Close() error { | ||
if c.eventer != nil { | ||
c.eventer.Closing() | ||
c.eventer.Closed() | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters