Skip to content

Commit 75ce3a9

Browse files
Merge pull request #168 from splunk/test/sc4s_arg
Test/sc4s arg
2 parents bc5623f + b580513 commit 75ce3a9

File tree

7 files changed

+19
-11
lines changed

7 files changed

+19
-11
lines changed

pytest_splunk_addon/splunk.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ def pytest_addoption(parser):
172172
default="514",
173173
help="SC4S Port. default is 514",
174174
)
175+
group.addoption(
176+
"--thread-count",
177+
action="store",
178+
default=20,
179+
dest="thread_count",
180+
help=(
181+
"Thread count for Data ingestion"
182+
),
183+
)
175184
group.addoption(
176185
"--search-index",
177186
action="store",
@@ -503,7 +512,8 @@ def splunk_ingest_data(request, splunk_hec_uri, sc4s):
503512
"sc4s_host": sc4s[0], # for sc4s
504513
"sc4s_port": sc4s[1][514] # for sc4s
505514
}
506-
IngestorHelper.ingest_events(ingest_meta_data, addon_path, config_path)
515+
thread_count = int(request.config.getoption("thread_count"))
516+
IngestorHelper.ingest_events(ingest_meta_data, addon_path, config_path, thread_count)
507517
sleep(50)
508518
if ("PYTEST_XDIST_WORKER" in os.environ):
509519
with open(os.environ.get("PYTEST_XDIST_TESTRUNUID") + "_wait", "w+"):

pytest_splunk_addon/standard_lib/event_ingestors/base_event_ingestor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ def __init__(self, required_configs):
1111
pass
1212

1313
@abc.abstractmethod
14-
def ingest(self, event_object):
14+
def ingest(self, event_object, thread_count):
1515
raise NotImplementedError

pytest_splunk_addon/standard_lib/event_ingestors/hec_event_ingestor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, required_configs):
3232
self.hec_uri = required_configs.get("splunk_hec_uri")
3333
self.session_headers = required_configs.get("session_headers")
3434

35-
def ingest(self, events):
35+
def ingest(self, events, thread_count):
3636
"""
3737
Ingests event and metric data into splunk using HEC token via event endpoint.
3838

pytest_splunk_addon/standard_lib/event_ingestors/hec_metric_ingestor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, required_configs):
3131
self.hec_uri = required_configs.get('splunk_hec_uri')
3232
self.session_headers = required_configs.get('session_headers')
3333

34-
def ingest(self, data):
34+
def ingest(self, data, thread_count):
3535
"""
3636
Ingests event and metric data into splunk using HEC token via event endpoint.
3737
Args:

pytest_splunk_addon/standard_lib/event_ingestors/hec_raw_ingestor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, required_configs):
3232
self.hec_uri = required_configs['splunk_hec_uri']
3333
self.session_headers = required_configs['session_headers']
3434

35-
def ingest(self, events):
35+
def ingest(self, events, thread_count):
3636
"""
3737
Ingests data into splunk via raw endpoint.
3838

pytest_splunk_addon/standard_lib/event_ingestors/ingestor_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_event_ingestor(cls, input_type, ingest_meta_data):
3030
return ingestor
3131

3232
@classmethod
33-
def ingest_events(cls, ingest_meta_data, addon_path, config_path):
33+
def ingest_events(cls, ingest_meta_data, addon_path, config_path, thread_count):
3434
"""
3535
Events are ingested in the splunk.
3636
Args:
@@ -57,4 +57,4 @@ def ingest_events(cls, ingest_meta_data, addon_path, config_path):
5757
for input_type, events in ingestor_dict.items():
5858

5959
event_ingestor = cls.get_event_ingestor(input_type, ingest_meta_data)
60-
event_ingestor.ingest(events)
60+
event_ingestor.ingest(events, thread_count)

pytest_splunk_addon/standard_lib/event_ingestors/sc4s_event_ingestor.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import concurrent.futures
66
from .base_event_ingestor import EventIngestor
77

8-
THREAD_POOL = 20
9-
108

119
class SC4SEventIngestor(EventIngestor):
1210
"""
@@ -28,7 +26,7 @@ def __init__(self, required_configs):
2826
self.sc4s_port = required_configs['sc4s_port']
2927
self.server_address = (required_configs['sc4s_host'], required_configs['sc4s_port'])
3028

31-
def ingest(self, events):
29+
def ingest(self, events, thread_count):
3230
"""
3331
Ingests events in the splunk via sc4s (Single/Batch of Events)
3432
@@ -40,7 +38,7 @@ def ingest(self, events):
4038
for event in events:
4139
raw_events.extend(event.event.splitlines())
4240

43-
with concurrent.futures.ThreadPoolExecutor(max_workers=THREAD_POOL) as executor:
41+
with concurrent.futures.ThreadPoolExecutor(max_workers=thread_count) as executor:
4442
_ = list(executor.map(self.ingest_event, raw_events))
4543

4644
def ingest_event(self, event):

0 commit comments

Comments
 (0)