vozlt/nginx-module-vts

First request always mapps as +inf bucket instead of real bucket

Veres72 opened this issue · 2 comments

The first request always maps as +inf bucket instead of real bucket, while all the following is correct.

The first request

nginx_vts_server_request_duration_seconds_bucket{host="_",le="0.001"} 0
nginx_vts_server_request_duration_seconds_bucket{host="_",le="1.000"} 0
nginx_vts_server_request_duration_seconds_bucket{host="_",le="100000.000"} 0
nginx_vts_server_request_duration_seconds_bucket{host="_",le="+Inf"} 1
nginx_vts_server_request_duration_seconds_sum{host="_"} 0.000
nginx_vts_server_request_duration_seconds_count{host="_"} 1

After several requests

nginx_vts_server_request_duration_seconds_bucket{host="_",le="0.001"} 11
nginx_vts_server_request_duration_seconds_bucket{host="_",le="1.000"} 11
nginx_vts_server_request_duration_seconds_bucket{host="_",le="100000.000"} 11
nginx_vts_server_request_duration_seconds_bucket{host="_",le="+Inf"} 12
nginx_vts_server_request_duration_seconds_sum{host="_"} 0.000
nginx_vts_server_request_duration_seconds_count{host="_"} 12
vozlt commented

@Veres72
As you think, since nginx_vts_server_request_duration_seconds_sum is zero, it should normally be calculated in the nginx_vts_server_request_duration_seconds_bucket{host="_",le="100000.000"} part.
My guess is that it didn't count for some reason in the ngx_http_vhost_traffic_status_node_histogram_observe() function. I haven't succeeded in reproducing it. Please let me know the system environment where I can reproduce the problem as below.

1. Reproducible nginx settings
2. nginx informations displayed by executing the command "$ nginx -V"
3. nginx-module-vts version

Testing

nginx_vts_server_request_duration_seconds_bucket{host="_",le="0.001"} 1
nginx_vts_server_request_duration_seconds_bucket{host="_",le="1.000"} 1
nginx_vts_server_request_duration_seconds_bucket{host="_",le="100000.000"} 1
nginx_vts_server_request_duration_seconds_bucket{host="_",le="+Inf"} 1
nginx_vts_server_request_duration_seconds_sum{host="_"} 0.000
nginx_vts_server_request_duration_seconds_count{host="_"} 1

CallStack

#2 ngx_http_vhost_traffic_status_node_histogram_observe()
#1 ngx_http_vhost_traffic_status_node_update()
#0 ngx_http_vhost_traffic_status_node_init()

void
ngx_http_vhost_traffic_status_node_histogram_observe(
ngx_http_vhost_traffic_status_node_histogram_bucket_t *b,
ngx_msec_int_t x)
{
ngx_uint_t i, n;
n = b->len;
for (i = 0; i < n; i++) {
if (x <= b->buckets[i].msec) {
b->buckets[i].counter++;
}
}
}

void
ngx_http_vhost_traffic_status_node_update(ngx_http_request_t *r,
ngx_http_vhost_traffic_status_node_t *vtsn, ngx_msec_int_t ms)
{
ngx_uint_t status = r->headers_out.status;
vtsn->stat_request_counter++;
vtsn->stat_in_bytes += (ngx_atomic_uint_t) r->request_length;
vtsn->stat_out_bytes += (ngx_atomic_uint_t) r->connection->sent;
ngx_http_vhost_traffic_status_add_rc(status, vtsn);
vtsn->stat_request_time_counter += (ngx_atomic_uint_t) ms;
ngx_http_vhost_traffic_status_node_time_queue_insert(&vtsn->stat_request_times,
ms);
ngx_http_vhost_traffic_status_node_histogram_observe(&vtsn->stat_request_buckets,
ms);
#if (NGX_HTTP_CACHE)
if (r->upstream != NULL && r->upstream->cache_status != 0) {
ngx_http_vhost_traffic_status_add_cc(r->upstream->cache_status, vtsn);
}
#endif
}

void
ngx_http_vhost_traffic_status_node_init(ngx_http_request_t *r,
ngx_http_vhost_traffic_status_node_t *vtsn)
{
ngx_msec_int_t ms;
/* init serverZone */
ngx_http_vhost_traffic_status_node_zero(vtsn);
ngx_http_vhost_traffic_status_node_time_queue_init(&vtsn->stat_request_times);
ngx_http_vhost_traffic_status_node_histogram_bucket_init(r, &vtsn->stat_request_buckets);
/* init upstreamZone */
vtsn->stat_upstream.type = NGX_HTTP_VHOST_TRAFFIC_STATUS_UPSTREAM_NO;
vtsn->stat_upstream.response_time_counter = 0;
vtsn->stat_upstream.response_time = 0;
ngx_http_vhost_traffic_status_node_time_queue_init(&vtsn->stat_upstream.response_times);
ngx_http_vhost_traffic_status_node_histogram_bucket_init(r,
&vtsn->stat_upstream.response_buckets);
/* set serverZone */
ms = ngx_http_vhost_traffic_status_request_time(r);
vtsn->stat_request_time = (ngx_msec_t) ms;
ngx_http_vhost_traffic_status_node_update(r, vtsn, ms);
}

I updated from vts 0.1.18 to 0.2.1 and problem was solved. I will close the issue. Thank you.