-
Notifications
You must be signed in to change notification settings - Fork 5k
Move HTTP calls to Logstash from New() to Fetch() #15306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
26bee1c
ad2b588
b695681
f077d1d
7ca1709
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,8 +18,6 @@ | |
| package node_stats | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/elastic/beats/metricbeat/mb" | ||
| "github.com/elastic/beats/metricbeat/mb/parse" | ||
| "github.com/elastic/beats/metricbeat/module/logstash" | ||
|
|
@@ -59,25 +57,6 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { | |
| return nil, err | ||
| } | ||
|
|
||
| if ms.XPack { | ||
| logstashVersion, err := logstash.GetVersion(ms) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| arePipelineGraphAPIsAvailable := logstash.ArePipelineGraphAPIsAvailable(logstashVersion) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if !arePipelineGraphAPIsAvailable { | ||
| const errorMsg = "The %v metricset with X-Pack enabled is only supported with Logstash >= %v. You are currently running Logstash %v" | ||
| return nil, fmt.Errorf(errorMsg, ms.FullyQualifiedName(), logstash.PipelineGraphAPIsAvailableVersion, logstashVersion) | ||
| } | ||
|
|
||
| ms.HTTP.SetURI(ms.HTTP.GetURI() + "?vertices=true") | ||
| } | ||
|
|
||
| return &MetricSet{ | ||
| ms, | ||
| }, nil | ||
|
|
@@ -87,6 +66,15 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { | |
| // It returns the event which is then forward to the output. In case of an error, a | ||
| // descriptive error must be returned. | ||
| func (m *MetricSet) Fetch(r mb.ReporterV2) error { | ||
| err := m.init() | ||
| if err != nil { | ||
| if m.XPack { | ||
| m.Logger().Error(err) | ||
| return nil | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| content, err := m.HTTP.FetchContent() | ||
| if err != nil { | ||
| if m.XPack { | ||
|
|
@@ -107,3 +95,16 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { | |
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (m *MetricSet) init() error { | ||
| if m.XPack { | ||
| err := m.CheckPipelineGraphAPIsAvailable() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| m.HTTP.SetURI(m.HTTP.GetURI() + "?vertices=true") | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ycombinator The two init function looks really close to me could it be possible to move them to the logstash package and use the same?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ph I extracted much of the common code into the |
||
| return nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.