Skip to content

Commit

Permalink
apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
ruflin committed Jul 10, 2018
1 parent d5cb2eb commit d4edb11
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 9 deletions.
10 changes: 10 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -3672,6 +3672,16 @@ type: long
Processed data events.
--
*`elasticsearch.ml.job.data_counts.invalid_date_count`*::
+
--
type: long
The number of records with either a missing date field or a date that could not be parsed.
--
[float]
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/include/fields.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion metricbeat/module/elasticsearch/ml_job/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
=== elasticsearch ml MetricSet
=== elasticsearch ml_job MetricSet

This is the ml_job metricset of the module Elasticsearch. This metricset requires https://www.elastic.co/products/x-pack/machine-learning[Machine Learning] to be enabled.
6 changes: 6 additions & 0 deletions metricbeat/module/elasticsearch/ml_job/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@
type: long
description: >
Processed data events.
- name: data_counts.invalid_date_count
type: long
description: >
The number of records with either a missing date field or a date that could not be parsed.
12 changes: 7 additions & 5 deletions metricbeat/module/elasticsearch/ml_job/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package ml_job
import (
"encoding/json"

"github.com/joeshaw/multierror"

"github.com/elastic/beats/libbeat/common"
s "github.com/elastic/beats/libbeat/common/schema"
c "github.com/elastic/beats/libbeat/common/schema/mapstriface"
Expand All @@ -32,6 +34,7 @@ var (
"state": c.Str("state"),
"data_counts": c.Dict("data_counts", s.Schema{
"processed_record_count": c.Int("processed_record_count"),
"invalid_date_count": c.Int("invalid_date_count"),
}),
}
)
Expand All @@ -40,16 +43,15 @@ type jobsStruct struct {
Jobs []map[string]interface{} `json:"jobs"`
}

func eventsMapping(r mb.ReporterV2, content []byte) []error {
func eventsMapping(r mb.ReporterV2, content []byte) error {

jobsData := &jobsStruct{}
err := json.Unmarshal(content, jobsData)
if err != nil {
r.Error(err)
return []error{err}
return err
}

var errs []error
var errs multierror.Errors
for _, job := range jobsData.Jobs {

event := mb.Event{}
Expand All @@ -63,5 +65,5 @@ func eventsMapping(r mb.ReporterV2, content []byte) []error {
event.RootFields.Put("service.name", "elasticsearch")
r.Event(event)
}
return errs
return errs.Err()
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) {

// Not master, no event sent
if !isMaster {
logp.Debug("elasticsearch", "Trying to fetch index summary stats from a none master node.")
logp.Debug("elasticsearch", "Trying to fetch machine learning job stats from a non-master node.")
return
}

Expand All @@ -74,5 +74,9 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) {
return
}

eventsMapping(r, content)
err = eventsMapping(r, content)
if err != nil {
r.Error(err)
return
}
}
3 changes: 2 additions & 1 deletion metricbeat/module/elasticsearch/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def create_ml_job(self):
try:
es.transport.perform_request('POST', "/_xpack/license/start_trial?acknowledge=true")
except:
print "Trial already enabled"
e = sys.exc_info()[0]
print "Trial already enabled. Error: {}".format(e)

# Check if an ml job already exists
response = es.transport.perform_request('GET', "/_xpack/ml/anomaly_detectors/_all/")
Expand Down

0 comments on commit d4edb11

Please sign in to comment.