Skip to content

Commit 008a6c5

Browse files
committed
Add branch uscf->flags is NGX_HTTP_UPSTREAM_MODIFY
1 parent 7350d7f commit 008a6c5

File tree

1 file changed

+50
-47
lines changed

1 file changed

+50
-47
lines changed

src/ngx_http_vhost_traffic_status_display_json.c

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -616,53 +616,56 @@ ngx_http_vhost_traffic_status_display_set_upstream_group(ngx_http_request_t *r,
616616
zone = 1;
617617

618618
#if nginx_version > 1027003
619-
// for (peers = uscf->peer.data; peers; peers = peers->next) {
620-
// ngx_http_upstream_rr_peers_rlock(peers);
621-
// for (peer = peers->peer; peer; peer = peer->next) {
622-
// p = ngx_cpymem(p, uscf->host.data, uscf->host.len);
623-
// *p++ = NGX_HTTP_VHOST_TRAFFIC_STATUS_KEY_SEPARATOR;
624-
// p = ngx_cpymem(p, peer->name.data, peer->name.len);
625-
//
626-
// dst.len = uscf->host.len + sizeof("@") - 1 + peer->name.len;
627-
//
628-
// rc = ngx_http_vhost_traffic_status_node_generate_key(r->pool, &key, &dst, type);
629-
// if (rc != NGX_OK) {
630-
// ngx_http_upstream_rr_peers_unlock(peers);
631-
// return buf;
632-
// }
633-
//
634-
// hash = ngx_crc32_short(key.data, key.len);
635-
// node = ngx_http_vhost_traffic_status_node_lookup(ctx->rbtree, &key, hash);
636-
//
637-
// usn.weight = peer->weight;
638-
// usn.max_fails = peer->max_fails;
639-
// usn.fail_timeout = peer->fail_timeout;
640-
// usn.backup = 0;
641-
//#if (NGX_HTTP_UPSTREAM_CHECK)
642-
// if (ngx_http_upstream_check_peer_down(peer->check_index)) {
643-
// usn.down = 1;
644-
//
645-
// } else {
646-
// usn.down = 0;
647-
// }
648-
//#else
649-
// usn.down = (peer->fails >= peer->max_fails || peer->down);
650-
//#endif
651-
//
652-
// usn.name = peer->name;
653-
//
654-
// if (node != NULL) {
655-
// vtsn = (ngx_http_vhost_traffic_status_node_t *) &node->color;
656-
// buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, vtsn);
657-
// } else {
658-
// buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, NULL);
659-
// }
660-
// p = dst.data;
661-
// }
662-
// ngx_http_upstream_rr_peers_unlock(peers);
663-
// }
664-
peers = uscf->peer.data;
665-
buf = ngx_http_vhost_traffic_status_display_ug_host(r, uscf->host, ctx->rbtree->root, ctx->rbtree->sentinel, peers, buf);
619+
if (uscf->flags & NGX_HTTP_UPSTREAM_MODIFY) {
620+
peers = uscf->peer.data;
621+
buf = ngx_http_vhost_traffic_status_display_ug_host(r, uscf->host, ctx->rbtree->root, ctx->rbtree->sentinel, peers, buf);
622+
} else {
623+
for (peers = uscf->peer.data; peers; peers = peers->next) {
624+
ngx_http_upstream_rr_peers_rlock(peers);
625+
for (peer = peers->peer; peer; peer = peer->next) {
626+
p = ngx_cpymem(p, uscf->host.data, uscf->host.len);
627+
*p++ = NGX_HTTP_VHOST_TRAFFIC_STATUS_KEY_SEPARATOR;
628+
p = ngx_cpymem(p, peer->name.data, peer->name.len);
629+
630+
dst.len = uscf->host.len + sizeof("@") - 1 + peer->name.len;
631+
632+
rc = ngx_http_vhost_traffic_status_node_generate_key(r->pool, &key, &dst, type);
633+
if (rc != NGX_OK) {
634+
ngx_http_upstream_rr_peers_unlock(peers);
635+
return buf;
636+
}
637+
638+
hash = ngx_crc32_short(key.data, key.len);
639+
node = ngx_http_vhost_traffic_status_node_lookup(ctx->rbtree, &key, hash);
640+
641+
usn.weight = peer->weight;
642+
usn.max_fails = peer->max_fails;
643+
usn.fail_timeout = peer->fail_timeout;
644+
usn.backup = 0;
645+
#if (NGX_HTTP_UPSTREAM_CHECK)
646+
if (ngx_http_upstream_check_peer_down(peer->check_index)) {
647+
usn.down = 1;
648+
649+
} else {
650+
usn.down = 0;
651+
}
652+
#else
653+
usn.down = (peer->fails >= peer->max_fails || peer->down);
654+
#endif
655+
656+
usn.name = peer->name;
657+
658+
if (node != NULL) {
659+
vtsn = (ngx_http_vhost_traffic_status_node_t *) &node->color;
660+
buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, vtsn);
661+
} else {
662+
buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, NULL);
663+
}
664+
p = dst.data;
665+
}
666+
ngx_http_upstream_rr_peers_unlock(peers);
667+
}
668+
}
666669
goto last;
667670
#endif
668671

0 commit comments

Comments
 (0)