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

Read build args for metricbeat system tests from file #14520

Merged
merged 8 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ The list below covers the major changes between 7.0.0-rc2 and master only.
- Strip debug symbols from binaries to reduce binary sizes. {issue}12768[12768]
- Compare event by event in `testadata` framework to avoid sorting problems {pull}13747[13747]
- Added a `default_field` option to fields in fields.yml to offer a way to exclude fields from the default_field list. {issue}14262[14262] {pull}14341[14341]
- `supported-versions.txt` can be used in metricbeat python system tests to obtain the build args for docker compose builds. {pull}14520[14520]
jsoriano marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion libbeat/tests/system/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ termcolor==1.1.0
texttable==0.9.1
urllib3==1.24.2
websocket-client==0.47.0
parameterized==0.6.1
parameterized==0.7.0
jsondiff==1.1.2
semver==2.8.1
9 changes: 0 additions & 9 deletions metricbeat/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,6 @@ services:
ports:
- 4949

mysql:
image: docker.elastic.co/observability-ci/beats-integration-mysql:${MYSQL_VARIANT:-mysql}-${MYSQL_VERSION:-5.7.12}-1
build:
context: ./module/mysql/_meta
args:
MYSQL_IMAGE: ${MYSQL_VARIANT:-mysql}:${MYSQL_VERSION:-5.7.12}
ports:
- 3306

nats:
image: docker.elastic.co/observability-ci/beats-integration-nats:${NATS_VERSION:-2.0.4}-1
build:
Expand Down
3 changes: 3 additions & 0 deletions metricbeat/module/apache/supported-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variants:
- APACHE_VERSION: 2.4.12
- APACHE_VERSION: 2.4.20
33 changes: 18 additions & 15 deletions metricbeat/module/apache/test_apache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from nose.plugins.attrib import attr
import urllib2
import time
import semver
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), '../../tests/system'))
Expand All @@ -29,7 +30,7 @@
"load", "user", "system", "children_user", "children_system"
]


@metricbeat.parameterized_with_supported_versions
class ApacheStatusTest(metricbeat.BaseTest):

COMPOSE_SERVICES = ['apache']
Expand Down Expand Up @@ -74,22 +75,24 @@ def test_output(self):
def verify_fields(self, evt):
self.assertItemsEqual(self.de_dot(APACHE_FIELDS), evt.keys())
apache_status = evt["apache"]["status"]
self.assertItemsEqual(
self.de_dot(APACHE_STATUS_FIELDS), apache_status.keys())
self.assertItemsEqual(
self.de_dot(CPU_FIELDS), apache_status["cpu"].keys())
# There are more fields that could be checked.
if self.old_apache_version():
self.assertItemsEqual(
self.de_dot(APACHE_OLD_STATUS_FIELDS), apache_status.keys())
else:
self.assertItemsEqual(
self.de_dot(APACHE_STATUS_FIELDS), apache_status.keys())
self.assertItemsEqual(
self.de_dot(CPU_FIELDS), apache_status["cpu"].keys())
# There are more fields that could be checked.

def get_hosts(self):
return ['http://' + self.compose_host()]

def old_apache_version(self):
if not 'APACHE_VERSION' in self.COMPOSE_ENV:
return False

class ApacheOldStatusTest(ApacheStatusTest):
version = self.COMPOSE_ENV['APACHE_VERSION']
return semver.compare(version, '2.4.12') <= 0

COMPOSE_ENV = {'APACHE_VERSION': '2.4.12'}

def verify_fields(self, evt):
self.assertItemsEqual(self.de_dot(APACHE_FIELDS), evt.keys())
apache_status = evt["apache"]["status"]
self.assertItemsEqual(
self.de_dot(APACHE_OLD_STATUS_FIELDS), apache_status.keys())
def get_hosts(self):
return ['http://' + self.compose_host()]
11 changes: 11 additions & 0 deletions metricbeat/module/mysql/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '2.3'

services:
mysql:
image: docker.elastic.co/observability-ci/beats-integration-mysql:${MYSQL_VARIANT:-mysql}-${MYSQL_VERSION:-5.7.12}-1
build:
context: ./_meta
args:
MYSQL_IMAGE: ${MYSQL_VARIANT:-mysql}:${MYSQL_VERSION:-5.7.12}
ports:
- 3306
8 changes: 8 additions & 0 deletions metricbeat/module/mysql/supported-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
variants:
- {'MYSQL_VARIANT': 'mysql', 'MYSQL_VERSION': '5.7.12'}
- {'MYSQL_VARIANT': 'mysql', 'MYSQL_VERSION': '8.0.13'}
- {'MYSQL_VARIANT': 'percona', 'MYSQL_VERSION': '5.7.24'}
- {'MYSQL_VARIANT': 'percona', 'MYSQL_VERSION': '8.0.13-4'}
- {'MYSQL_VARIANT': 'mariadb', 'MYSQL_VERSION': '10.2.23'}
- {'MYSQL_VARIANT': 'mariadb', 'MYSQL_VERSION': '10.3.14'}
- {'MYSQL_VARIANT': 'mariadb', 'MYSQL_VERSION': '10.4.4'}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdelapenya when we agree on the format and location of this file I will open this for review.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved these files to the _meta directory of each module as in #14355.

Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import os
import metricbeat
import sys
import unittest
from nose.plugins.attrib import attr

sys.path.append(os.path.join(os.path.dirname(__file__), '../../tests/system'))
import metricbeat

MYSQL_FIELDS = metricbeat.COMMON_FIELDS + ["mysql"]

MYSQL_STATUS_FIELDS = ["clients", "cluster", "cpu", "keyspace", "memory",
"persistence", "replication", "server", "stats"]


@metricbeat.parameterized_with_supported_versions
class Test(metricbeat.BaseTest):

COMPOSE_SERVICES = ['mysql']
Expand Down Expand Up @@ -44,45 +48,3 @@ def test_status(self):

def get_hosts(self):
return ['root:test@tcp({})/'.format(self.compose_host())]


class TestMysql80(Test):
COMPOSE_ENV = {
'MYSQL_VARIANT': 'mysql',
'MYSQL_VERSION': '8.0.13',
}


class TestPercona57(Test):
COMPOSE_ENV = {
'MYSQL_VARIANT': 'percona',
'MYSQL_VERSION': '5.7.24',
}


class TestPercona80(Test):
COMPOSE_ENV = {
'MYSQL_VARIANT': 'percona',
'MYSQL_VERSION': '8.0.13-4',
}


class TestMariadb102(Test):
COMPOSE_ENV = {
'MYSQL_VARIANT': 'mariadb',
'MYSQL_VERSION': '10.2.23',
}


class TestMariadb103(Test):
COMPOSE_ENV = {
'MYSQL_VARIANT': 'mariadb',
'MYSQL_VERSION': '10.3.14',
}


class TestMariadb104(Test):
COMPOSE_ENV = {
'MYSQL_VARIANT': 'mariadb',
'MYSQL_VERSION': '10.4.4',
}
33 changes: 33 additions & 0 deletions metricbeat/tests/system/metricbeat.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import re
import sys
import os
import yaml

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../libbeat/tests/system')))

from beat.beat import TestCase
from parameterized import parameterized_class

COMMON_FIELDS = ["@timestamp", "agent", "metricset.name", "metricset.host",
"metricset.module", "metricset.rtt", "host.name", "service.name", "event", "ecs"]
Expand Down Expand Up @@ -105,3 +107,34 @@ def check_metricset(self, module, metricset, hosts, fields=[], extras=[]):
self.assertItemsEqual(self.de_dot(fields), evt.keys())

self.assert_fields_are_documented(evt)


def supported_versions(path):
"""
Returns variants information as expected by parameterized_class,
that is as a list of lists with an only element that is used to
override the value of COMPOSE_ENV.
"""
if not os.path.exists(path):
# Return an empty variant so a class is instantiated with defaults
return [[{}]]

variants = [[{}]]
with open(path) as f:
versions_info = yaml.safe_load(f)

for variant in versions_info['variants']:
variants += [[variant]]

return variants

def parameterized_with_supported_versions(base_class):
"""
Decorates a class so instead of the base class, multiple copies
of it are registered, one for each supported version.
"""
class_dir = os.path.abspath(os.path.dirname(sys.modules[base_class.__module__].__file__))
versions_path = os.path.join(class_dir, 'supported-versions.yml')
variants = supported_versions(versions_path)
decorator = parameterized_class(['COMPOSE_ENV'], variants)
decorator(base_class)