Skip to content

Commit

Permalink
LB load new util (#42)
Browse files Browse the repository at this point in the history
LB load new util

Reviewed-by: Anton Kachurin <[email protected]>
Reviewed-by: Rodion Gyrbu <[email protected]>
Reviewed-by: Anton Sidelnikov <None>
Reviewed-by: None <None>
  • Loading branch information
anton-sidelnikov authored Feb 2, 2021
1 parent 93133ae commit ae42f2d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions csm_test_utils/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from csm_test_utils.rebalance_test import main as r_main
from csm_test_utils.dns import dns_lookup_main, host_main
from csm_test_utils.rds import rds_backup_main
from csm_test_utils.loadbalancer import lb_monitor

args = root_parser.parse_args()
if args.test == "monitor":
Expand All @@ -26,3 +27,5 @@
host_main()
if args.test == "rds_backup_monitor":
rds_backup_main()
if args.test == "lb_load":
lb_monitor()
1 change: 1 addition & 0 deletions csm_test_utils/loadbalancer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .lb_monitor import main as lb_monitor
44 changes: 44 additions & 0 deletions csm_test_utils/loadbalancer/lb_monitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import logging
import socket

import requests
from ocomone.logging import setup_logger

from ..common import base_parser, sub_parsers

LB_TIMING = "lb_timing"
LB_TIMEOUT = "lb_timeout"

LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)

AGP = sub_parsers.add_parser("lb_load", add_help=False, parents=[base_parser])


def main():
args, _ = AGP.parse_known_args()
setup_logger(LOGGER, "lb_load", log_dir=args.log_dir, log_format="[%(asctime)s] %(message)s")
timeout = 20
try:
res = requests.get(args.target, headers={"Connection": "close"}, timeout=timeout)
except requests.Timeout as ex:
LOGGER.exception("Timeout sending request to LB")
result = {
"reason": LB_TIMEOUT,
"client": socket.gethostname(),
"timeout": timeout * 1000,
"exception": ex
}
else:
result = {
"reason": LB_TIMING,
"client": socket.gethostname(),
"server": res.headers["Server"],
"elapsed": res.elapsed.microseconds / 1000
}

print(result)


if __name__ == "__main__":
main()

0 comments on commit ae42f2d

Please sign in to comment.