### ReportService Usage Example Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Example demonstrating how to create, initialize, and start a ReportService, and how to wait for its completion. ```go reportService, err := report.NewReportService("stdout") if err != nil { log.Fatal(err) } reportService.Init(debug=false, samplingRate=3) // Engine will call this to stream results go reportService.Start(resultsChan, assertionsChan) // Wait for reporting to complete <-reportService.DoneChan() ``` -------------------------------- ### ParseTLS Usage Example Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Example demonstrating how to use ParseTLS to load certificate files and assign them to a scenario step. ```go cert, pool, err := types.ParseTLS("cert.pem", "key.pem") if err != nil { log.Fatal(err) } step.Cert = cert step.CertPool = pool ``` -------------------------------- ### NewRequester Usage Example Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Example demonstrating how to create and use a requester for an HTTP scenario step. ```go step := types.ScenarioStep{ ID: 1, URL: "https://api.example.com/users", Method: "GET", } requester, err := requester.NewRequester(step) // Use requester to send HTTP requests ``` -------------------------------- ### Programmatic Usage Example Source: https://github.com/getanteon/anteon/blob/master/_autodocs/01-overview.md Shows how to use the Anteon engine programmatically in Go. This snippet illustrates creating a configuration reader, initializing engine services, and starting the load test. ```go import "go.ddosify.com/ddosify/config" // Create config reader from JSON bytes reader, err := config.NewConfigReader(jsonBytes, config.ConfigTypeJson) hammer, err := reader.CreateHammer() // Validate configuration err = hammer.Validate() // Run test es, err := core.InitEngineServices(hammer) engine, err := core.NewEngine(ctx, hammer, es) engine.Start() ``` -------------------------------- ### Install Ddosify from source with Go Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Install Ddosify from source using Go. Requires Go version 1.18 or higher. ```bash go install -v go.ddosify.com/ddosify@latest ``` -------------------------------- ### URL Validation Example Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Example showing how to use IsTargetValid to check the format of a target URL, including environment variables. ```go if err := types.IsTargetValid("{{BASE_URL}}/api"); err != nil { log.Fatal("Invalid target URL:", err) } ``` -------------------------------- ### Example Anteon Module Imports Source: https://github.com/getanteon/anteon/blob/master/_autodocs/07-modules.md Demonstrates how to import various Anteon modules for use in your Go programs. ```go import ( "go.ddosify.com/ddosify/config" "go.ddosify.com/ddosify/core" "go.ddosify.com/ddosify/core/types" "go.ddosify.com/ddosify/core/proxy" "go.ddosify.com/ddosify/core/report" "go.ddosify.com/ddosify/core/assertion" "go.ddosify.com/ddosify/core/scenario" ) ``` -------------------------------- ### Detailed Per-Step Assertion Example Source: https://github.com/getanteon/anteon/blob/master/_autodocs/06-scripting.md A comprehensive example of a per-step assertion configuration, including status code, body content, and header checks. ```json { "id": 1, "url": "https://api.example.com/users", "assertion": [ "equals(status_code, 200)", "contains(body, \"name\")", "in(headers.content-length, [100, 200, 300])" ] } ``` -------------------------------- ### ProxyService Initialization and Usage Example Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Demonstrates how to initialize a ProxyService with a specific proxy configuration and retrieve a proxy for a request. Ensure the proxy URL is correctly parsed. ```go proxyURL, _ := url.Parse("http://proxy.example.com:8080") proxyService, err := proxy.NewProxyService(proxy.ProxyTypeSingle) err = proxyService.Init(types.Proxy{ Strategy: proxy.ProxyTypeSingle, Addr: proxyURL, }) p := proxyService.GetProxy() // Get proxy for this request ``` -------------------------------- ### Install Ddosify on FreeBSD Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Install Ddosify on FreeBSD systems using the pkg package manager. ```bash pkg install ddosify ``` -------------------------------- ### Run Ddosify with Docker Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Execute Ddosify using a Docker container. This is a quick way to get started without local installation. ```bash docker run -it --rm ddosify/ddosify ``` -------------------------------- ### Run a Test Source: https://github.com/getanteon/anteon/blob/master/_autodocs/INDEX.md This snippet initializes the Ddosify engine services and starts a test execution. ```go services, _ := core.InitEngineServices(hammer) engine, _ := core.NewEngine(ctx, hammer, services) engine.Init() engine.Start() ``` -------------------------------- ### Example Usage of NewConfigReader Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Demonstrates how to create a JSON configuration reader and then use it to create a Hammer object. Ensure necessary imports are included. ```go import "go.ddosify.com/ddosify/config" jsonBytes := []byte(`{ "iteration_count": 100, "load_type": "linear", "steps": [{...}] }`) reader, err := config.NewConfigReader(jsonBytes, config.ConfigTypeJson) if err != nil { log.Fatal(err) } hammer, err := reader.CreateHammer() if err != nil { log.Fatal(err) } ``` -------------------------------- ### Install Ddosify on Alpine Linux Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Install Ddosify on Alpine Linux using an APK package. Superuser privileges are required. ```bash wget https://github.com/ddosify/ddosify/releases/download/v1.0.6/ddosify_amd64.apk apg --allow-untrusted ddosify_amd64.apk ``` -------------------------------- ### Per-Step Assertion Example Source: https://github.com/getanteon/anteon/blob/master/_autodocs/06-scripting.md Example of defining per-step assertions within a step's configuration. These assertions are evaluated for each individual request. ```json { "assertion": [ "equals(status_code, 200)", "equals(headers.content-type, \"application/json\")" ] } ``` -------------------------------- ### Example Step Configuration Source: https://github.com/getanteon/anteon/blob/master/_autodocs/04-configuration.md Defines a single HTTP POST request step with custom headers, payload, authentication, and assertions. Supports environment variable substitution for dynamic values. ```json { "id": 1, "name": "Create User", "url": "{{API_BASE}}/users", "method": "POST", "timeout": 5, "headers": { "Content-Type": "application/json", "Authorization": "Bearer {{TOKEN}}" }, "payload": "{\"name\": \"{{NAME}}\", \"email\": \"{{EMAIL}}\"}", "auth": { "username": "admin", "password": "secret123" }, "sleep": "100", "capture_env": { "USER_ID": { "from": "body", "json_path": "$.id" } }, "assertion": [ "equals(status_code,201)", "contains(body,\"success\")" ] } ``` -------------------------------- ### Install Ddosify using convenience script Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Install the latest Ddosify version on macOS and Linux using a convenience script. Requires curl and sudo privileges. ```bash curl -sSfL https://raw.githubusercontent.com/getanteon/anteon/master/scripts/install.sh | sh ``` -------------------------------- ### Install Ddosify with Homebrew Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Install Ddosify on macOS and Linux systems using Homebrew. Ensure you have Homebrew installed first. ```bash brew install ddosify/tap/ddosify ``` -------------------------------- ### Complete Anteon Configuration Example Source: https://github.com/getanteon/anteon/blob/master/_autodocs/04-configuration.md A comprehensive configuration file demonstrating various settings including load parameters, environment variables, data source configuration, success criteria, and detailed request steps. ```json { "iteration_count": 100, "load_type": "linear", "duration": 30, "debug": false, "engine_mode": "distinct-user", "output": "stdout", "sampling_rate": 5, "proxy": "http://proxy.example.com:8080", "env": { "API_BASE": "https://api.example.com", "TOKEN": "eyJhbGc...", "ADMIN_IDS": [1, 2, 3] }, "data": { "users": { "path": "users.csv", "delimiter": ",", "skip_first_line": true, "vars": { "0": {"tag": "user_id", "type": "int"}, "1": {"tag": "username"} } } }, "success_criterias": [ { "rule": "p90(iteration_duration) < 2000", "abort": false }, { "rule": "fail_count < 5", "abort": true, "delay": 5 } ], "cookie_jar": { "enabled": true, "cookies": [] }, "steps": [ { "id": 1, "name": "Login", "url": "{{API_BASE}}/login", "method": "POST", "timeout": 10, "headers": { "Content-Type": "application/json" }, "payload": "{\"username\": \"{{data.users.username}}\"}", "capture_env": { "AUTH_TOKEN": { "from": "body", "json_path": "$.token" } }, "assertion": ["equals(status_code, 200)"] }, { "id": 2, "name": "Get Profile", "url": "{{API_BASE}}/profile", "method": "GET", "timeout": 5, "headers": { "Authorization": "Bearer {{AUTH_TOKEN}}" }, "assertion": ["equals(status_code, 200)"] } ] } ``` -------------------------------- ### Install Ddosify on Redhat-based Linux Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Install Ddosify on Redhat, Fedora, CentOS, or RHEL using an RPM package. Superuser privileges are required. ```bash rpm -i https://github.com/ddosify/ddosify/releases/download/v1.0.6/ddosify_amd64.rpm ``` -------------------------------- ### Ddosify Command-Line Usage Source: https://github.com/getanteon/anteon/blob/master/_autodocs/INDEX.md Examples of running Ddosify from the command line, specifying a configuration file or target URL. ```bash ddosify -config test.json ``` ```bash ddosify -t https://api.example.com -n 100 -m POST ``` -------------------------------- ### Run Anteon Application Source: https://github.com/getanteon/anteon/blob/master/CONTRIBUTING.md Execute the main Go program to run the Anteon application. Ensure you have Go version 1.18 or higher installed. ```bash go run main.go ``` -------------------------------- ### CLI Invocation Examples Source: https://github.com/getanteon/anteon/blob/master/_autodocs/01-overview.md Demonstrates various ways to invoke the ddosify CLI for load testing. Includes simple requests, configuration file usage, debug output, and custom headers/authentication. ```bash # Simple single request ddosify -t https://example.com -n 100 -d 10 -m POST -b '{"key":"value"}' ``` ```bash # With config file ddosify -config scenario.json ``` ```bash # With debug output ddosify -config scenario.json -debug ``` ```bash # With custom headers and auth ddosify -t https://example.com -h 'Content-Type: application/json' -a username:password ``` -------------------------------- ### Build and Run Load Test Scenario Programmatically Source: https://github.com/getanteon/anteon/blob/master/_autodocs/08-examples.md Constructs a load testing scenario step-by-step, defining environment variables, requests, and headers. Validates the scenario and then initializes and starts the load test engine. ```go package main import ( "context" "log" "go.ddosify.com/ddosify/core" "go.ddosify.com/ddosify/core/proxy" "go.ddosify.com/ddosify/core/types" ) func main() { // Build scenario manually scenario := types.Scenario{ Envs: map[string]interface{}{ "API_BASE": "https://api.example.com", "TOKEN": "secret123", }, Steps: []types.ScenarioStep{ { ID: 1, Name: "Get Users", URL: "{{API_BASE}}/users", Method: "GET", Headers: map[string]string{ "Authorization": "Bearer {{TOKEN}}", }, Timeout: 10, }, { ID: 2, Name: "Create User", URL: "{{API_BASE}}/users", Method: "POST", Headers: map[string]string{ "Content-Type": "application/json", }, Payload: `{"name": "John", "email": "john@example.com"}`, Timeout: 10, }, }, } // Create Hammer hammer := types.Hammer{ IterationCount: 50, LoadType: types.LoadTypeLinear, TestDuration: 20, Scenario: scenario, ReportDestination: "stdout", Proxy: proxy.Proxy{ Strategy: proxy.ProxyTypeSingle, }, } // Validate if err := hammer.Validate(); err != nil { log.Fatal(err) } // Initialize and run services, _ := core.InitEngineServices(hammer) ctx, _ := context.WithCancel(context.Background()) engine, _ := core.NewEngine(ctx, hammer, services) engine.Init() engine.Start() } ``` -------------------------------- ### Example Error Handling in Go Source: https://github.com/getanteon/anteon/blob/master/_autodocs/05-errors.md Demonstrates how to iterate through results and handle different types of request errors using a switch statement. ```go for result := range resultsChan { for _, stepResult := range result.StepResults { if stepResult.Err.Type != "" { log.Printf("Request failed: %v", stepResult.Err.Error()) switch stepResult.Err.Type { case types.ErrorProxy: log.Println("Proxy configuration or connectivity issue") case types.ErrorConn: log.Println("Target service unreachable") case types.ErrorDns: log.Println("DNS resolution failed") case types.ErrorInvalidRequest: log.Println("Request is malformed") } } } } ``` -------------------------------- ### Install Ddosify on Debian-based Linux Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Install Ddosify on Ubuntu, Debian, or Linux Mint using a DEB package. Superuser privileges are required. ```bash wget https://github.com/ddosify/ddosify/releases/download/v1.0.6/ddosify_amd64.deb dpkg -i ddosify_amd64.deb ``` -------------------------------- ### Engine Start Method Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Executes the load test synchronously. This method blocks until all iterations are completed or the test is aborted. Results are sent to the report service and assertions are applied. ```go // Start test with graceful shutdown on Ctrl+C go func() { sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, os.Interrupt) <- sigChan cancel() // triggers engine shutdown }() engine.Start() ``` -------------------------------- ### Full Ddosify Configuration with Correlation and Injection Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md An example of a complete Ddosify configuration file demonstrating multi-step correlation and variable injection using captured and environment variables. ```json // ddosify_config_correlation.json { "iteration_count": 100, "load_type": "linear", "duration": 10, "steps": [ { "id": 1, "url": "{{TARGET_URL}}", "method": "POST", "headers": { "User-Key": "{{USER_KEY}}", "Rand-Selected-Num": "{{rand(NUMBERS)}}" }, "payload": "{{COMPANY_NAME}}", "capture_env": { "NUM": { "from": "body", "json_path": "num" }, "NAME": { "from": "body", "json_path": "name" }, "SQUAD": { "from": "body", "json_path": "squad" }, "PLAYERS": { "from": "body", "json_path": "squad.players" }, "MESSI": { "from": "body", "json_path": "squad.players.0" }, "TOKEN": { "from": "header", "header_key": "Authorization" }, "CONTENT_TYPE": { "from": "header", "header_key": "Content-Type", "regexp": { "exp": "application/(\w)+", "matchNo": 0 } } } }, { "id": 2, "url": "{{TARGET_URL}}", "method": "POST", "headers": { "User-Key": "{{USER_KEY}}", "Authorization": "{{TOKEN}}", "Content-Type": "{{CONTENT_TYPE}}" }, "payload_file": "payload.json", "capture_env": { "TITLE": { "from": "body", "xpath": "//item/title" }, "REGEX_MATCH_ENV": { "from": "body", "regexp": { "exp": "[a-z]+_[0-9]+", "matchNo": 1 } } } } ], "env": { "TARGET_URL": "http://localhost:8084/hello", "USER_KEY": "ABC", "COMPANY_NAME": "Ddosify", "RANDOM_COUNTRY": "{{_randomCountry}}", "NUMBERS": [22, 33, 10, 52] } } ``` -------------------------------- ### Basic Load Test with GET Request Source: https://github.com/getanteon/anteon/blob/master/_autodocs/08-examples.md Send a specified number of GET requests to a target URL over a defined duration. Useful for simple endpoint performance checks. ```bash ddosify -t https://api.example.com/endpoint -n 100 -d 10 -m GET ``` -------------------------------- ### Handle Service Initialization Errors Source: https://github.com/getanteon/anteon/blob/master/_autodocs/05-errors.md Ensure all errors during service and engine initialization are handled. This includes factory errors, engine creation failures, and potential I/O errors during engine setup. ```go // Always handle factory errors services, err := core.InitEngineServices(hammer) if err != nil { log.Fatalf("Service initialization failed: %v", err) } engine, err := core.NewEngine(ctx, hammer, services) if err != nil { log.Fatalf("Engine creation failed: %v", err) } // Engine initialization can fail with I/O errors (CSV loading) if err := engine.Init(); err != nil { log.Fatalf("Engine initialization failed: %v", err) } ``` -------------------------------- ### X-WWW-Form-URLencoded Payload Example Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Demonstrates how to send data with the 'application/x-www-form-urlencoded' Content-Type. ```json { "headers": { "Content-Type": "application/x-www-form-urlencoded" }, "payload": "key1=value1&key2=value2" } ``` -------------------------------- ### Handle Per-Step Errors During Execution Source: https://github.com/getanteon/anteon/blob/master/_autodocs/05-errors.md Process results from a channel and check for errors at the step level. This example demonstrates logging specific error types and suggests handling logic for connection or proxy errors. ```go // Check per-step errors during result processing for result := range resultsChan { for _, stepResult := range result.StepResults { if stepResult.Err.Type != "" { log.Printf("Step %d failed: %s: %s", stepResult.StepID, stepResult.Err.Type, stepResult.Err.Reason) // Handle specific error types if stepResult.Err.Type == types.ErrorConn { // Retry logic or failover } else if stepResult.Err.Type == types.ErrorProxy { // Proxy troubleshooting } } } } ``` -------------------------------- ### Run Load Test Using Configuration File Source: https://github.com/getanteon/anteon/blob/master/_autodocs/08-examples.md Execute a load test scenario defined in a JSON configuration file. This is useful for managing complex test setups and ensuring reproducibility. ```bash ddosify -config test_scenario.json ``` -------------------------------- ### Scenario-Based Load Test Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Run a load test defined by a configuration file. This example involves multiple HTTP requests with basic authentication and payload data, repeated a specified number of times. ```bash ddosify -config config_examples/config.json ``` -------------------------------- ### Ddosify Linear Load Test Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Example of running a linear load test. Ensure the iteration count is sufficient for the desired duration. ```bash ddosify -t https://getanteon.com -l linear ``` -------------------------------- ### Anteon Complex Multi-Step Workflow Example Source: https://github.com/getanteon/anteon/blob/master/_autodocs/08-examples.md This configuration defines a complex multi-step workflow for an e-commerce scenario, including user registration, product browsing, adding to cart, checkout, and order confirmation. It utilizes environment variables, data files, and assertions for validation. ```json { "iteration_count": 30, "load_type": "linear", "duration": 60, "engine_mode": "distinct-user", "env": { "BASE_URL": "https://ecommerce.example.com" }, "data": { "products": { "path": "./products.csv", "vars": { "0": {"tag": "product_id"}, "1": {"tag": "category"} } }, "users": { "path": "./users.csv", "vars": { "0": {"tag": "email"}, "1": {"tag": "password"} } } }, "success_criterias": [ { "rule": "p99(iteration_duration) < 5000", "abort": false }, { "rule": "fail_count < 2", "abort": true, "delay": 10 } ], "steps": [ { "id": 1, "name": "Register", "url": "{{BASE_URL}}/auth/register", "method": "POST", "headers": { "Content-Type": "application/json" }, "payload": "{\"email\": \"{{data.users.email}}\", \"password\": \"{{data.users.password}}\"}", "capture_env": { "AUTH_TOKEN": { "from": "body", "json_path": "$.token" } }, "assertion": ["equals(status_code, 201)"] }, { "id": 2, "name": "Browse Products", "url": "{{BASE_URL}}/products?category={{data.products.category}}", "method": "GET", "headers": { "Authorization": "Bearer {{AUTH_TOKEN}}" }, "assertion": ["equals(status_code, 200)"] }, { "id": 3, "name": "Add to Cart", "url": "{{BASE_URL}}/cart/items", "method": "POST", "headers": { "Authorization": "Bearer {{AUTH_TOKEN}}", "Content-Type": "application/json" }, "payload": "{\"product_id\": {{data.products.product_id}}, \"quantity\": 1}", "capture_env": { "CART_ID": { "from": "body", "json_path": "$.cart_id" } }, "assertion": ["equals(status_code, 200)"] }, { "id": 4, "name": "Checkout", "url": "{{BASE_URL}}/orders", "method": "POST", "headers": { "Authorization": "Bearer {{AUTH_TOKEN}}", "Content-Type": "application/json" }, "payload": "{\"cart_id\": \"{{CART_ID}}\", \"shipping_address\": \"123 Main St\"}", "capture_env": { "ORDER_ID": { "from": "body", "json_path": "$.order_id" } }, "assertion": ["equals(status_code, 201)"] }, { "id": 5, "name": "Confirm Order", "url": "{{BASE_URL}}/orders/{{ORDER_ID}}/confirm", "method": "POST", "headers": { "Authorization": "Bearer {{AUTH_TOKEN}}" }, "assertion": [ "equals(status_code, 200)", "contains(body, \"confirmed\")" ] } ] } ``` -------------------------------- ### Global Variable Scoping Example Source: https://github.com/getanteon/anteon/blob/master/_autodocs/06-scripting.md Define global variables in the 'env' section, making them accessible across all steps in the configuration. ```json { "env": { "API_BASE": "https://api.example.com" } } ``` -------------------------------- ### Example Usage of JsonReader CreateHammer Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Illustrates initializing a JsonReader with configuration data and then creating a Hammer object. The Hammer object's Validate method can then be called. ```go configJSON := loadConfigFile("test.json") reader := &config.JsonReader{} reader.Init(configJSON) hammer, err := reader.CreateHammer() hammer.Validate() ``` -------------------------------- ### ScenarioService.Run Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Executes the scenario, reading iteration indices from input channel and sending results. This method is used to start the scenario execution after initialization. ```APIDOC ## ScenarioService.Run ### Description Executes the scenario, reading iteration indices from input channel and sending results. ### Method ```go func (s *ScenarioService) Run(input <-chan int) <-chan *types.ScenarioResult ``` ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters - **input** (`<-chan int`) - Required - Channel to read iteration indices from ### Response #### Success Response - **<-chan *types.ScenarioResult** - Channel that sends scenario results for each iteration. ### Request Example ```go scenario := types.Scenario{ Steps: []types.ScenarioStep{...}, Envs: map[string]interface{}{ "url": "https://example.com"}, } ss := scenario.NewScenarioService() ss.Init(ctx, scenario, []*url.URL{nil}, scenario.ScenarioOpts{ EngineMode: "distinct-user", }) iterChan := make(chan int) resultChan := ss.Run(iterChan) go func() { for i := 0; i < 100; i++ { iterChan <- i } close(iterChan) }() for result := range resultChan { log.Printf("Iteration completed: %d steps", len(result.StepResults)) } ``` ``` -------------------------------- ### Multiple Test-Wide Assertion Rules Source: https://github.com/getanteon/anteon/blob/master/_autodocs/06-scripting.md Example demonstrating multiple test-wide assertion rules using percentile and aggregate functions, including 'abort' and 'delay' options. ```json { "success_criterias": [ { "rule": "p99(iteration_duration) < 5000", "abort": false }, { "rule": "p90(iteration_duration) < 2000", "abort": true, "delay": 10 }, { "rule": "fail_count < 1", "abort": true, "delay": 0 }, { "rule": "fail_count_perc < 0.05", "abort": false } ] } ``` -------------------------------- ### Add DDoSify to Oh My Zsh Plugins Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/completions/README.md Installs DDoSify Zsh completions by creating a plugin directory within Oh My Zsh and copying the completion script. It also shows how to enable the plugin in your `.zshrc` file. ```bash mkdir -p ~/.oh-my-zsh/plugins/ddosify cp completions/_ddosify ~/.oh-my-zsh/plugins/ddosify ``` ```bash # ~/.zshrc plugins=( ... ddosify ) ``` -------------------------------- ### Processing Assertion Failures Source: https://github.com/getanteon/anteon/blob/master/_autodocs/05-errors.md Example code demonstrating how to iterate through failed rules from an assertion result and log relevant information. It also checks if the test was aborted due to failures. ```go result := <-assertionResultChan if result.Fail { for _, failedRule := range result.FailedRules { log.Printf("Assertion failed: %s", failedRule.Rule) log.Printf("Received: %v", failedRule.ReceivedMap) } if result.Aborted { log.Println("Test was aborted due to assertion failure") } } ``` -------------------------------- ### Example Assertion Flow Configuration Source: https://github.com/getanteon/anteon/blob/master/_autodocs/06-scripting.md This JSON configuration defines success criteria for assertions, including a rule to check the 90th percentile of iteration duration. It specifies that the test should abort if the rule is violated, with an optional delay before aborting. ```json { "success_criterias": [ { "rule": "p90(iteration_duration) < 1000", "abort": true, "delay": 5 } ] } ``` -------------------------------- ### Initialize Scenario Service Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Initializes the scenario service with the test scenario, proxies, and execution options. Ensure context is valid. ```go func (s *ScenarioService) Init(ctx context.Context, scenario types.Scenario, proxies []*url.URL, opts ScenarioOpts) error ``` -------------------------------- ### Engine Init Method Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Initializes the engine after creation. This step involves loading test data from CSV files and preparing the internal state for test execution. ```go if err := engine.Init(); err != nil { log.Fatal("Initialization failed:", err) } ``` -------------------------------- ### Execute Basic Test with JSON Configuration Source: https://github.com/getanteon/anteon/blob/master/_autodocs/08-examples.md Loads configuration from a JSON byte slice, validates it, and runs a basic load test. Handles graceful shutdown via context cancellation. ```go package main import ( "context" "log" "os" "os/signal" "go.ddosify.com/ddosify/config" "go.ddosify.com/ddosify/core" "go.ddosify.com/ddosify/core/types" ) func main() { // Load configuration configBytes := []byte(`{ "iteration_count": 100, "load_type": "linear", "steps": [{ "id": 1, "url": "https://api.example.com/data", "method": "GET" }] }`) // Parse JSON config reader, err := config.NewConfigReader(configBytes, config.ConfigTypeJson) if err != nil { log.Fatal(err) } hammer, err := reader.CreateHammer() if err != nil { log.Fatal(err) } // Validate configuration if err := hammer.Validate(); err != nil { log.Fatal(err) } // Initialize services services, err := core.InitEngineServices(hammer) if err != nil { log.Fatal(err) } // Create engine ctx, cancel := context.WithCancel(context.Background()) defer cancel() engine, err := core.NewEngine(ctx, hammer, services) if err != nil { log.Fatal(err) } // Initialize engine (loads CSV data, etc.) if err := engine.Init(); err != nil { log.Fatal(err) } // Handle Ctrl+C go func() { sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, os.Interrupt) <-sigChan cancel() }() // Run test engine.Start() // Check results if engine.IsTestFailed() { log.Println("Test failed!") os.Exit(1) } else { log.Println("Test passed!") } } ``` -------------------------------- ### ScenarioService.Init Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Initializes the scenario with proxies and options. This method must be called before running a scenario. ```APIDOC ## ScenarioService.Init ### Description Initializes the scenario with proxies and options. ### Method ```go func (s *ScenarioService) Init(ctx context.Context, scenario types.Scenario, proxies []*url.URL, opts ScenarioOpts) error ``` ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters - **ctx** (`context.Context`) - Required - Context for request lifecycle - **scenario** (`types.Scenario`) - Required - Test scenario definition - **proxies** (`[]*url.URL`) - Required - List of proxies to use - **opts** (`ScenarioOpts`) - Required - Execution options ### ScenarioOpts ```go type ScenarioOpts struct { Debug bool IterationCount int MaxConcurrentIterCount int EngineMode string InitialCookies []*http.Cookie } ``` ``` -------------------------------- ### Contains Assertion Example Source: https://github.com/getanteon/anteon/blob/master/_autodocs/06-scripting.md Example of using the 'contains' assertion to check if a field includes a specific substring. Useful for validating response bodies or headers. ```json { "assertion": [ "contains(body, \"success\")", "contains(body, \"user_id=123\")" ] } ``` -------------------------------- ### Create a Test Configuration Source: https://github.com/getanteon/anteon/blob/master/_autodocs/INDEX.md Use this snippet to create a new test configuration object from JSON bytes. ```go reader, _ := config.NewConfigReader(configBytes, config.ConfigTypeJson) hammer, _ := reader.CreateHammer() hammer.Validate() ``` -------------------------------- ### Captured Variable Scoping Example Source: https://github.com/getanteon/anteon/blob/master/_autodocs/06-scripting.md Captured variables are available only after their definition step. This example shows a variable captured in step 1 being used in step 2. ```json { "steps": [ { "id": 1, "capture_env": {"TOKEN": {...}} }, { "id": 2 // Can use {{TOKEN}} here } ] } ``` -------------------------------- ### In List Assertion Example Source: https://github.com/getanteon/anteon/blob/master/_autodocs/06-scripting.md Example of using the 'in' assertion to verify if a value exists within a predefined list of acceptable values. Applicable to status codes or variable values. ```json { "assertion": [ "in(status_code, [200, 201, 204])", "in(variables.user_type, [\"admin\", \"user\"])" ] } ``` -------------------------------- ### Range Assertion Example Source: https://github.com/getanteon/anteon/blob/master/_autodocs/06-scripting.md Example of using the 'range' assertion to check if a numeric field falls within a specified minimum and maximum value (inclusive). Useful for status codes or content lengths. ```json { "assertion": [ "range(status_code, 200, 299)", "range(headers.content-length, 1000, 10000)" ] } ``` -------------------------------- ### Create Scenario Service Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Creates an uninitialized scenario service. Use this before calling Init. ```go func NewScenarioService() *ScenarioService ``` -------------------------------- ### Handle Proxy Service Initialization Errors Source: https://github.com/getanteon/anteon/blob/master/_autodocs/05-errors.md Use this when initializing the proxy service. It catches errors related to unsupported proxy strategies or invalid proxy URLs. ```go proxyService, err := proxy.NewProxyService("invalid_strategy") // Error: "unsupported proxy strategy: invalid_strategy" ``` -------------------------------- ### Engine.IsTestFailed Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Returns whether the test failed based on assertion results. This should be checked after `Start()` completes. ```APIDOC ## Engine.IsTestFailed ### Description Returns whether the test failed based on assertion results. This should be checked after `Start()` completes. ### Method `IsTestFailed()` ### Parameters None ### Request Example ```go engine.Start() if engine.IsTestFailed() { os.Exit(1) } ``` ### Response #### Success Response - **bool** - `true` if assertions failed or requests had errors, `false` otherwise. ``` -------------------------------- ### Parameterization on Config File Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Utilize dynamic variables within a configuration file for URL parameters and headers, enabling complex test scenarios. ```bash ddosify -config ddosify_config_dynamic.json ``` ```json { "iteration_count": 100, "load_type": "linear", "duration": 10, "steps": [ { "id": 1, "url": "https://getanteon.com/?key={{_randomString}}", "method": "POST", "headers": { "User-Key": "{{_randomInt}}" } } ] } ``` -------------------------------- ### Engine.Init Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Initializes the engine, loading test data from CSV files and preparing internal state. ```APIDOC ## Engine.Init ### Description Initializes the engine, loading test data from CSV files and preparing internal state. ### Method `Init()` ### Parameters None ### Request Example ```go if err := engine.Init(); err != nil { log.Fatal("Initialization failed:", err) } ``` ### Response #### Success Response Returns `nil` if initialization is successful. #### Error Response Returns an error if CSV data loading or initialization fails. ``` -------------------------------- ### ResultListener Interface Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Interface for processing scenario results. It provides methods to start processing results and signal completion. ```APIDOC ## ResultListener Interface ### Description Interface for processing scenario results. ### Methods - `Start(input <-chan *types.ScenarioResult)`: Begin processing results from channel. - `DoneChan() <-chan struct{}`: Signal when result processing completes. ``` -------------------------------- ### Ddosify Incremental Load Test Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Example of running an incremental load test. This type of test gradually increases the load. ```bash ddosify -t https://getanteon.com -l incremental ``` -------------------------------- ### Simple Load Test Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Run a basic load test with default settings. This command sends 100 requests over 10 seconds to the specified URL. ```bash ddosify -t https://getanteon.com ``` -------------------------------- ### Example of Hammer Validation Error Source: https://github.com/getanteon/anteon/blob/master/_autodocs/05-errors.md Demonstrates how hammer validation fails with an unsupported LoadType, resulting in a specific error message. ```go hammer := types.Hammer{ IterationCount: 100, LoadType: "invalid_type", Scenario: scenario, } err := hammer.Validate() // Error: "unsupported LoadType: invalid_type" ``` -------------------------------- ### Engine IsTestFailed Method Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Checks if the test has failed based on assertion results. This method should be called after the `Start()` method has completed. ```go engine.Start() if engine.IsTestFailed() { os.Exit(1) } ``` -------------------------------- ### Multipart Form Data with Name-Value Pairs Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Example of sending form data including simple name-value pairs using multipart/form-data. ```json "payload_multipart": [ { "name": "[field-name]", "value": "[field-value]" } ] ``` -------------------------------- ### Load TLS Certificate and Key Source: https://github.com/getanteon/anteon/blob/master/_autodocs/05-errors.md Parses TLS certificate and key files, returning a tls.Certificate and a CertPool. Handles file not found and parsing errors. ```go func ParseTLS(certFile, keyFile string) (tls.Certificate, *x509.CertPool, error) ``` -------------------------------- ### NewEngine Constructor Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Constructs a new Engine instance. Requires a context, hammer configuration, and initialized engine services. The context is used to manage the test lifecycle. ```go import ( "context" "go.ddosify.com/ddosify/core" "go.ddosify.com/ddosify/core/types" ) hammer := types.Hammer{ IterationCount: 100, LoadType: "linear", Scenario: scenario, } es, err := core.InitEngineServices(hammer) if err != nil { log.Fatal(err) } ctx, cancel := context.WithCancel(context.Background()) deferr cancel() engine, err := core.NewEngine(ctx, hammer, es) if err != nil { log.Fatal(err) } ``` -------------------------------- ### ReportService Interface Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Interface for result output and reporting implementations. It provides methods to initialize, start processing results, and signal completion. ```APIDOC ## ReportService Interface ### Description Interface for result output and reporting implementations. It provides methods to initialize, start processing results, and signal completion. ### Methods - `Init(debug bool, samplingRate int)`: Configure output (debug mode, sampling rate). - `Start(input chan *types.ScenarioResult, assertionResultChan <-chan assertion.TestAssertionResult)`: Begin listening for results and writing output. - `DoneChan() <-chan bool`: Signal channel when reporting completes. ``` -------------------------------- ### Handle Report Service Initialization Errors Source: https://github.com/getanteon/anteon/blob/master/_autodocs/05-errors.md Use this when initializing the report service. It catches errors related to unsupported output types. ```go reportService, err := report.NewReportService("custom_format") // Error: "unsupported output type: custom_format" ``` -------------------------------- ### Ddosify Waved Load Test Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Example of running a waved load test. This test pattern involves cyclical increases and decreases in load. ```bash ddosify -t https://getanteon.com -l waved ``` -------------------------------- ### Fail Count Percentage Aggregate Assertion Source: https://github.com/getanteon/anteon/blob/master/_autodocs/06-scripting.md Example of using the 'fail_count_perc' aggregate function in test-wide assertions to limit the percentage of failed requests. ```json { "rule": "fail_count_perc < 0.05" } ``` -------------------------------- ### Fail Count Aggregate Assertion Source: https://github.com/getanteon/anteon/blob/master/_autodocs/06-scripting.md Example of using the 'fail_count' aggregate function in test-wide assertions to limit the total number of failed requests. ```json { "rule": "fail_count < 5" } ``` -------------------------------- ### Load Test with Test Data from CSV Source: https://github.com/getanteon/anteon/blob/master/ddosify_engine/README.md Run a load test by loading test data from a CSV file using a configuration file. This allows tagging specific columns for use in request URLs, headers, and payloads. ```bash ddosify -config ddosify_data_csv.json ``` -------------------------------- ### Define ScenarioResult Type Source: https://github.com/getanteon/anteon/blob/master/_autodocs/02-types.md Represents the outcome of a complete scenario execution. Includes start time, proxy used, and results of individual steps. ```go type ScenarioResult struct { StartTime time.Time ProxyAddr *url.URL StepResults []*ScenarioStepResult Others map[string]interface{} } ``` -------------------------------- ### Run Scenario Execution Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Executes the initialized scenario. Reads iteration indices from the input channel and returns results via the output channel. Ensure the input channel is closed after all iterations are sent. ```go func (s *ScenarioService) Run(input <-chan int) <-chan *types.ScenarioResult ``` ```go scenario := types.Scenario{ Steps: []types.ScenarioStep{...}, Envs: map[string]interface{}{ "url": "https://example.com"}, } ss := scenario.NewScenarioService() ss.Init(ctx, scenario, []*url.URL{nil}, scenario.ScenarioOpts{ EngineMode: "distinct-user", }) iterChan := make(chan int) resultChan := ss.Run(iterChan) go func() { for i := 0; i < 100; i++ { iterChan <- i } close(iterChan) }() for result := range resultChan { log.Printf("Iteration completed: %d steps", len(result.StepResults)) } ``` -------------------------------- ### Test Configuration with Environment Variables Source: https://github.com/getanteon/anteon/blob/master/_autodocs/08-examples.md This configuration utilizes environment variables to parameterize requests. It shows how to use variables for base URLs, API versions, dynamic values, and timeouts. ```json { "iteration_count": 50, "load_type": "linear", "duration": 15, "env": { "API_BASE": "https://api.example.com", "API_VERSION": "v2", "ADMIN_IDS": [1, 2, 3, 4, 5], "TIMEOUT": 10 }, "steps": [ { "id": 1, "url": "{{API_BASE}}/api/{{API_VERSION}}/users/{{rand(ADMIN_IDS)}}", "method": "GET", "timeout": "{{TIMEOUT}}", "headers": { "X-Request-ID": "{{_randomInt}}" } } ] } ``` -------------------------------- ### Percentile Functions for Test-Wide Assertions Source: https://github.com/getanteon/anteon/blob/master/_autodocs/06-scripting.md Example of using percentile functions (p50, p90, p99, p100) for test-wide assertions. These evaluate aggregate metrics across all requests. ```json { "success_criterias": [ { "rule": "p90(iteration_duration) < 1000", "abort": false }, { "rule": "p50(iteration_duration) < 500" } ] } ``` -------------------------------- ### Complete Scenario with Scripting Source: https://github.com/getanteon/anteon/blob/master/_autodocs/06-scripting.md This JSON defines a complete load testing scenario using scripting for assertions and environment variables. It includes steps for login, profile retrieval, and profile updates, with validation at each stage. ```json { "iteration_count": 50, "load_type": "linear", "duration": 30, "env": { "API_BASE": "https://api.example.com", "ADMIN_USERS": [1, 2, 3], "TIMEOUT": 5 }, "data": { "users": { "path": "test_users.csv", "vars": { "0": {"tag": "username"}, "1": {"tag": "password"} } } }, "success_criterias": [ { "rule": "p90(iteration_duration) < 2000", "abort": true, "delay": 5 }, { "rule": "fail_count < 2", "abort": false } ], "steps": [ { "id": 1, "name": "Login", "url": "{{API_BASE}}/auth/login", "method": "POST", "timeout": "{{TIMEOUT}}", "payload": "{\"username\": \"{{data.users.username}}\", \"password\": \"{{data.users.password}}\"}", "capture_env": { "AUTH_TOKEN": { "from": "body", "json_path": "$.access_token" }, "USER_ID": { "from": "body", "json_path": "$.user.id" } }, "assertion": [ "equals(status_code, 200)", "contains(body, \"access_token\")" ] }, { "id": 2, "name": "Get User Profile", "url": "{{API_BASE}}/users/{{USER_ID}}", "method": "GET", "headers": { "Authorization": "Bearer {{AUTH_TOKEN}}", "X-Request-ID": "{{_randomInt}}" }, "assertion": [ "equals(status_code, 200)", "in(headers.content-type, [\"application/json\", \"text/json\"])" ] }, { "id": 3, "name": "Update Profile", "url": "{{API_BASE}}/users/{{USER_ID}}", "method": "PUT", "headers": { "Authorization": "Bearer {{AUTH_TOKEN}}" }, "payload": "{\"name\": \"Updated {{data.users.username}}\"}", "assertion": [ "equals(status_code, 200)" ] } ] } ``` -------------------------------- ### NewConfigReader Factory Function Source: https://github.com/getanteon/anteon/blob/master/_autodocs/03-api-core.md Creates a configuration reader based on the provided configuration data and type. Use this factory to abstract the underlying configuration format. ```go func NewConfigReader(config []byte, configType string) (ConfigReader, error) ``` -------------------------------- ### Validate Configuration Before Running Source: https://github.com/getanteon/anteon/blob/master/_autodocs/05-errors.md Always validate configurations before execution. This snippet shows how to check for specific validation errors and log fatal messages. ```go // Always validate before running err := hammer.Validate() if err != nil { // Check if it's a validation-time error var validationErr types.ScenarioValidationError if errors.As(err, &validationErr) { log.Fatalf("Configuration invalid: %v", validationErr) } log.Fatalf("Unexpected error: %v", err) } ```