-
Notifications
You must be signed in to change notification settings - Fork 2k
out_splunk: Add auto_extract_timestamp parameter #12143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cosmo0920
wants to merge
2
commits into
master
Choose a base branch
from
cosmo0920-extract-timestamp-automatically-on-out_splunk
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
tests/integration/scenarios/out_splunk/config/out_splunk_auto_extract_timestamp.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| service: | ||
| flush: 1 | ||
| log_level: info | ||
| http_server: on | ||
| http_port: ${FLUENT_BIT_HTTP_MONITORING_PORT} | ||
| pipeline: | ||
| inputs: | ||
| - name: dummy | ||
| tag: out_splunk | ||
| dummy: '{"message":"2022-06-13 12:34:56 example event"}' | ||
| samples: 1 | ||
| outputs: | ||
| - name: splunk | ||
| match: out_splunk | ||
| host: 127.0.0.1 | ||
| port: ${TEST_SUITE_HTTP_PORT} | ||
| tls: off | ||
| splunk_token: secret-token | ||
| auto_extract_timestamp: true |
20 changes: 20 additions & 0 deletions
20
.../integration/scenarios/out_splunk/config/out_splunk_auto_extract_timestamp_event_key.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| service: | ||
| flush: 1 | ||
| log_level: info | ||
| http_server: on | ||
| http_port: ${FLUENT_BIT_HTTP_MONITORING_PORT} | ||
| pipeline: | ||
| inputs: | ||
| - name: dummy | ||
| tag: out_splunk | ||
| dummy: '{"message":"2022-06-13 12:34:56 example event"}' | ||
| samples: 1 | ||
| outputs: | ||
| - name: splunk | ||
| match: out_splunk | ||
| host: 127.0.0.1 | ||
| port: ${TEST_SUITE_HTTP_PORT} | ||
| tls: off | ||
| splunk_token: secret-token | ||
| event_key: $message | ||
| auto_extract_timestamp: true |
18 changes: 18 additions & 0 deletions
18
tests/integration/scenarios/out_splunk/config/out_splunk_default.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| service: | ||
| flush: 1 | ||
| log_level: info | ||
| http_server: on | ||
| http_port: ${FLUENT_BIT_HTTP_MONITORING_PORT} | ||
| pipeline: | ||
| inputs: | ||
| - name: dummy | ||
| tag: out_splunk | ||
| dummy: '{"message":"2022-06-13 12:34:56 example event"}' | ||
| samples: 1 | ||
| outputs: | ||
| - name: splunk | ||
| match: out_splunk | ||
| host: 127.0.0.1 | ||
| port: ${TEST_SUITE_HTTP_PORT} | ||
| tls: off | ||
| splunk_token: secret-token |
94 changes: 94 additions & 0 deletions
94
tests/integration/scenarios/out_splunk/tests/test_out_splunk_001.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import os | ||
|
|
||
| import pytest | ||
| import requests | ||
|
|
||
| from server.http_server import configure_http_response, data_storage, http_server_run | ||
| from utils.test_service import FluentBitTestService | ||
|
|
||
|
|
||
| class Service: | ||
| def __init__(self, config_file): | ||
| self.config_file = os.path.abspath( | ||
| os.path.join(os.path.dirname(__file__), "../config", config_file) | ||
| ) | ||
| self.service = FluentBitTestService( | ||
| self.config_file, | ||
| data_storage=data_storage, | ||
| data_keys=["payloads", "requests"], | ||
| pre_start=self._start_receiver, | ||
| post_stop=self._stop_receiver, | ||
| ) | ||
|
|
||
| def _start_receiver(self, service): | ||
| http_server_run(service.test_suite_http_port) | ||
| configure_http_response(status_code=200, body={"text": "Success", "code": 0}) | ||
| self.service.wait_for_http_endpoint( | ||
| f"http://127.0.0.1:{service.test_suite_http_port}/ping", | ||
| timeout=10, | ||
| interval=0.5, | ||
| ) | ||
|
|
||
| def _stop_receiver(self, service): | ||
| try: | ||
| requests.post( | ||
| f"http://127.0.0.1:{service.test_suite_http_port}/shutdown", | ||
| timeout=2, | ||
| ) | ||
| except requests.RequestException: | ||
| pass | ||
|
|
||
| def start(self): | ||
| self.service.start() | ||
|
|
||
| def stop(self): | ||
| self.service.stop() | ||
|
|
||
| def wait_for_requests(self, minimum_count, timeout=10): | ||
| if os.environ.get("VALGRIND"): | ||
| timeout = max(timeout * 3, 30) | ||
|
|
||
| return self.service.wait_for_condition( | ||
| lambda: data_storage["requests"] | ||
| if len(data_storage["requests"]) >= minimum_count | ||
| else None, | ||
| timeout=timeout, | ||
| interval=0.5, | ||
| description=f"{minimum_count} outbound Splunk requests", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("config_file", "expected_query", "expected_event_type"), | ||
| [ | ||
| ("out_splunk_default.yaml", "", dict), | ||
| ( | ||
| "out_splunk_auto_extract_timestamp.yaml", | ||
| "auto_extract_timestamp=true", | ||
| dict, | ||
| ), | ||
| ( | ||
| "out_splunk_auto_extract_timestamp_event_key.yaml", | ||
| "auto_extract_timestamp=true", | ||
| str, | ||
| ), | ||
| ], | ||
| ids=["default", "auto_extract_timestamp", "auto_extract_timestamp_event_key"], | ||
| ) | ||
| def test_out_splunk_auto_extract_timestamp( | ||
| config_file, expected_query, expected_event_type | ||
| ): | ||
| service = Service(config_file) | ||
| service.start() | ||
|
|
||
| try: | ||
| requests_seen = service.wait_for_requests(1) | ||
| finally: | ||
| service.stop() | ||
|
|
||
| first_request = requests_seen[0] | ||
| assert first_request["path"] == "/services/collector/event" | ||
| assert first_request["query_string"] == expected_query | ||
| assert first_request["headers"].get("Authorization") == "Splunk secret-token" | ||
| assert isinstance(first_request["json"]["event"], expected_event_type) | ||
| assert ("time" in first_request["json"]) == (expected_query == "") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.