Skip to content

Commit

Permalink
[test] Add EXTENDED_METRICS integration test.
Browse files Browse the repository at this point in the history
This commit add the EXTENDED_Metrics integration test.

Signed-off-by: Eloy Coto <eloy.coto@gmail.com>
  • Loading branch information
eloycoto committed May 2, 2019
1 parent 6cb6dd0 commit 9b2deea
Showing 1 changed file with 161 additions and 2 deletions.
163 changes: 161 additions & 2 deletions t/prometheus-metrics.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
use lib 't';
use Test::APIcast::Blackbox 'no_plan';

add_response_body_check(sub {
my ($block, $body, $req_idx, $repeated_req_idx, $dry_run) = @_;

my @asserts = @{$block->{expected_multiple_values}};
if (@asserts == 0) {
return "";
}
my $index = 0;
my $assertValues = $asserts[0][$req_idx];
if (ref($assertValues) eq 'ARRAY') {
foreach my $regexp(@{$assertValues}){
if (!($body =~ m/$regexp/)) {
fail(sprintf("Regular expression: '%s' does not match with the body: \n %s",$regexp, $body));
}
}
}else{
if (!($body =~ m/$assertValues/)) {
fail(sprintf("Regular expression: '%s' does not match with the body: \n %s",$assertValues, $body));
}
}
});

# The output varies between requests, so run only once
repeat_each(1);

Expand Down Expand Up @@ -231,7 +253,7 @@ In particular, it shows the status codes and the response times
--- response_body_like eval
[
"",
qr/upstream_response_time_seconds(.|\n)*upstream_response_time_seconds_bucket\{le=".*"\} 1(.|\n)*upstream_status\{status="200"\} 1/
qr/upstream_response_time_seconds(.|\n)*upstream_response_time_seconds_bucket\{service="all",le=".*"\} 1(.|\n)*upstream_status\{status="200",service="all"\} 1/
]
--- no_error_log
[error]
Expand Down Expand Up @@ -275,7 +297,144 @@ qr/upstream_response_time_seconds(.|\n)*upstream_response_time_seconds_bucket\{l
--- response_body_like eval
[
"",
qr/total_response_time_seconds(.|\n)*total_response_time_seconds_bucket\{le=".*"\} 1/
qr/total_response_time_seconds(.|\n)*total_response_time_seconds_bucket\{service="all",le=".*"\} 1/
]
--- no_error_log
[error]
=== TEST 6: extended metrics show services id
--- env eval
("APICAST_EXTENDED_METRICS", "true")
--- configuration
{
"services": [
{
"id": 42,
"proxy": {
"policy_chain": [
{
"name": "apicast.policy.upstream",
"configuration": {
"rules": [
{
"regex": "/",
"url": "http://test:$TEST_NGINX_SERVER_PORT"
}
]
}
}
]
}
}
]
}
--- upstream
location / {
content_by_lua_block {
ngx.exit(200);
}
}
--- request eval
["GET /", "GET /metrics"]
--- more_headers eval
["", "Host: metrics"]
--- error_code eval
[ 200, 200 ]
--- expected_multiple_values eval
[
"",
[
qr/total_response_time_seconds(.|\n)*total_response_time_seconds_bucket\{service="42",le=".*"\} 1/,
qr/upstream_response_time_seconds(.|\n)*upstream_response_time_seconds_bucket\{service="42",le=".*"\} 1(.|\n)*upstream_status\{status="200",service="42"\} 1/
]
]
--- no_error_log
[error]
=== TEST 7: extended metrics with multiple services
--- env eval
("APICAST_EXTENDED_METRICS", "true")
--- configuration
{
"services": [
{
"id": 42,
"proxy": {
"hosts": [
"one"
],
"policy_chain": [
{
"name": "apicast.policy.upstream",
"configuration": {
"rules": [
{
"regex": "/",
"url": "http://test:$TEST_NGINX_SERVER_PORT"
}
]
}
}
]
}
},
{
"id": 21,
"proxy": {
"hosts": [
"two"
],
"policy_chain": [
{
"name": "apicast.policy.upstream",
"configuration": {
"rules": [
{
"regex": "/",
"url": "http://test:$TEST_NGINX_SERVER_PORT/two"
}
]
}
}
]
}
}
]
}
--- upstream
location / {
content_by_lua_block {
ngx.exit(200);
}
}
location /two {
content_by_lua_block {
ngx.exit(200);
}
}
--- request eval
["GET /", "GET /two", "GET /metrics"]
--- more_headers eval
["Host: one", "Host: two", "Host: metrics"]
--- error_code eval
[ 200, 200, 200 ]
--- expected_multiple_values eval
[
"",
"",
[
qr/total_response_time_seconds_bucket\{service="42",le=".*"\} 1/,
qr/upstream_response_time_seconds_bucket\{service="42",le=".*"\} 1/,
qr/upstream_status\{status="200",service="42"\}/,
qr/total_response_time_seconds_bucket\{service="21",le=".*"\} 1/,
qr/upstream_response_time_seconds_bucket\{service="21",le=".*"\} 1/,
qr/upstream_status\{status="200",service="21"\}/,
]]
--- no_error_log
[error]

0 comments on commit 9b2deea

Please sign in to comment.