Skip to content

Commit

Permalink
Refactoring: use common helper function in place of old custom one (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ycombinator authored and ruflin committed Jul 26, 2018
1 parent f841529 commit bb4adc0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
13 changes: 3 additions & 10 deletions metricbeat/module/elasticsearch/cluster_stats/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ package cluster_stats

import (
"encoding/json"
"fmt"

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

"github.com/elastic/beats/libbeat/common"

Expand Down Expand Up @@ -51,14 +52,6 @@ var (
}
)

// TODO: Remove this function and use the one implemented (currently) in the kibana
// module, after extracting it into the metricbeat helper package
func reportErrorForMissingField(field string, r mb.ReporterV2) error {
err := fmt.Errorf("Could not find field '%v' in Kibana stats API response", field)
r.Error(err)
return err
}

func eventMapping(r mb.ReporterV2, content []byte) error {
var data map[string]interface{}
err := json.Unmarshal(content, &data)
Expand All @@ -75,7 +68,7 @@ func eventMapping(r mb.ReporterV2, content []byte) error {

clusterName, ok := data["cluster_name"]
if !ok {
return reportErrorForMissingField("cluster_name", r)
return elastic.ReportErrorForMissingField("cluster_name", elastic.Elasticsearch, r)
}

var event mb.Event
Expand Down
9 changes: 0 additions & 9 deletions metricbeat/module/kibana/kibana.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,8 @@ import (
"github.com/elastic/beats/libbeat/common"

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

// ReportErrorForMissingField reports and returns an error message for the given
// field being missing in API response received from Kibana
func ReportErrorForMissingField(field string, r mb.ReporterV2) error {
err := fmt.Errorf("Could not find field '%v' in Kibana stats API response", field)
r.Error(err)
return err
}

// GetVersion returns the version of the Kibana instance
func GetVersion(http *helper.HTTP, currentPath string) (string, error) {
const statusPath = "api/status"
Expand Down

0 comments on commit bb4adc0

Please sign in to comment.