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

Adding beat module with state metricset #12615

Merged
merged 49 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
417805d
Renaming anchor for beats common fields
ycombinator Jun 20, 2019
62a719d
Removing extraneous file accidentally checked in
ycombinator Jun 20, 2019
eab26fe
Adding beats module with stats metricset
ycombinator May 13, 2019
8ca2c09
Rename argument for clarity
ycombinator May 20, 2019
8ccfeee
Adding tests
ycombinator May 20, 2019
237867e
Adding tests + sample data
ycombinator Jun 17, 2019
7d7bce0
Removing debugging statements
ycombinator Jun 17, 2019
039d633
Regenerating data.json file
ycombinator Jun 17, 2019
fadc626
Trying a different host name
ycombinator Jun 18, 2019
177931f
Stubbing out xpack code path
ycombinator Jun 18, 2019
53df00e
Fixing service name in system test
ycombinator Jun 18, 2019
b3317dc
Fleshing out TODOs
ycombinator Jun 18, 2019
7e94594
Fixing index name
ycombinator Jun 18, 2019
83e336e
Renaming module name from beats to beat
ycombinator Jun 19, 2019
9406d7a
Regenerating data.json file
ycombinator Jun 19, 2019
ac0ed93
Update metricbeat/module/beat/_meta/config.reference.yml
ycombinator Jun 19, 2019
f4215a6
Update metricbeat/module/beat/_meta/config-xpack.yml
ycombinator Jun 19, 2019
d9183d1
Update metricbeat/module/beat/_meta/config.yml
ycombinator Jun 19, 2019
cd1a045
Update metricbeat/modules.d/beat-xpack.yml.disabled
ycombinator Jun 19, 2019
e44bb9f
Update metricbeat/modules.d/beat.yml.disabled
ycombinator Jun 19, 2019
7ad570a
Renaming system test
ycombinator Jun 19, 2019
e2171e8
Trying to use the new testdata framework
ycombinator Jun 19, 2019
fb92606
Renaming service to avoid naming collision
ycombinator Jun 19, 2019
a88d84c
Adding back data_test.go
ycombinator Jun 19, 2019
3f13074
Fixing HTTP server hostname
ycombinator Jun 19, 2019
306c6b3
Trying localhost
ycombinator Jun 19, 2019
f6faddd
Fixing inconsistencies
ycombinator Jun 19, 2019
2ee1068
Fixing typo
ycombinator Jun 19, 2019
dc2ab19
Make runtime optional as it is absent in older versions of Beats
ycombinator Jun 19, 2019
8accb48
Renaming anchor for beats common fields
ycombinator Jun 20, 2019
f620dcc
Adding beats module with stats metricset
ycombinator May 13, 2019
5401f0d
Renaming module name from beats to beat
ycombinator Jun 19, 2019
801f921
Adding beat/state metricset
ycombinator Jun 19, 2019
d079df4
Adding data_test.go
ycombinator Jun 19, 2019
abd1251
Rebase misses
ycombinator Jun 20, 2019
040b1d2
Removing files accidentally checked in
ycombinator Jun 21, 2019
7731dc3
Regenerating docs
ycombinator Jun 21, 2019
b4b10a0
Adding CHANGELOG entry
ycombinator Jun 21, 2019
b8e66ee
Regenerating docs
ycombinator Jun 21, 2019
69c1128
Removing extraneous file
ycombinator Jun 22, 2019
3414443
Undoing accidental change during rebase
ycombinator Jun 22, 2019
2cd63dd
Adding state metricset to integration test
ycombinator Jun 22, 2019
d7f1336
Removing files since new testdata framework cannot be used yet
ycombinator Jun 23, 2019
bc7c697
Fixing data type
ycombinator Jun 23, 2019
5cc275c
Regenerating generated files
ycombinator Jun 23, 2019
14e182b
Updating system test to include state metricset
ycombinator Jun 23, 2019
ebeb11f
Fixing datatype (again!)
ycombinator Jun 23, 2019
64eff0c
Correctly set service fields
ycombinator Jun 24, 2019
30e9289
Merge branch 'master' into mb-beat-state
ycombinator Jun 24, 2019
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 @@ -238,6 +238,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add a system/entropy metricset {pull}12450[12450]
- Allow redis URL format in redis hosts config. {pull}12408[12408]
- Add tags into ec2 metricset. {issue}[12263]12263 {pull}12372[12372]
- Add `beat` module. {pull}12181[12181] {pull}12615[12615]
- Collect tags for cloudwatch metricset in aws module. {issue}[12263]12263 {pull}12480[12480]

*Packetbeat*
Expand Down
47 changes: 47 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,53 @@ type: keyword
Beat type.


type: keyword

--

[float]
=== state

Beat state



*`beat.state.management.enabled`*::
+
--
Is central management enabled?


type: boolean

--

*`beat.state.module.count`*::
+
--
Number of modules enabled


type: integer

--

*`beat.state.output.name`*::
+
--
Name of output used by Beat


type: keyword

--

*`beat.state.queue.name`*::
+
--
Name of queue being used by Beat


type: keyword

--
Expand Down
1 change: 1 addition & 0 deletions metricbeat/include/list.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ metricbeat.modules:
- module: beat
metricsets:
- stats
- state
period: 10s
hosts: ["http://localhost:5066"]
#ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/beat/_meta/config-xpack.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- module: beat
metricsets:
- stats
- state
period: 10s
hosts: ["http://localhost:5066"]
#username: "user"
Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/beat/_meta/config.reference.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- module: beat
metricsets:
- stats
- state
period: 10s
hosts: ["http://localhost:5066"]
#ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/beat/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- module: beat
metricsets:
- stats
- state
period: 10s
hosts: ["http://localhost:5066"]

2 changes: 2 additions & 0 deletions metricbeat/module/beat/beat_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ import (
"github.com/elastic/beats/libbeat/tests/compose"
mbtest "github.com/elastic/beats/metricbeat/mb/testing"
"github.com/elastic/beats/metricbeat/module/beat"
_ "github.com/elastic/beats/metricbeat/module/beat/state"
_ "github.com/elastic/beats/metricbeat/module/beat/stats"
)

var metricSets = []string{
"stats",
"state",
}

func TestFetch(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/beat/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions metricbeat/module/beat/state/_meta/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"@timestamp": "2017-10-12T08:05:34.853Z",
"beat": {
"state": {
"management": {
"enabled": false
},
"module": {
"count": 3
},
"output": {
"name": "elasticsearch"
},
"queue": {
"name": "mem"
}
}
},
"event": {
"dataset": "beat.state",
"duration": 115000,
"module": "beat"
},
"metricset": {
"name": "state"
},
"service": {
"address": "127.0.0.1:5066",
"id": "1f0c187b-f2ef-4950-b9cc-dd6864b9191a",
"name": "Shaunaks-MacBook-Pro-2.local",
"type": "metricbeat"
}
}
22 changes: 22 additions & 0 deletions metricbeat/module/beat/state/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- name: state
type: group
description: >
Beat state
release: ga
fields:
- name: management.enabled
type: boolean
description: >
Is central management enabled?
- name: module.count
type: integer
description: >
Number of modules enabled
- name: output.name
type: keyword
description: >
Name of output used by Beat
- name: queue.name
type: keyword
description: >
Name of queue being used by Beat
43 changes: 43 additions & 0 deletions metricbeat/module/beat/state/_meta/test/state.800.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"beat": {
"name": "Shaunaks-MBP-2"
},
"host": {
"architecture": "x86_64",
"hostname": "Shaunaks-MBP-2",
"id": "EF6274EA-462F-5316-A14A-850E7BFD8126",
"os": {
"build": "18F132",
"family": "darwin",
"kernel": "18.6.0",
"name": "Mac OS X",
"platform": "darwin",
"version": "10.14.5"
}
},
"management": {
"enabled": false
},
"module": {
"count": 3,
"names": [
"system"
]
},
"output": {
"name": "elasticsearch"
},
"outputs": {
"elasticsearch": {
"cluster_uuid": "c8sjZYNjRcOiCTGzQZoyqw"
}
},
"queue": {
"name": "mem"
},
"service": {
"id": "1f0c187b-f2ef-4950-b9cc-dd6864b9191a",
"name": "metricbeat",
"version": "8.0.0"
}
}
72 changes: 72 additions & 0 deletions metricbeat/module/beat/state/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package state

import (
"encoding/json"

"github.com/pkg/errors"

"github.com/elastic/beats/libbeat/common"
s "github.com/elastic/beats/libbeat/common/schema"
c "github.com/elastic/beats/libbeat/common/schema/mapstriface"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/module/beat"
)

var (
schema = s.Schema{
"management": c.Dict("management", s.Schema{
"enabled": c.Bool("enabled"),
}),
"module": c.Dict("module", s.Schema{
"count": c.Int("count"),
}),
"output": c.Dict("output", s.Schema{
"name": c.Str("name"),
}),
"queue": c.Dict("queue", s.Schema{
"name": c.Str("name"),
}),
}
)

func eventMapping(r mb.ReporterV2, info beat.Info, content []byte) error {
var event mb.Event
event.RootFields = common.MapStr{}
event.RootFields.Put("service", common.MapStr{
"id": info.UUID,
"name": info.Name,
})

event.Service = info.Beat

var data map[string]interface{}
err := json.Unmarshal(content, &data)
if err != nil {
return errors.Wrap(err, "failure parsing Beat's State API response")
}

event.MetricSetFields, err = schema.Apply(data)
if err != nil {
return errors.Wrap(err, "failure to apply state schema")
}

r.Event(event)
return nil
}
55 changes: 55 additions & 0 deletions metricbeat/module/beat/state/data_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

// +build !integration

package state

import (
"io/ioutil"
"path/filepath"
"testing"

"github.com/elastic/beats/metricbeat/module/beat"

mbtest "github.com/elastic/beats/metricbeat/mb/testing"

"github.com/stretchr/testify/assert"
)

func TestEventMapping(t *testing.T) {

files, err := filepath.Glob("./_meta/test/state.*.json")
assert.NoError(t, err)

info := beat.Info{
UUID: "1234",
Beat: "helloworld",
}

for _, f := range files {
input, err := ioutil.ReadFile(f)
assert.NoError(t, err)

reporter := &mbtest.CapturingReporterV2{}
err = eventMapping(reporter, info, input)

assert.NoError(t, err, f)
assert.True(t, len(reporter.GetEvents()) >= 1, f)
assert.Equal(t, 0, len(reporter.GetErrors()), f)
}
}
Loading