github.com/crowdsecurity/crowdsec@v1.6.1/docker/test/tests/test_metrics.py (about)

     1  #!/usr/bin/env python
     2  
     3  from http import HTTPStatus
     4  
     5  import pytest
     6  
     7  pytestmark = pytest.mark.docker
     8  
     9  
    10  def test_metrics_port_default(crowdsec, flavor):
    11      """Test metrics"""
    12      metrics_port = 6060
    13      with crowdsec(flavor=flavor) as cs:
    14          cs.wait_for_log("*Starting processing data*")
    15          cs.wait_for_http(8080, '/health', want_status=HTTPStatus.OK)
    16          cs.wait_for_http(metrics_port, '/metrics', want_status=HTTPStatus.OK)
    17          res = cs.cont.exec_run(f'wget -O - http://127.0.0.1:{metrics_port}/metrics')
    18          if 'executable file not found' in res.output.decode():
    19              # TODO: find an alternative to wget
    20              pytest.skip('wget not found')
    21          assert res.exit_code == 0
    22          stdout = res.output.decode()
    23          assert "# HELP cs_info Information about Crowdsec." in stdout
    24  
    25  
    26  def test_metrics_port_default_ipv6(crowdsec, flavor):
    27      """Test metrics (ipv6)"""
    28      pytest.skip('ipv6 not supported yet')
    29      port = 6060
    30      with crowdsec(flavor=flavor) as cs:
    31          cs.wait_for_log("*Starting processing data*")
    32          cs.wait_for_http(8080, '/health', want_status=HTTPStatus.OK)
    33          res = cs.cont.exec_run(f'wget -O - http://[::1]:{port}/metrics')
    34          if 'executable file not found' in res.output.decode():
    35              # TODO: find an alternative to wget
    36              pytest.skip('wget not found')
    37          assert res.exit_code == 0
    38          stdout = res.output.decode()
    39          assert "# HELP cs_info Information about Crowdsec." in stdout
    40  
    41  
    42  def test_metrics_port(crowdsec, flavor):
    43      """Test metrics (custom METRICS_PORT)"""
    44      port = 7070
    45      env = {
    46          "METRICS_PORT": port
    47      }
    48      with crowdsec(flavor=flavor, environment=env) as cs:
    49          cs.wait_for_log("*Starting processing data*")
    50          cs.wait_for_http(8080, '/health', want_status=HTTPStatus.OK)
    51          res = cs.cont.exec_run(f'wget -O - http://127.0.0.1:{port}/metrics')
    52          if 'executable file not found' in res.output.decode():
    53              # TODO: find an alternative to wget
    54              pytest.skip('wget not found')
    55          assert res.exit_code == 0
    56          stdout = res.output.decode()
    57          assert "# HELP cs_info Information about Crowdsec." in stdout
    58  
    59  
    60  def test_metrics_port_ipv6(crowdsec, flavor):
    61      """Test metrics (custom METRICS_PORT, ipv6)"""
    62      pytest.skip('ipv6 not supported yet')
    63      port = 7070
    64      env = {
    65          "METRICS_PORT": port
    66      }
    67      with crowdsec(flavor=flavor, environment=env) as cs:
    68          cs.wait_for_log("*Starting processing data*")
    69          cs.wait_for_http(8080, '/health', want_status=HTTPStatus.OK)
    70          res = cs.cont.exec_run(f'wget -O - http://[::1]:{port}/metrics')
    71          if 'executable file not found' in res.output.decode():
    72              # TODO: find an alternative to wget
    73              pytest.skip('wget not found')
    74          assert res.exit_code == 0
    75          stdout = res.output.decode()
    76          assert "# HELP cs_info Information about Crowdsec." in stdout