This document provides testing instructions for the pipe-delimited usecase filtering functionality in Logstory's Cloud Run deployment. This feature allows you to filter which usecases are processed when using replay all by setting the LOGSTORY_USECASES environment variable.
The LOGSTORY_USECASES environment variable filtering feature allows you to:
- Use
replay allcommand with selective usecase processing - Avoid gcloud argument parsing issues entirely
- Filter usecases using pipe-separated values (e.g.,
NETWORK_ANALYSIS|GITHUB) - Maintain backward compatibility - no filtering variable means process all usecases
When LOGSTORY_USECASES is set, the replay all command:
- Parses the pipe-separated usecase list
- Validates that all requested usecases exist
- Only processes the specified usecases instead of all available ones
- Provides clear feedback about which usecases are being processed
Set up your development environment:
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate
# Install in editable mode
pip install -e .
# Set required environment variables
export LOGSTORY_CUSTOMER_ID=your-uuid
export LOGSTORY_CREDENTIALS_PATH=/path/to/credentials.json
export LOGSTORY_REGION=US
export LOGSTORY_API_TYPE=rest# Should process all available usecases
logstory replay all --local-file-output
# Expected output: "Processing all usecases: NETWORK_ANALYSIS, RULES_SEARCH_WORKSHOP, ..."# Filter to single usecase
LOGSTORY_USECASES=NETWORK_ANALYSIS logstory replay all --local-file-output
# Expected output: "Processing filtered usecases: NETWORK_ANALYSIS"# Filter to multiple usecases
LOGSTORY_USECASES=NETWORK_ANALYSIS\|RULES_SEARCH_WORKSHOP logstory replay all --local-file-output
# Expected output: "Processing filtered usecases: NETWORK_ANALYSIS, RULES_SEARCH_WORKSHOP"# Test with invalid usecase
LOGSTORY_USECASES=INVALID_USECASE logstory replay all --local-file-output
# Expected: Error message listing available usecasesEnsure your Cloud Run environment is set up:
# Set required environment variables
export LOGSTORY_API_TYPE=rest
export LOGSTORY_CUSTOMER_ID=your-uuid
export LOGSTORY_PROJECT_ID=your-project-id
export LOGSTORY_REGION=US
# Build and deploy updated Docker image
make build
make docker-build# Process all usecases (no filtering)
gcloud run jobs execute logstory-replay \
--region us-central1 \
--args "logstory,replay,all" \
--wait# Filter to single usecase
gcloud run jobs execute logstory-replay \
--region us-central1 \
--args "logstory,replay,all" \
--update-env-vars "LOGSTORY_USECASES=NETWORK_ANALYSIS" \
--wait# Filter to multiple usecases using pipe separator
gcloud run jobs execute logstory-replay \
--region us-central1 \
--args "logstory,replay,all" \
--update-env-vars "LOGSTORY_USECASES=NETWORK_ANALYSIS|RULES_SEARCH_WORKSHOP" \
--wait# Combine filtering with entities and custom timestamp delta
gcloud run jobs execute logstory-replay \
--region us-central1 \
--args "logstory,replay,all,--entities" \
--update-env-vars "LOGSTORY_USECASES=NETWORK_ANALYSIS,LOGSTORY_TIMESTAMP_DELTA=3d" \
--wait# Get the latest execution name
EXECUTION_NAME=$(gcloud run jobs executions list \
--job logstory-replay \
--region us-central1 \
--limit 1 \
--format "value(name)")
# Check if it completed successfully
gcloud run jobs executions describe $EXECUTION_NAME \
--region us-central1 \
--format "value(status.conditions[0].status)"# Install beta components if needed
gcloud components install beta --quiet
# View execution logs
gcloud beta run jobs executions logs read $EXECUTION_NAME --region us-central1Look for these patterns in the logs:
Filtered Processing:
Processing filtered usecases: NETWORK_ANALYSIS, RULES_SEARCH_WORKSHOP
Processing usecase: NETWORK_ANALYSIS, logtype: BRO_JSON
Processing usecase: RULES_SEARCH_WORKSHOP, logtype: POWERSHELL
Successfully posted entries using RestIngestionBackend
Normal Processing:
Processing all usecases: NETWORK_ANALYSIS, RULES_SEARCH_WORKSHOP, THW2
Error Handling:
Error: Invalid usecases: INVALID_NAME
Available usecases: NETWORK_ANALYSIS, RULES_SEARCH_WORKSHOP, THW2
Solution: Check execution logs for specific error messages and verify environment variables are set correctly.
Solution: Verify the Docker image was rebuilt and deployed after code changes. Check that LOGSTORY_USECASES environment variable is correctly set.
Solution: Run logstory usecases list-installed to see available usecases, or check the error message for the list of valid options.
# Check job configuration
gcloud run jobs describe logstory-replay --region us-central1
# List recent executions
gcloud run jobs executions list \
--job logstory-replay \
--region us-central1 \
--limit 5
# Check environment variables in job
gcloud run jobs describe logstory-replay \
--region us-central1 \
--format "value(spec.template.template.spec.template.spec.containers[0].env[])"- No gcloud parsing issues - Environment variables avoid command-line argument parsing problems
- Clean command structure - Simple
logstory,replay,allarguments - Flexible filtering - Easy to specify any combination of usecases
- Backward compatible - Existing behavior preserved when no filtering is specified
- Clear feedback - Logs clearly show which usecases are being processed
# Test locally first
LOGSTORY_USECASES=NETWORK_ANALYSIS|RULES_SEARCH_WORKSHOP logstory replay all --local-file-output
# Deploy to Cloud Run
make build && make docker-build
# Test in Cloud Run
gcloud run jobs execute logstory-replay \
--region us-central1 \
--args "logstory,replay,all" \
--update-env-vars "LOGSTORY_USECASES=NETWORK_ANALYSIS|RULES_SEARCH_WORKSHOP" \
--wait# Set environment variables in .env file or Cloud Run job configuration
LOGSTORY_USECASES=PRODUCTION_USECASE_1|PRODUCTION_USECASE_2
# Deploy with scheduled execution
gcloud run jobs execute logstory-replay \
--region us-central1 \
--args "logstory,replay,all" \
--waitThis implementation provides a clean, reliable solution for filtering usecases in Cloud Run deployments while maintaining full backward compatibility and avoiding all gcloud argument parsing issues.