项目作者: salosh

项目描述 :
Nudnik - Infrastructure Fuzzing
高级语言: Python
项目地址: git://github.com/salosh/nudnik.git
创建时间: 2018-11-19T18:39:29Z
项目社区:https://github.com/salosh/nudnik

开源协议:GNU General Public License v3.0

下载


Nudnik

Goals

Allow easy testing of load-balancing and failures in gRPC and REST based service-mesh

Features

  • Rate limiting
  • Fake IO load from either client or server side
  • Export timing metrics to a file or InfluxDB with any custom formatting

Quick Start

  • Install Nudnik:

    1. # Install package
    2. pip install nudnik
  • Run example Server:

    1. nudnik --server
  • Run a client that identifies itself as barbaz, fork to 2 threads, each sending 5 gRPC messages every 3 seconds.

    1. nudnik --name barbaz --streams 2 --interval 3 --rate 5

Docker - Quick Start

  • Running on your local/remote docker daemon using docker-compose:
    docker-compose up

Under The Hood

The server binds to the host:port that were specified, and listens to incoming gRPC messages.
Every message consists of several fields:

  • name: The name of the client, arbitrary string
  • stream_id: The stream id, the streams are numbered from 0 to whatever was configureed via the streams arg.
  • message_id: At every interval, the client sends rate messages, this id is an autoincrement index for that message.
  • ctime: The timestamp at which the request was created
  • rtime: The timestamp at which the request was retransmitted (0 if not applicapble)
  • rcount: The amount of times this message was retransmitted (0 if not applicapble)
  • meta: Just another string field that does nothing, you may send additional arbitrary data to increase message size or specify random to generate random data with every request
  • load: This field may be repeated several times, it instructs the server to create fake load of some sort before replying.

    Upon recieveing a message, the server will:

    • parse the load field
    • perform the required load
    • print a log message using the configured out_format
    • reply an OK to the client, also add the field ptime, which represents the time at which the request was parsed at the server,
      this allows the client to calculate exact RTT, even if NTP is not synchronized.

Local Development

As a rule of thumb wed’e recommend using virtualenv.
Requirement are Python 3.7 + requirements.txt file

  • Clone and initialize Nudnik:
    ```sh

    Install python requirements

    pip install grpcio grpcio-tools requests-unixsocket

Clone and configure the repository

git clone https://github.com/salosh/nudnik.git
git config —global push.default matching
git config —global user.name “Your Name”
git config —global user.email your.email@salosh.org

“Compile” the entity protobuf

cd nudnik
python -m grpc_tools.protoc —proto_path=./nudnik/ —python_out=./nudnik/ —grpc_python_out=./nudnik/ ./entity.proto

  1. Configure
  2. --------
  3. [Configuration](/nudnik/docs/configuration.md) documentation
  4. [Formatting](/nudnik/docs/formatting.md) documentation
  5. ## Via `Nudnik` Command line args:
  6. ```sh
  7. nudnik -h
  8. usage: nudnik [-h] [--config-file CONFIG_FILE] [--host HOST] [--port PORT]
  9. [--server] [--name NAME]
  10. [--name-mismatch-error {prefix,suffix,exact}] [--meta META]
  11. [--workers WORKERS] [--streams STREAMS]
  12. [--initial-stream-index INITIAL_STREAM_INDEX]
  13. [--interval INTERVAL] [--rate RATE] [--count COUNT]
  14. [--chaos CHAOS] [--load load_type load_value]
  15. [--retry-count RETRY_COUNT] [--fail-ratio FAIL_RATIO] [--ruok]
  16. [--metrics {stdout,file,influxdb,prometheus}]
  17. [--stats {stdout,file,influxdb,prometheus}] [--extra EXTRA]
  18. [--debug] [--verbose] [--version]
  19. Nudnik - gRPC load tester
  20. optional arguments:
  21. -h, --help show this help message and exit
  22. --config-file CONFIG_FILE, -f CONFIG_FILE
  23. Path to YAML config file
  24. --host HOST, -H HOST host
  25. --port PORT, -p PORT port
  26. --server, -S Operation mode (default: client)
  27. --name NAME, -n NAME Parser name
  28. --name-mismatch-error {prefix,suffix,exact}
  29. Fail request on name mismatch (default: None)
  30. --meta META, -M META Send this extra data with every request
  31. --workers WORKERS, -w WORKERS
  32. Number of workers (Default: Count of CPU cores)
  33. --streams STREAMS, -s STREAMS
  34. Number of streams (Default: 1)
  35. --initial-stream-index INITIAL_STREAM_INDEX
  36. Calculate stream ID from this initial index (Default:
  37. 0)
  38. --interval INTERVAL, -i INTERVAL
  39. Number of seconds per stream message cycle (Default:
  40. 1)
  41. --rate RATE, -r RATE Number of messages per interval (Default: 10)
  42. --count COUNT, -C COUNT
  43. Count of total messages that should be sent (Default:
  44. 0 == unlimited)
  45. --chaos CHAOS, -c CHAOS
  46. Compute statistical process level random crashes [0,
  47. 3600/interval] (Default: 0)
  48. --load load_type load_value, -l load_type load_value
  49. Add artificial load [rtt, rttr, cpu, mem, cmd, fcmd]
  50. (Default: None)
  51. --retry-count RETRY_COUNT
  52. Number of times to re-send failed messages (Default:
  53. -1, which means infinite times)
  54. --fail-ratio FAIL_RATIO
  55. Percent of requests to intentionally fail (Default: 0)
  56. --ruok, -R Enable "Are You OK?" HTTP/1.1 API (default: False)
  57. --metrics {stdout,file,influxdb,prometheus}, -m {stdout,file,influxdb,prometheus}
  58. Enable metrics outputs (Default: None)
  59. --stats {stdout,file,influxdb,prometheus}, -t {stdout,file,influxdb,prometheus}
  60. Enable stats outputs (Default: None)
  61. --extra EXTRA, -e EXTRA
  62. Extra args (Default: None)
  63. --debug, -d Debug mode (default: False)
  64. --verbose, -v Verbose mode, specify multiple times for extra
  65. verbosity (default: None)
  66. --version, -V Display Nudnik version
  67. 2018 (C) Salo Shp <https://github.com/salosh/nudnik.git>

Via config file:

  1. nano ./config.yml

Getting started

Please refer to our examples repository for multiple guides and usage examples


Visit our website at https://salosh.org