Skip to content

Commit

Permalink
bug: lib/bots: fix names of private attributes
Browse files Browse the repository at this point in the history
Make private members `__is_multithreadable` and `__collector_empty_process` protected members `_is_multithreadable` and `_collector_empty_process` to make them easily modifiable by Bot classes

fixes #2108
  • Loading branch information
Sebastian Wagner authored and Wagner committed Sep 10, 2021
1 parent d396543 commit 5c91a8c
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 17 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ CHANGELOG

### Core
- `intelmq.lib.bot.CollectorBot`: Fixed an issue with within the `new_report` function, which re-loads the harmonization file after a new incoming dataset, which leads to CPU drain and decreased performance (PR#2106 by Sebastian Waldbauer, fixes #2098).
- `intelmq.lib.bot.Bot`: Make private members `__is_multithreadable` and `__collector_empty_process` protected members `_is_multithreadable` and `_collector_empty_process` to make them easily modifiable by Bot classes (PR#2109 by Sebastian Wagner, fixes #2108).
Also affected and adapted bots by this change are:
- `intelmq.bots.collectors.api.collector_api`
- `intelmq.bots.collectors.stomp.collector`
- `intelmq.bots.experts.splunk_saved_search.expert`
- `intelmq.bots.experts.threshold.expert`
- `intelmq.bots.outputs.file.output`
- `intelmq.bots.outputs.misp.output_api`
- `intelmq.bots.outputs.misp.output_feed`
- `intelmq.bots.outputs.tcp.output`
- `intelmq.bots.outputs.udp.output`

### Bots
#### Experts
Expand Down
4 changes: 2 additions & 2 deletions intelmq/bots/collectors/api/collector_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class APICollectorBot(CollectorBot):
"""Collect data by exposing a HTTP API interface"""
name: str = "API"
port: int = 5000
__collector_empty_process: bool = True
_collector_empty_process: bool = True
provider: str = "APICollector"
__is_multithreadable: bool = False
_is_multithreadable: bool = False
use_socket = False
socket_path = '/tmp/imq_api_default_socket'
_server: Optional['HTTPServer'] = None
Expand Down
2 changes: 1 addition & 1 deletion intelmq/bots/collectors/stomp/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class StompCollectorBot(CollectorBot):
ssl_client_certificate_key: str = 'client.key' # TODO pathlib.Path
heartbeat: int = 6000

__collector_empty_process: bool = True
_collector_empty_process: bool = True
__conn = False # define here so shutdown method can check for it

def init(self):
Expand Down
2 changes: 1 addition & 1 deletion intelmq/bots/experts/splunk_saved_search/expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SplunkSavedSearchBot(Bot):
search_parameters = {"event field": "search parameter"}
url: str = None

__is_multithreadable = False
_is_multithreadable = False

def init(self):
if requests is None:
Expand Down
2 changes: 1 addition & 1 deletion intelmq/bots/experts/threshold/expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ThresholdExpertBot(Bot, CacheMixin):

_message_processed_verb = 'Forwarded'

__is_multithreadable = False
_is_multithreadable = False
bypass = False

def init(self):
Expand Down
2 changes: 1 addition & 1 deletion intelmq/bots/outputs/file/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FileOutputBot(OutputBot):
message_jsondict_as_string: bool = False
message_with_type: bool = False
single_key: bool = False
__is_multithreadable = False
_is_multithreadable = False

def init(self):
# needs to be done here, because in process() FileNotFoundError handling we call init(),
Expand Down
2 changes: 1 addition & 1 deletion intelmq/bots/outputs/misp/output_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class MISPAPIOutputBot(OutputBot):
misp_url: str = None
significant_fields: list = []

_Bot__is_multithreadable = False
_is_multithreadable = False

def init(self):
if pymisp is None and import_fail_reason == 'syntax':
Expand Down
2 changes: 1 addition & 1 deletion intelmq/bots/outputs/misp/output_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MISPFeedOutputBot(OutputBot):
misp_org_name = None
misp_org_uuid = None
output_dir: str = "/opt/intelmq/var/lib/bots/mispfeed-output" # TODO: should be path
__is_multithreadable: bool = False
_is_multithreadable: bool = False

@staticmethod
def check_output_dir(dirname):
Expand Down
2 changes: 1 addition & 1 deletion intelmq/bots/outputs/tcp/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TCPOutputBot(Bot):
port: int = None
separator: str = None

__is_multithreadable = False
_is_multithreadable = False

def init(self):
self.to_intelmq = self.counterpart_is_intelmq
Expand Down
2 changes: 1 addition & 1 deletion intelmq/bots/outputs/udp/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class UDPOutputBot(Bot):
udp_host: str = "localhost"
udp_port: int = None

__is_multithreadable = False
_is_multithreadable = False

def init(self):
self.delimiter = self.field_delimiter
Expand Down
14 changes: 7 additions & 7 deletions intelmq/lib/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ class Bot(object):
# True for (non-main) threads of a bot instance
is_multithreaded: bool = False
# True if the bot is thread-safe and it makes sense
__is_multithreadable: bool = True
_is_multithreadable: bool = True
# Collectors with an empty process() should set this to true, prevents endless loops (#1364)
__collector_empty_process: bool = False
_collector_empty_process: bool = False

def __init__(self, bot_id: str, start: bool = False, sighup_event=None,
disable_multithreading: bool = None):
Expand Down Expand Up @@ -158,11 +158,11 @@ def __init__(self, bot_id: str, start: bool = False, sighup_event=None,

broker = self.source_pipeline_broker.title()
if broker != 'Amqp':
self.__is_multithreadable = False
self._is_multithreadable = False

""" Multithreading """
if (self.instances_threads > 1 and not self.is_multithreaded and
self.__is_multithreadable and not disable_multithreading):
self._is_multithreadable and not disable_multithreading):
self.logger.handlers = []
num_instances = int(self.instances_threads)
instances = []
Expand All @@ -189,7 +189,7 @@ def handle_sighup_signal_threading(signum: int,
thread.join()
return
elif (getattr(self, 'instances_threads', 1) > 1 and
not self.__is_multithreadable):
not self._is_multithreadable):
self.logger.error('Multithreading is configured, but is not '
'available for this bot. Look at the FAQ '
'for a list of reasons for this. '
Expand Down Expand Up @@ -435,7 +435,7 @@ def start(self, starting: bool = True, error_on_pipeline: bool = True,
if do_rate_limit:
if self.rate_limit and self.run_mode != 'scheduled':
self.__sleep()
if self.__collector_empty_process and self.run_mode != 'scheduled':
if self._collector_empty_process and self.run_mode != 'scheduled':
self.__sleep(1, log=False)

self.__stats()
Expand Down Expand Up @@ -1152,7 +1152,7 @@ class CollectorBot(Bot):
Does some sanity checks on message sending.
"""

__is_multithreadable: bool = False
_is_multithreadable: bool = False
name: Optional[str] = None
accuracy: int = 100
code: Optional[str] = None
Expand Down

0 comments on commit 5c91a8c

Please sign in to comment.