forked from uber-archive/statsrelay
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
accurate .upper and .lower value for high frequency timers (#22)
/cc @theatrus
- Loading branch information
1 parent
37eac7a
commit 4e8201f
Showing
5 changed files
with
133 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -382,4 +382,3 @@ int hashmap_iter(hashmap *map, hashmap_callback cb, void *data) { | |
} | ||
return should_break; | ||
} | ||
|
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 |
---|---|---|
|
@@ -18,8 +18,20 @@ const char* t3n = "foo"; | |
|
||
static void print_callback(void* data, const char* key, const char* line, int len) { | ||
char* expect = (char*)data; | ||
stats_log(" Expect: %s Got: %s \n", expect, line); | ||
assert(strcmp(line, expect) == 0); | ||
char* buffer = (char*)malloc(strlen(line) * sizeof(char) + 1); | ||
|
||
strcpy(buffer, line); | ||
buffer[strlen(line)] = '\0'; | ||
|
||
stats_log("Expect: %s Got: %s\n", expect, line); | ||
/** | ||
* Since we flush upper and lower values | ||
* on every flush, while sampling | ||
* we need to check for both values | ||
*/ | ||
buffer[strcspn(buffer, "\n")] = 0; | ||
assert(strstr(expect, buffer) != NULL); | ||
free(buffer); | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
|
@@ -52,13 +64,13 @@ int main(int argc, char** argv) { | |
/* Feed another value, make sure we are now in sampling mode */ | ||
assert(sampler_consider_timer(sampler, t1n, &t1_res) == SAMPLER_SAMPLING); | ||
|
||
/* Feed t2, to check that its not sampled */ | ||
// Feed t2, to check that its not sampled | ||
assert(sampler_consider_metric(sampler, t2n, &t2_res) == SAMPLER_NOT_SAMPLING); | ||
|
||
/* Feed another value, make sure we are now in sampling mode */ | ||
assert(sampler_consider_timer(sampler, t1n, &t1_res) == SAMPLER_SAMPLING); | ||
|
||
sampler_flush(sampler, print_callback, "differing_geohash_query:77923.2|ms@1\n"); | ||
sampler_flush(sampler, print_callback, "differing_geohash_query:77923.2|ms@1.0\n"); | ||
|
||
/* This update should not sampled */ | ||
assert(sampler_consider_timer(sampler, t1n, &t1_res) == SAMPLER_NOT_SAMPLING); | ||
|
@@ -75,7 +87,7 @@ int main(int argc, char** argv) { | |
assert(sampler_consider_timer(sampler, t1n, &t1_res) == SAMPLER_SAMPLING); | ||
} | ||
|
||
sampler_flush(sampler, print_callback, "differing_geohash_query:77923.2|ms@0.001\n"); | ||
sampler_flush(sampler, print_callback, "differing_geohash_query:77923.2|ms@1.0\ndiffering_geohash_query:77923.2|[email protected]\n"); | ||
|
||
/* foo should still be sampling (it does so across two periods) - lets check */ | ||
assert(sampler_is_sampling(sampler, t1n, METRIC_TIMER) == SAMPLER_SAMPLING); | ||
|
@@ -89,7 +101,7 @@ int main(int argc, char** argv) { | |
assert(sampler_consider_timer(sampler, t3n, &t3_res) == SAMPLER_SAMPLING); | ||
} | ||
|
||
sampler_flush(sampler, print_callback, "foo:12|ms@0.0002\n"); | ||
sampler_flush(sampler, print_callback, "foo:12|ms@0.2\nfoo:12|[email protected]\n"); | ||
|
||
/* foo should now should still be sampling */ | ||
assert(sampler_is_sampling(sampler, t3n, METRIC_TIMER) == SAMPLER_SAMPLING); | ||
|
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 |
---|---|---|
|
@@ -56,6 +56,11 @@ def check_recv_in(self, fd, subset, size=512): | |
bytes_read = fd.recv(size) | ||
self.assertIn(subset, bytes_read) | ||
|
||
def check_list_in_recv(self, fd, subset=list(), size=512): | ||
bytes_read = fd.recv(size) | ||
for line in subset: | ||
self.assertIn(line, bytes_read) | ||
|
||
def recv_status(self, fd): | ||
return fd.recv(65536) | ||
|
||
|
@@ -208,22 +213,44 @@ def test_tcp_with_timer_sampler(self): | |
fd, addr = self.statsd_listener.accept() | ||
sender = self.connect('tcp', self.bind_statsd_port) | ||
for i in range(0, 5): | ||
sender.sendall('test.srv.req:1|ms\n') | ||
expected = 'test-1.test.srv.req.suffix:1|ms\n' | ||
sender.sendall('test.srv.req:1.0|ms\n') | ||
expected = 'test-1.test.srv.req.suffix:1.0|ms\n' | ||
self.check_recv(fd, expected, len(expected)) | ||
|
||
# We should now be in sampling mode | ||
for i in range(0, 200): | ||
sender.sendall('test.srv.req:1|ms\n') | ||
sender.sendall('test.srv.req:1|ms|@0.2\n') | ||
|
||
time.sleep(4.0) | ||
self.check_recv_in(fd, 'test-1.test.srv.req.suffix:1|[email protected]\n') | ||
|
||
# We should now be in sampling mode | ||
# should have flushed the upper and lower values | ||
samples = [ | ||
'test-1.test.srv.req.suffix:1|[email protected]\n', | ||
'test-1.test.srv.req.suffix:1|[email protected]\n', | ||
] | ||
|
||
self.check_list_in_recv(fd, samples, 1024) | ||
|
||
|
||
# We should now be in sampling mode | ||
for i in range(0, 200): | ||
sender.sendall('test.srv.req:%s|ms|@1.0\n' % str(i)) | ||
|
||
time.sleep(5.0) | ||
|
||
samples = [ | ||
'test-1.test.srv.req.suffix:199|ms@1\n', | ||
'test-1.test.srv.req.suffix:0|ms@1\n', | ||
] | ||
|
||
# Ensure lower and upper timer values are being flushed. | ||
self.check_list_in_recv(fd, samples, 1024) | ||
|
||
# We should now be in non sampling mode | ||
for i in range(0, 100): | ||
sender.sendall('test.srv.req:1|ms\n') | ||
sender.sendall('test.srv.req:1.0|ms\n') | ||
|
||
self.check_recv_in(fd, 'test-1.test.srv.req.suffix:1|ms@0.05\n') | ||
self.check_recv_in(fd, 'test-1.test.srv.req.suffix:1.0|ms\n') | ||
|
||
sender.sendall('status\n') | ||
status = sender.recv(65536) | ||
|
@@ -240,10 +267,8 @@ def test_tcp_with_timer_sampler(self): | |
backends[backend][key] = int(value) | ||
|
||
key = '127.0.0.1:%d:tcp' % (self.statsd_listener.getsockname()[1],) | ||
self.assertEqual(backends[key]['relayed_lines'], 15) | ||
self.assertEqual(backends[key]['relayed_lines'], 24) | ||
self.assertEqual(backends[key]['dropped_lines'], 0) | ||
self.assertEqual(backends[key]['bytes_sent'], 535) | ||
self.assertEqual(backends[key]['bytes_queued'], 325) | ||
|
||
def test_tcp_with_ingress_blacklist(self): | ||
with self.generate_config('tcp', suffix="-blacklist.json") as config_path: | ||
|