Skip to content
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

Fix for not reusable http client leading to connection leaks in Jolokia module #11014

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix issue with `elasticsearch/node_stats` metricset (x-pack) not indexing `source_node` field. {pull}10639[10639]
- Migrate docker autodiscover to ECS. {issue}10757[10757] {pull}10862[10862]
- Fix issue in kubernetes module preventing usage percentages to be properly calculated. {pull}10946[10946]
- Fix for not reusable http client leading to connection leaks in Jolokia module {pull}11014[11014]

*Packetbeat*

Expand Down
22 changes: 8 additions & 14 deletions metricbeat/module/jolokia/jmx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/helper"
)

type JMXMapping struct {
Expand Down Expand Up @@ -355,20 +354,17 @@ func (pc *JolokiaHTTPGetFetcher) Fetch(m *MetricSet) ([]common.MapStr, error) {
}

for _, r := range httpReqs {
m.http.SetMethod(r.HTTPMethod)
m.http.SetURI(m.BaseMetricSet.HostData().SanitizedURI + r.URI)

http, err := helper.NewHTTP(m.BaseMetricSet)

http.SetMethod(r.HTTPMethod)
http.SetURI(m.BaseMetricSet.HostData().SanitizedURI + r.URI)

resBody, err := http.FetchContent()
resBody, err := m.http.FetchContent()
if err != nil {
return nil, err
}

if logp.IsDebug(metricsetName) {
m.log.Debugw("Jolokia response body",
"host", m.HostData().Host, "uri", http.GetURI(), "body", string(resBody), "type", "response")
"host", m.HostData().Host, "uri", m.http.GetURI(), "body", string(resBody), "type", "response")
}

// Map response to Metricbeat events
Expand Down Expand Up @@ -491,19 +487,17 @@ func (pc *JolokiaHTTPPostFetcher) Fetch(m *MetricSet) ([]common.MapStr, error) {
}
}

http, err := helper.NewHTTP(m.BaseMetricSet)

http.SetMethod(httpReqs[0].HTTPMethod)
http.SetBody(httpReqs[0].Body)
m.http.SetMethod(httpReqs[0].HTTPMethod)
m.http.SetBody(httpReqs[0].Body)

resBody, err := http.FetchContent()
resBody, err := m.http.FetchContent()
jsoriano marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}

if logp.IsDebug(metricsetName) {
m.log.Debugw("Jolokia response body",
"host", m.HostData().Host, "uri", http.GetURI(), "body", string(resBody), "type", "response")
"host", m.HostData().Host, "uri", m.http.GetURI(), "body", string(resBody), "type", "response")
}

// Map response to Metricbeat events
Expand Down
17 changes: 13 additions & 4 deletions metricbeat/module/jolokia/jmx/jmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package jmx
import (
"github.com/joeshaw/multierror"

"github.com/elastic/beats/metricbeat/helper"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/mb"
Expand Down Expand Up @@ -55,8 +57,9 @@ type MetricSet struct {
mb.BaseMetricSet
mapping []JMXMapping
namespace string
http JolokiaHTTPRequestFetcher
jolokia JolokiaHTTPRequestFetcher
log *logp.Logger
http *helper.HTTP
}

// New create a new instance of the MetricSet
Expand All @@ -71,16 +74,22 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
return nil, err
}

jolokiaHTTPBuild := NewJolokiaHTTPRequestFetcher(config.HTTPMethod)
jolokiaFetcher := NewJolokiaHTTPRequestFetcher(config.HTTPMethod)

log := logp.NewLogger(metricsetName).With("host", base.HostData().Host)

http, err := helper.NewHTTP(base)
if err != nil {
return nil, err
}

return &MetricSet{
BaseMetricSet: base,
mapping: config.Mappings,
namespace: config.Namespace,
http: jolokiaHTTPBuild,
jolokia: jolokiaFetcher,
log: log,
http: http,
}, nil
}

Expand All @@ -89,7 +98,7 @@ func (m *MetricSet) Fetch() ([]common.MapStr, error) {

var allEvents []common.MapStr

allEvents, err := m.http.Fetch(m)
allEvents, err := m.jolokia.Fetch(m)
if err != nil {
return nil, err
}
Expand Down