Skip to content

Commit

Permalink
Don't stop Metricbeat if aerospike server is down (#6874)
Browse files Browse the repository at this point in the history
Ensure Aerospike module constructor doesn't return an error if it cannot
immediately connect to the server.
  • Loading branch information
exekias authored and ruflin committed Apr 17, 2018
1 parent f3aa089 commit fd15ea2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Fix Windows perfmon metricset so that it sends metrics when an error occurs. {pull}6542[6542]
- Fix Kubernetes calculated fields store. {pull}6564{6564}
- Exclude bind mounts in fsstat and filesystem metricsets. {pull}6819[6819]
- Don't stop Metricbeat if aerospike server is down. {pull}6874[6874]

*Packetbeat*

Expand Down
24 changes: 18 additions & 6 deletions metricbeat/module/aerospike/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func init() {
// multiple fetch calls.
type MetricSet struct {
mb.BaseMetricSet
host *as.Host
client *as.Client
}

Expand All @@ -47,14 +48,9 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
return nil, errors.Wrap(err, "Invalid host format, expected hostname:port")
}

client, err := as.NewClientWithPolicyAndHost(as.NewClientPolicy(), host)
if err != nil {
return nil, err
}

return &MetricSet{
BaseMetricSet: base,
client: client,
host: host,
}, nil
}

Expand All @@ -64,6 +60,10 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
func (m *MetricSet) Fetch() ([]common.MapStr, error) {
var events []common.MapStr

if err := m.connect(); err != nil {
return nil, err
}

for _, node := range m.client.GetNodes() {
info, err := as.RequestNodeInfo(node, "namespaces")
if err != nil {
Expand Down Expand Up @@ -91,3 +91,15 @@ func (m *MetricSet) Fetch() ([]common.MapStr, error) {

return events, nil
}

// create an aerospike client if it doesn't exist yet
func (m *MetricSet) connect() error {
if m.client == nil {
client, err := as.NewClientWithPolicyAndHost(as.NewClientPolicy(), m.host)
if err != nil {
return err
}
m.client = client
}
return nil
}

0 comments on commit fd15ea2

Please sign in to comment.