-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[etcd] add test, metrics and service checks
Copied from the apache/riackcs tests, using the AgentCheckTest.
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 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
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,63 @@ | ||
require './ci/common' | ||
|
||
def etcd_version | ||
ENV['ETCD_VERSION'] || '2.0.3' | ||
end | ||
|
||
def etcd_rootdir | ||
"#{ENV['INTEGRATIONS_DIR']}/etcd_#{etcd_version}" | ||
end | ||
|
||
namespace :ci do | ||
namespace :etcd do |flavor| | ||
task :before_install => ['ci:common:before_install'] | ||
|
||
task :install => ['ci:common:install'] do | ||
unless Dir.exist? File.expand_path(etcd_rootdir) | ||
sh %(curl -s -L -o $VOLATILE_DIR/etcd.tar.gz\ | ||
https://github.com/coreos/etcd/releases/download/v#{etcd_version}/etcd-v#{etcd_version}-linux-amd64.tar.gz) | ||
sh %(mkdir -p #{etcd_rootdir}) | ||
sh %(tar xzvf $VOLATILE_DIR/etcd.tar.gz\ | ||
-C #{etcd_rootdir}\ | ||
--strip-components=1 >/dev/null) | ||
end | ||
end | ||
|
||
task :before_script => ['ci:common:before_script'] do | ||
sh %(cd $VOLATILE_DIR && #{etcd_rootdir}/etcd >/dev/null &) | ||
sleep_for 10 | ||
end | ||
|
||
task :script => ['ci:common:script'] do | ||
this_provides = [ | ||
'etcd' | ||
] | ||
Rake::Task['ci:common:run_tests'].invoke(this_provides) | ||
end | ||
|
||
task :cleanup => ['ci:common:cleanup'] do | ||
# This will delete the temp directory of etcd, | ||
# so the etcd process will kill himself quickly after that (<10s) | ||
sh %(rm -rf $VOLATILE_DIR/*etcd*) | ||
end | ||
|
||
task :execute do | ||
exception = nil | ||
begin | ||
%w(before_install install before_script script).each do |t| | ||
Rake::Task["#{flavor.scope.path}:#{t}"].invoke | ||
end | ||
rescue => e | ||
exception = e | ||
puts "Failed task: #{e.class} #{e.message}".red | ||
end | ||
if ENV['SKIP_CLEANUP'] | ||
puts 'Skipping cleanup, disposable environments are great'.yellow | ||
else | ||
puts 'Cleaning up' | ||
Rake::Task["#{flavor.scope.path}:cleanup"].invoke | ||
end | ||
fail exception if exception | ||
end | ||
end | ||
end |
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,43 @@ | ||
import unittest | ||
from tests.common import AgentCheckTest | ||
from nose.plugins.attrib import attr | ||
from time import sleep | ||
from checks import AgentCheck | ||
from requests.exceptions import Timeout | ||
|
||
@attr(requires='etcd') | ||
class EtcdTest(AgentCheckTest): | ||
|
||
CHECK_NAME = "etcd" | ||
def __init__(self, *args, **kwargs): | ||
AgentCheckTest.__init__(self, *args, **kwargs) | ||
self.config = {"instances": [{"url": "http://localhost:4001"}]} | ||
|
||
def test_metrics(self): | ||
self.run_check(self.config) | ||
sleep(1) | ||
self.run_check(self.config) | ||
tags = ['url:http://localhost:4001', 'etcd_state:leader'] | ||
self.assertMetric('etcd.store.gets.success', metric_value=0.0, tags=tags) | ||
self.assertMetric('etcd.store.gets.fail', metric_value=0.0, tags=tags) | ||
self.assertMetric('etcd.self.send.appendrequest.count', metric_value=0.0, tags=tags) | ||
|
||
|
||
def test_service_checks(self): | ||
self.run_check(self.config) | ||
|
||
self.assertEqual(len(self.service_checks), 1, self.service_checks) | ||
sc = self.service_checks[0] | ||
self.assertEquals(sc["check"], self.check.SERVICE_CHECK_NAME, sc["check"]) | ||
self.assertEquals(sc["status"], AgentCheck.OK, sc["status"]) | ||
self.assertEquals(sc["tags"], ['url:http://localhost:4001', 'etcd_state:leader'], sc["tags"]) | ||
|
||
def test_bad_config(self): | ||
self.assertRaises(Exception, | ||
lambda: self.run_check({"instances": [{"url": "http://localhost:4001/test"}]})) | ||
service_checks = self.check.get_service_checks() | ||
self.assertEqual(len(service_checks), 1, service_checks) | ||
sc = service_checks[0] | ||
self.assertEquals(sc["check"], self.check.SERVICE_CHECK_NAME, sc["check"]) | ||
self.assertEquals(sc["status"], AgentCheck.CRITICAL, sc["status"]) | ||
self.assertEquals(sc["tags"], ['url:http://localhost:4001/test/v2/stats/self'], sc["tags"]) |