diff --git a/.github/workflows/docker-helm-ci.yml b/.github/workflows/docker-helm-ci.yml index 6553ee7..239af21 100644 --- a/.github/workflows/docker-helm-ci.yml +++ b/.github/workflows/docker-helm-ci.yml @@ -3,8 +3,11 @@ name: Docker and Helm CI on: push: branches: [ main, master ] + tags: [ 'v*' ] pull_request: branches: [ main, master ] + release: + types: [ published ] workflow_dispatch: jobs: @@ -70,8 +73,9 @@ jobs: rate_normal_min: 0.0001 rate_normal_max: 0.1 rate_peak: 0.500 - log_line_size: 100 - log_line_size_estimate: 100 # Added missing parameter + log_line_size_estimate: 100 + user_agent_pool_size: 100 + max_segment_duration_normal: 5 base_exit_probability: 0.05 rate_change_probability: 0.1 rate_change_max_percentage: 0.1 @@ -91,6 +95,28 @@ jobs: - INFO - WARNING - ERROR + + # HTTP status codes and corresponding messages + http_status_codes: + '200 OK': + - 'API request received' + - 'API response sent' + '400 Bad Request': + - 'Invalid user input detected' + '500 Internal Server Error': + - 'Unexpected error occurred' + + # User agent browsers for generating user agents + user_agent_browsers: + - 'Chrome' + - 'Firefox' + - 'Safari' + + # User agent systems for generating user agents + user_agent_systems: + - 'Windows NT 10.0; Win64; x64' + - 'Macintosh; Intel Mac OS X 13_4' + - 'X11; Linux x86_64' EOF # Run the container with the test config for a short time @@ -227,3 +253,49 @@ jobs: # Clean up helm delete test-release + + docker-publish: + runs-on: ubuntu-latest + needs: [python-tests, docker-build] + if: github.event_name == 'release' || (github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')) + permissions: + contents: read + packages: write + + steps: + - name: Checkout code + uses: actions/checkout@v4.2.2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.10.0 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3.3.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5.6.0 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v6.16.0 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + platforms: linux/amd64,linux/arm64 diff --git a/README.md b/README.md index fb38738..e152f64 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,25 @@ pip install random-log-generator ### Using Docker -You can also run the Random Log Generator using Docker: +You can run the Random Log Generator using Docker in several ways: + +#### Using Pre-built Images from GitHub Container Registry + +```bash +# Pull and run the latest image +docker run -v $(pwd)/logs:/app/logs ghcr.io/sd416/random-log-generator:latest + +# Run a specific version +docker run -v $(pwd)/logs:/app/logs ghcr.io/sd416/random-log-generator:v0.1.0 + +# Run with a custom configuration file +docker run -v $(pwd)/config.yaml:/app/config.yaml -v $(pwd)/logs:/app/logs ghcr.io/sd416/random-log-generator:latest --config config.yaml + +# Run with environment variable overrides +docker run -e LOG_GEN_STOP_AFTER_SECONDS=30 -v $(pwd)/logs:/app/logs ghcr.io/sd416/random-log-generator:latest +``` + +#### Building from Source ```bash # Build the Docker image @@ -47,6 +65,14 @@ docker run -v $(pwd)/logs:/app/logs random-log-generator docker run -v $(pwd)/config.yaml:/app/config.yaml -v $(pwd)/logs:/app/logs random-log-generator --config config.yaml ``` +#### Available Image Tags + +- `latest` - Latest stable release from the main branch +- `v{version}` - Specific version tags (e.g., `v0.1.0`, `v0.2.0`) +- `main` - Latest development build from the main branch + +Images are automatically built for both `linux/amd64` and `linux/arm64` platforms. + ### Using Kubernetes with Helm If you want to deploy the Random Log Generator on a Kubernetes cluster, you can use the provided Helm chart: diff --git a/helm/random-log-generator/templates/configmap.yaml b/helm/random-log-generator/templates/configmap.yaml index c3ef6ee..19ab0bf 100644 --- a/helm/random-log-generator/templates/configmap.yaml +++ b/helm/random-log-generator/templates/configmap.yaml @@ -13,7 +13,9 @@ data: rate_normal_min: {{ .Values.config.rateNormalMin }} rate_normal_max: {{ .Values.config.rateNormalMax }} rate_peak: {{ .Values.config.ratePeak }} - log_line_size: {{ .Values.config.logLineSize }} + log_line_size_estimate: {{ .Values.config.logLineSize }} + user_agent_pool_size: {{ .Values.config.userAgentPoolSize | default 100 }} + max_segment_duration_normal: {{ .Values.config.maxSegmentDurationNormal | default 5 }} base_exit_probability: {{ .Values.config.baseExitProbability }} rate_change_probability: {{ .Values.config.rateChangeProbability }} rate_change_max_percentage: {{ .Values.config.rateChangeMaxPercentage }} @@ -31,4 +33,120 @@ data: log_levels: {{- range .Values.config.logLevels }} - {{ . }} - {{- end }} \ No newline at end of file + {{- end }} + + # HTTP status codes and corresponding messages + http_status_codes: + '200 OK': + - 'API request received' + - 'API response sent' + - 'Application deployment completed' + - 'Application deployment started' + - 'Application rollback completed' + - 'Application rollback initiated' + - 'Backup completed successfully' + - 'Cache cleared' + - 'Configuration updated' + - 'Database connection established' + - 'Data fetched successfully' + - 'Data processed successfully' + - 'Email sent successfully' + - 'File uploaded successfully' + - 'New user registered' + - 'Password change requested' + - 'Password change successful' + - 'Payment transaction completed' + - 'Scheduled task completed' + - 'Scheduled task started' + - 'Service health check passed' + - 'Service started' + - 'Service stopped' + - 'Session token refreshed' + - 'SMS sent successfully' + - 'User account unlocked' + - 'User login successful' + - 'User logged out' + - 'User profile updated' + '400 Bad Request': + - 'Invalid user input detected' + - 'Configuration validation error' + - 'Credit card validation error' + - 'License key expired' + - 'Service rate limit exceeded' + - 'Service quota exceeded' + - 'Request body too large' + - 'Invalid request header' + - 'Missing required parameter' + '401 Unauthorized': + - 'User login failed' + - 'Permission denied' + - 'Unauthorized access attempt detected' + - 'Invalid authentication token' + - 'Authentication token expired' + '403 Forbidden': + - 'Permission denied' + - 'Access to resource forbidden' + - 'Account suspended' + '404 Not Found': + - 'File not found' + - 'Service endpoint deprecated' + - 'Service endpoint removed' + - 'Resource not found' + - 'User not found' + '500 Internal Server Error': + - 'Error fetching data from database' + - 'Unexpected error occurred' + - 'Resource allocation failure' + - 'Database connection lost' + - 'Cache update failed' + - 'Backup failed' + - 'Password change failed' + - 'Service health check failed' + - 'File upload failed' + - 'User profile update failed' + - 'Email delivery failed' + - 'SMS delivery failed' + - 'Payment transaction failed' + - 'User account locked' + - 'Service degraded' + - 'High memory usage detected' + - 'Memory leak detected' + - 'System backup cancelled' + - 'User subscription cancelled' + - 'Trial period ended' + - 'Database migration started' + - 'Database migration completed' + - 'Cloud resource deprovisioned' + - 'API key revoked' + - 'User role update failed' + - 'Service unavailable' + - 'Timeout error' + '503 Service Unavailable': + - 'Service temporarily unavailable' + - 'Maintenance in progress' + - 'Server overloaded' + + # User agent browsers for generating user agents + user_agent_browsers: + - 'Chrome' + - 'Firefox' + - 'Safari' + - 'Edge' + - 'Opera' + - 'Brave' + + # User agent systems for generating user agents + user_agent_systems: + - 'Windows NT 10.0; Win64; x64' + - 'Macintosh; Intel Mac OS X 13_4' + - 'iPhone; CPU iPhone OS 16_5 like Mac OS X' + - 'X11; Linux x86_64' + - 'Linux; Android 13; K' + - 'iPad; CPU OS 16_5 like Mac OS X' + - 'Macintosh; Intel Mac OS X 13_4_1' + - 'Windows NT 10.0; WOW64' + - 'X11; Ubuntu; Linux i686' + - 'Macintosh; Intel Mac OS X 10_15_7' + - 'Linux; Android 13; SM-S918B' + - 'Linux; Android 14; Pixel 7' + - 'ChromeOS; x86_64 15183.78.0' diff --git a/helm/random-log-generator/values.yaml b/helm/random-log-generator/values.yaml index 49e6143..f44b96e 100644 --- a/helm/random-log-generator/values.yaml +++ b/helm/random-log-generator/values.yaml @@ -61,7 +61,9 @@ config: rateNormalMin: 0.0001 rateNormalMax: 0.1 ratePeak: 0.500 - logLineSize: 100 + logLineSize: 100 # This maps to log_line_size_estimate in the config + userAgentPoolSize: 100 # Number of user agents to pre-generate + maxSegmentDurationNormal: 5 # Maximum duration for a single segment during normal log generation baseExitProbability: 0.05 rateChangeProbability: 0.1 rateChangeMaxPercentage: 0.1 @@ -79,4 +81,4 @@ config: - DEBUG - INFO - WARNING - - ERROR \ No newline at end of file + - ERROR diff --git a/random_log_generator/__pycache__/__init__.cpython-313.pyc b/random_log_generator/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..fae0ca3 Binary files /dev/null and b/random_log_generator/__pycache__/__init__.cpython-313.pyc differ diff --git a/random_log_generator/__pycache__/cli.cpython-312.pyc b/random_log_generator/__pycache__/cli.cpython-312.pyc new file mode 100644 index 0000000..e7387f9 Binary files /dev/null and b/random_log_generator/__pycache__/cli.cpython-312.pyc differ diff --git a/random_log_generator/__pycache__/cli.cpython-313.pyc b/random_log_generator/__pycache__/cli.cpython-313.pyc new file mode 100644 index 0000000..f2a43f7 Binary files /dev/null and b/random_log_generator/__pycache__/cli.cpython-313.pyc differ diff --git a/random_log_generator/config/__pycache__/__init__.cpython-313.pyc b/random_log_generator/config/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..1bca20c Binary files /dev/null and b/random_log_generator/config/__pycache__/__init__.cpython-313.pyc differ diff --git a/random_log_generator/config/__pycache__/config_loader.cpython-312.pyc b/random_log_generator/config/__pycache__/config_loader.cpython-312.pyc index f68e01a..c4640bd 100644 Binary files a/random_log_generator/config/__pycache__/config_loader.cpython-312.pyc and b/random_log_generator/config/__pycache__/config_loader.cpython-312.pyc differ diff --git a/random_log_generator/config/__pycache__/config_loader.cpython-313.pyc b/random_log_generator/config/__pycache__/config_loader.cpython-313.pyc new file mode 100644 index 0000000..4e81662 Binary files /dev/null and b/random_log_generator/config/__pycache__/config_loader.cpython-313.pyc differ diff --git a/random_log_generator/config/__pycache__/validators.cpython-312.pyc b/random_log_generator/config/__pycache__/validators.cpython-312.pyc index c9fec79..d0e0720 100644 Binary files a/random_log_generator/config/__pycache__/validators.cpython-312.pyc and b/random_log_generator/config/__pycache__/validators.cpython-312.pyc differ diff --git a/random_log_generator/config/validators.py b/random_log_generator/config/validators.py index 7600659..7ec1a46 100644 --- a/random_log_generator/config/validators.py +++ b/random_log_generator/config/validators.py @@ -27,7 +27,8 @@ 'http_format_logs', 'stop_after_seconds', 'custom_app_names', - 'custom_log_format' + 'custom_log_format', + 'logging_level' ] @@ -83,6 +84,7 @@ def validate_config(config): # Validate string values validate_string(config_params, 'log_file_path') validate_string(config_params, 'custom_log_format') + validate_logging_level(config_params, 'logging_level') # Validate list values validate_list(config_params, 'custom_app_names') @@ -207,3 +209,27 @@ def validate_dict(config, key): error_msg = f"Configuration parameter '{key}' must be a dictionary, got {type(value).__name__}" logging.error(error_msg) raise ValueError(error_msg) + + +def validate_logging_level(config, key): + """ + Validate that a configuration value is a valid logging level. + + Args: + config (dict): Configuration dictionary. + key (str): Key to validate. + + Raises: + ValueError: If the value is not a valid logging level. + """ + value = config[key] + if not isinstance(value, str): + error_msg = f"Configuration parameter '{key}' must be a string, got {type(value).__name__}" + logging.error(error_msg) + raise ValueError(error_msg) + + valid_levels = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] + if value.upper() not in valid_levels: + error_msg = f"Configuration parameter '{key}' must be one of {valid_levels}, got '{value}'" + logging.error(error_msg) + raise ValueError(error_msg) diff --git a/random_log_generator/core/__pycache__/__init__.cpython-312.pyc b/random_log_generator/core/__pycache__/__init__.cpython-312.pyc index 193ec43..5d3c23b 100644 Binary files a/random_log_generator/core/__pycache__/__init__.cpython-312.pyc and b/random_log_generator/core/__pycache__/__init__.cpython-312.pyc differ diff --git a/random_log_generator/core/__pycache__/__init__.cpython-313.pyc b/random_log_generator/core/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..f9a0a0f Binary files /dev/null and b/random_log_generator/core/__pycache__/__init__.cpython-313.pyc differ diff --git a/random_log_generator/core/__pycache__/generator.cpython-312.pyc b/random_log_generator/core/__pycache__/generator.cpython-312.pyc index 6e95fdd..94f64be 100644 Binary files a/random_log_generator/core/__pycache__/generator.cpython-312.pyc and b/random_log_generator/core/__pycache__/generator.cpython-312.pyc differ diff --git a/random_log_generator/core/__pycache__/generator.cpython-313.pyc b/random_log_generator/core/__pycache__/generator.cpython-313.pyc new file mode 100644 index 0000000..0d8ecae Binary files /dev/null and b/random_log_generator/core/__pycache__/generator.cpython-313.pyc differ diff --git a/random_log_generator/core/__pycache__/rate_limiter.cpython-313.pyc b/random_log_generator/core/__pycache__/rate_limiter.cpython-313.pyc new file mode 100644 index 0000000..ba4c4c4 Binary files /dev/null and b/random_log_generator/core/__pycache__/rate_limiter.cpython-313.pyc differ diff --git a/random_log_generator/core/__pycache__/strategies.cpython-312.pyc b/random_log_generator/core/__pycache__/strategies.cpython-312.pyc index 4935d6c..c9ea416 100644 Binary files a/random_log_generator/core/__pycache__/strategies.cpython-312.pyc and b/random_log_generator/core/__pycache__/strategies.cpython-312.pyc differ diff --git a/random_log_generator/core/__pycache__/strategies.cpython-313.pyc b/random_log_generator/core/__pycache__/strategies.cpython-313.pyc new file mode 100644 index 0000000..8e5e11e Binary files /dev/null and b/random_log_generator/core/__pycache__/strategies.cpython-313.pyc differ diff --git a/random_log_generator/formatters/__pycache__/__init__.cpython-313.pyc b/random_log_generator/formatters/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..4a40324 Binary files /dev/null and b/random_log_generator/formatters/__pycache__/__init__.cpython-313.pyc differ diff --git a/random_log_generator/formatters/__pycache__/base.cpython-313.pyc b/random_log_generator/formatters/__pycache__/base.cpython-313.pyc new file mode 100644 index 0000000..909a870 Binary files /dev/null and b/random_log_generator/formatters/__pycache__/base.cpython-313.pyc differ diff --git a/random_log_generator/formatters/__pycache__/custom.cpython-313.pyc b/random_log_generator/formatters/__pycache__/custom.cpython-313.pyc new file mode 100644 index 0000000..ce2a5a1 Binary files /dev/null and b/random_log_generator/formatters/__pycache__/custom.cpython-313.pyc differ diff --git a/random_log_generator/formatters/__pycache__/http.cpython-313.pyc b/random_log_generator/formatters/__pycache__/http.cpython-313.pyc new file mode 100644 index 0000000..74472a4 Binary files /dev/null and b/random_log_generator/formatters/__pycache__/http.cpython-313.pyc differ diff --git a/random_log_generator/metrics/__pycache__/__init__.cpython-313.pyc b/random_log_generator/metrics/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..ae2f892 Binary files /dev/null and b/random_log_generator/metrics/__pycache__/__init__.cpython-313.pyc differ diff --git a/random_log_generator/metrics/__pycache__/collector.cpython-313.pyc b/random_log_generator/metrics/__pycache__/collector.cpython-313.pyc new file mode 100644 index 0000000..54b78e7 Binary files /dev/null and b/random_log_generator/metrics/__pycache__/collector.cpython-313.pyc differ diff --git a/random_log_generator/metrics/__pycache__/reporter.cpython-313.pyc b/random_log_generator/metrics/__pycache__/reporter.cpython-313.pyc new file mode 100644 index 0000000..9ec8e20 Binary files /dev/null and b/random_log_generator/metrics/__pycache__/reporter.cpython-313.pyc differ diff --git a/random_log_generator/output/__pycache__/__init__.cpython-313.pyc b/random_log_generator/output/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..5843f95 Binary files /dev/null and b/random_log_generator/output/__pycache__/__init__.cpython-313.pyc differ diff --git a/random_log_generator/output/__pycache__/base.cpython-313.pyc b/random_log_generator/output/__pycache__/base.cpython-313.pyc new file mode 100644 index 0000000..6d08371 Binary files /dev/null and b/random_log_generator/output/__pycache__/base.cpython-313.pyc differ diff --git a/random_log_generator/output/__pycache__/console_output.cpython-313.pyc b/random_log_generator/output/__pycache__/console_output.cpython-313.pyc new file mode 100644 index 0000000..25daae6 Binary files /dev/null and b/random_log_generator/output/__pycache__/console_output.cpython-313.pyc differ diff --git a/random_log_generator/output/__pycache__/file_output.cpython-313.pyc b/random_log_generator/output/__pycache__/file_output.cpython-313.pyc new file mode 100644 index 0000000..0613769 Binary files /dev/null and b/random_log_generator/output/__pycache__/file_output.cpython-313.pyc differ diff --git a/random_log_generator/output/__pycache__/rotation.cpython-313.pyc b/random_log_generator/output/__pycache__/rotation.cpython-313.pyc new file mode 100644 index 0000000..9cbb891 Binary files /dev/null and b/random_log_generator/output/__pycache__/rotation.cpython-313.pyc differ diff --git a/random_log_generator/utils/__pycache__/__init__.cpython-313.pyc b/random_log_generator/utils/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..caa9be2 Binary files /dev/null and b/random_log_generator/utils/__pycache__/__init__.cpython-313.pyc differ diff --git a/random_log_generator/utils/__pycache__/ip_generator.cpython-313.pyc b/random_log_generator/utils/__pycache__/ip_generator.cpython-313.pyc new file mode 100644 index 0000000..46ce2dd Binary files /dev/null and b/random_log_generator/utils/__pycache__/ip_generator.cpython-313.pyc differ diff --git a/random_log_generator/utils/__pycache__/user_agents.cpython-313.pyc b/random_log_generator/utils/__pycache__/user_agents.cpython-313.pyc new file mode 100644 index 0000000..ec74bf6 Binary files /dev/null and b/random_log_generator/utils/__pycache__/user_agents.cpython-313.pyc differ