Skip to content

Commit

Permalink
Add system tests to check document fields for docker module (#2971)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruflin authored and andrewkroh committed Nov 18, 2016
1 parent c9405bb commit 647ed86
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 7 deletions.
6 changes: 0 additions & 6 deletions metricbeat/_meta/kibana/index-pattern/metricbeat.json

This file was deleted.

1 change: 1 addition & 0 deletions metricbeat/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ services:
working_dir: /go/src/github.com/elastic/beats/metricbeat
volumes:
- ${PWD}/..:/go/src/github.com/elastic/beats/
- /var/run/docker.sock:/var/run/docker.sock
command: make
entrypoint: /go/src/github.com/elastic/beats/metricbeat/docker-entrypoint.sh

Expand Down
8 changes: 8 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,14 @@ type: keyword
Container status.
[float]
=== docker.container.socket
type: keyword
Socket path
[float]
== size Fields
Expand Down
5 changes: 5 additions & 0 deletions metricbeat/metricbeat.template-es2x.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@
}
}
},
"socket": {
"ignore_above": 1024,
"index": "not_analyzed",
"type": "string"
},
"status": {
"ignore_above": 1024,
"index": "not_analyzed",
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/metricbeat.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@
}
}
},
"socket": {
"ignore_above": 1024,
"type": "keyword"
},
"status": {
"ignore_above": 1024,
"type": "keyword"
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/module/docker/container/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
type: keyword
description: >
Container status.
- name: socket
type: keyword
description: >
Socket path
- name: size
type: group
description: >
Expand Down
2 changes: 2 additions & 0 deletions metricbeat/module/docker/cpu/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ func eventMapping(stats *CPUStats) common.MapStr {
mb.ModuleData: common.MapStr{
"container": stats.Container.ToMapStr(),
},
// TODO: Does it make sense to have all fields under usage?
"usage": common.MapStr{
// TODO: What to happen with per_cpu -> seperate metricset like core?
"per_cpu": stats.PerCpuUsage,
"total": stats.TotalUsage,
"kernel_mode": stats.UsageInKernelmode,
Expand Down
3 changes: 3 additions & 0 deletions metricbeat/module/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func FetchStats(client *docker.Client) ([]DockerStat, error) {

containersList := []DockerStat{}
for _, container := range containers {
// This is currently very inefficient as docker calculates the average for each request,
// means each request will take at least 2s: https://github.com/docker/docker/blob/master/cli/command/container/stats_helpers.go#L148
// Getting all stats at once is implemented here: https://github.com/docker/docker/pull/25361
containersList = append(containersList, exportContainerStats(client, &container))
}

Expand Down
4 changes: 4 additions & 0 deletions metricbeat/tests/system/config/metricbeat.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ metricbeat.modules:
{% endfor %}
{% endif -%}

{% if m.socket -%}
socket: "{{ m.socket }}"
{% endif -%}

{% if m.username -%}
username: {{ m.username }}
{% endif -%}
Expand Down
176 changes: 176 additions & 0 deletions metricbeat/tests/system/test_docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import metricbeat

import unittest
from nose.plugins.attrib import attr

class Test(metricbeat.BaseTest):

@unittest.skipUnless(metricbeat.INTEGRATION_TESTS, "integration test")
def test_container_fields(self):
"""
test container fields
"""
self.render_config_template(modules=[{
"name": "docker",
"metricsets": ["container"],
"hosts": ["localhost"],
"period": "1s",
"socket": "unix:///var/run/docker.sock",
}])

proc = self.start_beat()
self.wait_until(lambda: self.output_lines() > 0, max_timeout=20)
proc.check_kill_and_wait()

# Ensure no errors or warnings exist in the log.
log = self.get_log()
self.assertNotRegexpMatches(log.replace("WARN EXPERIMENTAL", ""), "ERR|WARN")

output = self.read_output_json()
evt = output[0]

evt = self.remove_labels_and_ports(evt)
self.assert_fields_are_documented(evt)

@unittest.skipUnless(metricbeat.INTEGRATION_TESTS, "integration test")
def test_cpu_fields(self):
"""
test cpu fields
"""
self.render_config_template(modules=[{
"name": "docker",
"metricsets": ["cpu"],
"hosts": ["localhost"],
"period": "1s"
}])

proc = self.start_beat()
self.wait_until(lambda: self.output_lines() > 0, max_timeout=30)
proc.check_kill_and_wait()

# Ensure no errors or warnings exist in the log.
log = self.get_log()
self.assertNotRegexpMatches(log.replace("WARN EXPERIMENTAL", ""), "ERR|WARN")

output = self.read_output_json()
evt = output[0]

evt = self.remove_labels_and_ports(evt)

if 'per_cpu' in evt["docker"]["cpu"]["usage"]:
del evt["docker"]["cpu"]["usage"]["per_cpu"]

self.assert_fields_are_documented(evt)

@unittest.skipUnless(metricbeat.INTEGRATION_TESTS, "integration test")
def test_diskio_fields(self):
"""
test diskio fields
"""
self.render_config_template(modules=[{
"name": "docker",
"metricsets": ["diskio"],
"hosts": ["localhost"],
"period": "1s"
}])

proc = self.start_beat()
self.wait_until(lambda: self.output_lines() > 0, max_timeout=30)
proc.check_kill_and_wait()

# Ensure no errors or warnings exist in the log.
log = self.get_log()
self.assertNotRegexpMatches(log.replace("WARN EXPERIMENTAL", ""), "ERR|WARN")

output = self.read_output_json()
evt = output[0]

evt = self.remove_labels_and_ports(evt)

self.assert_fields_are_documented(evt)

@unittest.skipUnless(metricbeat.INTEGRATION_TESTS, "integration test")
def test_info_fields(self):
"""
test info fields
"""
self.render_config_template(modules=[{
"name": "docker",
"metricsets": ["info"],
"hosts": ["localhost"],
"period": "1s"
}])

proc = self.start_beat()
self.wait_until(lambda: self.output_lines() > 0, max_timeout=30)
proc.check_kill_and_wait()

# Ensure no errors or warnings exist in the log.
log = self.get_log()
self.assertNotRegexpMatches(log.replace("WARN EXPERIMENTAL", ""), "ERR|WARN")

output = self.read_output_json()
evt = output[0]

self.assert_fields_are_documented(evt)

@unittest.skipUnless(metricbeat.INTEGRATION_TESTS, "integration test")
def test_memory_fields(self):
"""
test memory fields
"""
self.render_config_template(modules=[{
"name": "docker",
"metricsets": ["memory"],
"hosts": ["localhost"],
"period": "1s"
}])

proc = self.start_beat()
self.wait_until(lambda: self.output_lines() > 0, max_timeout=30)
proc.check_kill_and_wait()

# Ensure no errors or warnings exist in the log.
log = self.get_log()
self.assertNotRegexpMatches(log.replace("WARN EXPERIMENTAL", ""), "ERR|WARN")

output = self.read_output_json()
evt = output[0]

evt = self.remove_labels_and_ports(evt)
self.assert_fields_are_documented(evt)

@unittest.skipUnless(metricbeat.INTEGRATION_TESTS, "integration test")
def test_network_fields(self):
"""
test info fields
"""
self.render_config_template(modules=[{
"name": "docker",
"metricsets": ["network"],
"hosts": ["localhost"],
"period": "1s"
}])

proc = self.start_beat()
self.wait_until(lambda: self.output_lines() > 0, max_timeout=30)
proc.check_kill_and_wait()

# Ensure no errors or warnings exist in the log.
log = self.get_log()
self.assertNotRegexpMatches(log.replace("WARN EXPERIMENTAL", ""), "ERR|WARN")

output = self.read_output_json()
evt = output[0]

evt = self.remove_labels_and_ports(evt)
self.assert_fields_are_documented(evt)

def remove_labels_and_ports(self, evt):

if 'labels' in evt["docker"]["container"]:
del evt["docker"]["container"]["labels"]
if 'ports' in evt["docker"]["container"]:
del evt["docker"]["container"]["ports"]

return evt
1 change: 0 additions & 1 deletion metricbeat/tests/system/test_haproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def test_info(self):
output = self.read_output_json()
self.assertEqual(len(output), 1)
evt = output[0]
print evt

self.assertItemsEqual(self.de_dot(HAPROXY_FIELDS), evt.keys(), evt)

Expand Down

0 comments on commit 647ed86

Please sign in to comment.