-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix mapping and race condition in sql module (#15738)
Mapping was defined at the metricset level, but it should be defined at the module level. Add system test to earlier detect this kind of issues. Also add validation so driver and sql_query options cannot be empty. Fetch was reusing some maps when building the event, what was causing mixed data in events and panics on queries with lots of rows. Fixes #15736
- Loading branch information
Showing
6 changed files
with
86 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1 @@ | ||
- name: query | ||
type: group | ||
release: beta | ||
description: > | ||
query | ||
fields: | ||
- name: driver | ||
type: keyword | ||
description: > | ||
Driver used to execute the query. | ||
- name: query | ||
type: keyword | ||
description: > | ||
Query executed to collect metrics. | ||
- name: metrics.numeric.* | ||
type: object | ||
object_type: double | ||
description: > | ||
Numeric metrics collected. | ||
- name: metrics.string.* | ||
type: object | ||
object_type: keyword | ||
description: > | ||
Non-numeric values collected. | ||
- release: beta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
import sys | ||
import unittest | ||
|
||
sys.path.append(os.path.join(os.path.dirname(__file__), '../../tests/system')) | ||
from xpack_metricbeat import XPackTest, metricbeat | ||
|
||
|
||
class Test(XPackTest): | ||
|
||
COMPOSE_SERVICES = ['mysql'] | ||
|
||
@unittest.skipUnless(metricbeat.INTEGRATION_TESTS, "integration test") | ||
def test_query(self): | ||
""" | ||
sql custom query test | ||
""" | ||
self.render_config_template(modules=[{ | ||
"name": "sql", | ||
"metricsets": ["query"], | ||
"hosts": self.get_hosts(), | ||
"period": "5s", | ||
"additional_content": """ | ||
driver: mysql | ||
sql_query: 'select table_schema, table_name, engine, table_rows from information_schema.tables where table_rows > 0'""" | ||
}]) | ||
proc = self.start_beat(home=self.beat_path) | ||
self.wait_until(lambda: self.output_lines() > 0) | ||
proc.check_kill_and_wait() | ||
self.assert_no_logged_warnings() | ||
|
||
output = self.read_output_json() | ||
self.assertGreater(len(output), 0) | ||
|
||
for evt in output: | ||
self.assert_fields_are_documented(evt) | ||
self.assertIn("sql", evt.keys(), evt) | ||
self.assertIn("query", evt["sql"].keys(), evt) | ||
|
||
def get_hosts(self): | ||
return ['root:test@tcp({})/'.format(self.compose_host())] |