Skip to content

Commit

Permalink
Exit after connection error
Browse files Browse the repository at this point in the history
  • Loading branch information
camdencheek committed Aug 18, 2020
1 parent 26d50e2 commit 7b1ab3b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/broker/topic_offset_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package broker

import (
"fmt"
"os"

"github.com/newrelic/infra-integrations-sdk/data/metric"
"github.com/newrelic/infra-integrations-sdk/integration"
"github.com/newrelic/infra-integrations-sdk/jmx"
"github.com/newrelic/infra-integrations-sdk/log"
"github.com/newrelic/nri-kafka/src/args"
"github.com/newrelic/nri-kafka/src/connection"
Expand All @@ -24,7 +26,10 @@ func gatherTopicOffset(b *connection.Broker, topicSampleLookup map[string]*metri

beanName := beanModifier(metrics.TopicOffsetMetricDef.MBean)
results, err := jmxwrapper.JMXQuery(beanName, args.GlobalArgs.Timeout)
if err != nil {
if err != nil && err == jmx.ErrConnection {
log.Error("Connection error: %s", err)
os.Exit(1)
} else if err != nil {
log.Error("Broker '%s' failed to make JMX Query: %s", b.Host, err.Error())
continue
} else if len(results) == 0 {
Expand Down
19 changes: 15 additions & 4 deletions src/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ package metrics
import (
"errors"
"fmt"
"os"
"regexp"
"strings"

"github.com/newrelic/infra-integrations-sdk/data/metric"
"github.com/newrelic/infra-integrations-sdk/integration"
"github.com/newrelic/infra-integrations-sdk/jmx"
"github.com/newrelic/infra-integrations-sdk/log"
"github.com/newrelic/nri-kafka/src/args"
"github.com/newrelic/nri-kafka/src/jmxwrapper"
Expand Down Expand Up @@ -74,8 +76,11 @@ func CollectBrokerRequestMetrics(sample *metric.Set, metricSets []*JMXMetricSet)
// Return all the results under a specific mBean
results, err := jmxwrapper.JMXQuery(beanName, args.GlobalArgs.Timeout)
// If we fail we don't want a total failure as other metrics can be collected even if a single failure/timout occurs
if err != nil {
log.Error("Unable to execute JMX query for MBean '%s': %s", beanName, err.Error())
if err != nil && err == jmx.ErrConnection {
log.Error("Connection error: %s", err)
os.Exit(1)
} else if err != nil {
log.Error("Unable to execute JMX query for MBean '%s': %s", beanName, err)
continue
}

Expand Down Expand Up @@ -127,7 +132,10 @@ func CollectMetricDefinitions(sample *metric.Set, metricSets []*JMXMetricSet, be
// Return all the results under a specific mBean
results, err := jmxwrapper.JMXQuery(beanName, args.GlobalArgs.Timeout)
// If we fail we don't want a total failure as other metrics can be collected even if a single failure/timout occurs
if err != nil {
if err != nil && err == jmx.ErrConnection {
log.Error("Connection error: %s", err)
os.Exit(1)
} else if err != nil {
log.Error("Unable to execute JMX query for MBean '%s': %s", beanName, err.Error())
continue
}
Expand Down Expand Up @@ -198,7 +206,10 @@ func getTopicListFromJMX(producer string) ([]string, error) {

func getAllTopicsFromJMX(producer string) ([]string, error) {
result, err := jmxwrapper.JMXQuery(fmt.Sprintf("kafka.producer:type=producer-topic-metrics,client-id=%s,topic=*", producer), args.GlobalArgs.Timeout)
if err != nil {
if err != nil && err == jmx.ErrConnection {
log.Error("Connection error: %s", err)
os.Exit(1)
} else if err != nil {
return nil, err
}

Expand Down

0 comments on commit 7b1ab3b

Please sign in to comment.