Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
flame-clmc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flame
flame-clmc
Commits
82e239a0
Commit
82e239a0
authored
Mar 6, 2018
by
MJB
Browse files
Options
Downloads
Patches
Plain Diff
updates to telegraf tests to correctly test measurement queries
parent
3fc79692
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/services/pytest/install.sh
+2
-2
2 additions, 2 deletions
test/services/pytest/install.sh
test/telegraf-agents/test_telegraf_agents.py
+57
-11
57 additions, 11 deletions
test/telegraf-agents/test_telegraf_agents.py
with
59 additions
and
13 deletions
test/services/pytest/install.sh
+
2
−
2
View file @
82e239a0
...
...
@@ -24,6 +24,6 @@
#//
#/////////////////////////////////////////////////////////////////////////
apt-get update
apt-get
install
python3 python3-pip
apt-get
install
python3 python3-pip
python-influxdb
update-alternatives
--install
/usr/bin/python python /usr/bin/python3 10
pip
install
pytest pyyaml
This diff is collapsed.
Click to expand it.
test/telegraf-agents/test_telegraf_agents.py
+
57
−
11
View file @
82e239a0
#!/usr/bin/python3
import
sys
if
sys
.
version_info
[
0
]
<
3
:
...
...
@@ -7,6 +6,7 @@ if sys.version_info[0] < 3:
import
pytest
import
os
import
json
from
urllib.parse
import
urlencode
from
urllib.request
import
Request
,
urlopen
from
os.path
import
join
,
dirname
...
...
@@ -27,16 +27,61 @@ def test_ping(telegraf_agent_config):
response
=
os
.
system
(
"
ping -c 1
"
+
x
[
'
ip_address
'
])
assert
response
==
0
,
"
Could not ping
"
+
x
[
'
name
'
]
+
"
on ip address
"
+
x
[
'
ip_address
'
]
@pytest.mark.parametrize
(
"
queries
"
,
[{
'
nginx
'
:
{
'
measurement
'
:
'
nginx
'
,
'
query
'
:
'
SELECT mean(
"
requests
"
) AS
"
mean_active
"
FROM
"
CLMCMetrics
"
.
"
autogen
"
.
"
nginx
"'
,
'
result
'
:
'
1
'
}}])
def
test_nginx
(
telegraf_agent_config
,
queries
):
@pytest.mark.parametrize
(
"
query
"
,
[{
'
measurement
'
:
'
nginx
'
,
'
query
'
:
'
SELECT mean(
"
requests
"
) AS
"
mean_active
"
FROM
"
CLMCMetrics
"
.
"
autogen
"
.
"
nginx
"'
,
'
expected_result
'
:
'
0
'
},
{
'
measurement
'
:
'
cpu
'
,
'
query
'
:
'
SELECT mean(
"
usage_idle
"
) AS
"
mean_usage_idle
"
FROM
"
CLMCMetrics
"
.
"
autogen
"
.
"
cpu
"'
,
'
expected_result
'
:
'
0
'
},
{
'
measurement
'
:
'
mongodb
'
,
'
query
'
:
'
SELECT mean(
"
net_in_bytes
"
) AS
"
mean_net_in_bytes
"
FROM
"
CLMCMetrics
"
.
"
autogen
"
.
"
mongodb
"'
,
'
expected_result
'
:
'
0
'
},
])
def
test_all_inputs
(
telegraf_agent_config
,
query
):
"""
Tests measurements are received from an input plugin aggregated across all services
Arguments:
telegraf_agent_config {Structure according to rspec.yml format} -- The resource specification for the services under test
query {test to run} -- a mean query run against a specific measurement value with an expected minimum mean result value
"""
influxdb_url
=
"
http://
"
+
telegraf_agent_config
[
'
hosts
'
][
0
][
'
ip_address
'
]
+
"
:8086
"
measurements
=
send_query
(
influxdb_url
,
'
SHOW measurements ON
"
CLMCMetrics
"'
)
assert
measurements
is
not
None
,
"
Show measurements returned no results
"
l_value
=
[
query
[
'
measurement
'
]]
assert
l_value
in
measurements
[
'
results
'
][
0
][
'
series
'
][
0
][
'
values
'
],
"
{0} not in measurement list
"
.
format
(
query
[
'
measurement
'
])
measurement_result
=
send_query
(
influxdb_url
,
query
[
'
query
'
])
actual_result
=
int
(
measurement_result
[
'
results
'
][
0
][
'
series
'
][
0
][
'
values
'
][
0
][
1
])
assert
actual_result
>
int
(
query
[
'
expected_result
'
]),
"
actual result {0} is not > expected result {1} for query {2}
"
.
format
(
actual_result
,
query
[
'
expected_result
'
],
query
[
'
query
'
])
@pytest.mark.parametrize
(
"
service
"
,
[{
'
ipendpoint
'
:
'
id
'
,
'
measurements
'
:
[{
'
measurement
'
:
'
cpu
'
,
'
query
'
:
'
query
'
,
'
result
'
:
'
result
'
}
,
{
'
measurement
'
:
'
nginx
'
,
'
query
'
:
'
query
'
,
'
result
'
:
'
result
'
},
{
'
measurement
'
:
'
mongo
'
,
'
query
'
:
'
query
'
,
'
result
'
:
'
result
'
}]},
{
'
ipendpoint
'
:
'
id
'
,
'
measurements
'
:
[{
'
measurement
'
:
'
cpu
'
,
'
query
'
:
'
query
'
,
'
result
'
:
'
result
'
}
,
{
'
nmeasurementme
'
:
'
nginx
'
,
'
query
'
:
'
query
'
,
'
result
'
:
'
result
'
}]}
])
def
test_multiple_inputs_on_a_service
(
telegraf_agent_config
,
service
):
"""
This test checks that a service configured with multiple input plugins as separate telegraf config files generates measurements in the database
Arguments:
telegraf_agent_config {[type]} -- The resource specification for the services under test
service {[type]} -- Includes the IP endpoint configured with multiple inputs, and a list of queries for each measurement generated by the inputs
"""
# for each item in the measurement list run the query and test the result
assert
1
@pytest.mark.parametrize
(
"
query
"
,
[{
'
query
'
:
'
filter query
'
,
'
expected_result
'
:
'
0
'
},
{
'
query
'
:
'
filter query
'
,
'
expected_result
'
:
'
0
'
},
{
'
query
'
:
'
filter query
'
,
'
expected_result
'
:
'
0
'
},
])
def
test_global_tag_filtering
(
telegraf_agent_config
,
query
):
"""
Tests that the global tags are inserted correctly into the global configuration using the install CLMC script
Arguments:
telegraf_agent_config {[type]} -- [description]
"""
measurements
=
send_query
(
"
http://localhost:8086
"
,
'
SHOW measurements ON
"
CLMCMetrics
"'
)
assert
queries
[
'
nginx
'
][
'
measurement
'
]
in
measurements
,
"
Measurement
"
+
measurement
+
"
not in the CLMCMetrics database
"
# run query
# check result
result
=
send_query
(
"
http://localhost:8086
"
,
queries
[
'
nginx
'
][
'
query
'
])
print
(
"
result
"
+
result
)
# assert results is correct
assert
1
def
send_query
(
url
,
query
):
"""
...
...
@@ -44,10 +89,11 @@ def send_query(url, query):
:param url: the target url to which the query is sent to - a string containing a valid URL address
:param query: the query to be executed on the given URL
:return: the result of the executed query
:return: the result of the executed query
as a python data structure
"""
query
=
urlencode
({
"
q
"
:
query
}).
encode
(
"
ascii
"
)
request
=
Request
(
"
{0}/query
"
.
format
(
url
),
query
)
result
=
urlopen
(
request
)
return
result
.
read
().
decode
(
"
utf-8
"
).
strip
()
json_string
=
result
.
read
().
decode
(
"
utf-8
"
).
strip
()
return
json
.
loads
(
json_string
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment