From 0d46fe8003eb293ad623907bed07b76ad93088b7 Mon Sep 17 00:00:00 2001 From: Manabu Niseki Date: Sat, 2 Mar 2024 12:55:26 +0900 Subject: [PATCH] refactor: split parallel into analyzer_parallelism & emitter_parallelism --- docs/analyzers/index.md | 2 +- docs/configuration.md | 3 ++- docs/emitters/index.md | 2 +- lib/mihari/analyzers/base.rb | 2 +- lib/mihari/config.rb | 8 ++++++-- lib/mihari/emitters/base.rb | 2 +- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/analyzers/index.md b/docs/analyzers/index.md index 830164df..ba576ae7 100644 --- a/docs/analyzers/index.md +++ b/docs/analyzers/index.md @@ -97,7 +97,7 @@ queries: ### Parallel -`parallel` (`bool`) controls whether to allow parallel execution or not. Optional. Defaults to `false`. Configurable via `PARALLEL` environment variable. +`parallel` (`bool`) controls whether to allow parallel execution or not. Optional. Defaults to `false`. Configurable via `ANALYZER_PARALLELISM` environment variable. ### Pagination Interval diff --git a/docs/configuration.md b/docs/configuration.md index bcf3d2c6..e0f07e31 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -44,10 +44,11 @@ Alternatively you can set values through `.env` file. Values in `.env` file will | Environment Variable | Type | Description | Default | | ------------------------- | ------- | ----------------------------------------- | ------- | +| ANALYZER_PARALLELISM | Boolean | Whether to run analyzers in parallel | `false` | +| EMITTER_PARALLELISM | Boolean | Whether to run emitters in parallel | `true` | | IGNORE_ERROR | Boolean | Whether to ignore error while querying | `false` | | PAGINATION_INTERVAL | Integer | Pagination interval | `0` | | PAGINATION_LIMIT | Integer | Pagination limit | `100` | -| PARALLEL | Boolean | Whether to run queries in parallel | `false` | | RETRY_EXPONENTIAL_BACKOFF | Boolean | Whether to use retry exponential back off | `true` | | RETRY_INTERVAL | Integer | Retry interval | `5` | | RETRY_TIMES | Integer | Retry times | `3` | diff --git a/docs/emitters/index.md b/docs/emitters/index.md index 545f8e4b..db2fccc0 100644 --- a/docs/emitters/index.md +++ b/docs/emitters/index.md @@ -38,4 +38,4 @@ options: ### Parallel -`parallel` (`bool`) controls whether to allow parallel execution or not. Optional. Defaults to `false`. Configurable via `PARALLEL` environment variable. +`parallel` (`bool`) controls whether to allow parallel execution or not. Optional. Defaults to `true`. Configurable via `EMITTER_PARALLELISM` environment variable. diff --git a/lib/mihari/analyzers/base.rb b/lib/mihari/analyzers/base.rb index edc8cd64..c2900cfe 100644 --- a/lib/mihari/analyzers/base.rb +++ b/lib/mihari/analyzers/base.rb @@ -44,7 +44,7 @@ def ignore_error? # @return [Boolean] # def parallel? - options[:parallel] || Mihari.config.parallel + options[:parallel] || Mihari.config.analyzer_parallelism end # @return [Array, Array] diff --git a/lib/mihari/config.rb b/lib/mihari/config.rb index 1aa879c5..7244510a 100644 --- a/lib/mihari/config.rb +++ b/lib/mihari/config.rb @@ -42,7 +42,8 @@ class Config < Anyway::Config ignore_error: false, pagination_interval: 0, pagination_limit: 100, - parallel: false, + analyzer_parallelism: false, + emitter_parallelism: true, retry_exponential_backoff: true, retry_interval: 5, retry_times: 3, @@ -146,7 +147,10 @@ class Config < Anyway::Config # @!attribute [r] pagination_limit # @return [Integer] - # @!attribute [r] parallel + # @!attribute [r] analyzer_parallelism + # @return [Boolean] + + # @!attribute [r] emitter_parallelism # @return [Boolean] # @!attribute [r] ignore_error diff --git a/lib/mihari/emitters/base.rb b/lib/mihari/emitters/base.rb index 8e4eac0a..a1438cbf 100644 --- a/lib/mihari/emitters/base.rb +++ b/lib/mihari/emitters/base.rb @@ -23,7 +23,7 @@ def initialize(rule:, options: nil) # @return [Boolean] # def parallel? - options[:parallel] || Mihari.config.parallel + options[:parallel] || Mihari.config.emitter_parallelism end # A target to emit the data