Repository navigation
[yaml] add pubsub to splunk e2e and example tests #40885
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
derrickaw
wants to merge
2
commits into
apache:master
Choose a base branch
from
derrickaw:20261029_splunkE2EYaml
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
87 changes: 87 additions & 0 deletions
87
sdks/python/apache_beam/yaml/examples/transforms/pipelines/pubsub_to_splunk.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,87 @@ | ||
| # coding=utf-8 | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # This is an example of a Beam YAML pipeline that reads messages from a Pub/Sub | ||
| # subscription, transforms them into Splunk HEC events, writes them to Splunk, | ||
| # and routes failed messages to a Pub/Sub deadletter topic. This matches the | ||
| # Dataflow Template located here - | ||
| # https://cloud.google.com/dataflow/docs/guides/templates/provided/pubsub-to-splunk | ||
|
|
||
| pipeline: | ||
| type: composite | ||
| transforms: | ||
| # Step 1: Read messages from a Pub/Sub subscription | ||
| - type: ReadFromPubSub | ||
| name: ReadMessages | ||
| config: | ||
| subscription: "projects/apache-beam-testing/subscriptions/my-subscription" | ||
| format: JSON | ||
| schema: | ||
| type: object | ||
| properties: | ||
| label: {type: string} | ||
| rank: {type: integer} | ||
|
|
||
| # Step 2: Transform input messages and map to Splunk HEC event fields | ||
| - type: MapToFields | ||
| name: ConvertToSplunkEvents | ||
| input: ReadMessages | ||
| config: | ||
| language: python | ||
| fields: | ||
| time: 1700000000 | ||
| host: "'test-host'" | ||
| source: "'apache-beam'" | ||
| sourcetype: "'test-type'" | ||
| index: "'test-index'" | ||
| event: | ||
| callable: | | ||
| def format_event(row): | ||
| return "Event for label " + row.label + " with rank " + str(row.rank) | ||
| output_type: string | ||
|
|
||
| # Step 3: Write events to Splunk's HTTP Event Collector (HEC) endpoint | ||
| - type: WriteToSplunk | ||
| name: WriteToSplunk | ||
| input: ConvertToSplunkEvents | ||
| config: | ||
| url: "https://splunk-hec-host:8088" | ||
| token: "my-splunk-hec-token" | ||
| batch_count: 10 | ||
| parallelism: 1 | ||
| disable_certificate_validation: false | ||
| enable_batch_logs: true | ||
| enable_gzip_http_compression: true | ||
| error_handling: | ||
| output: write_errors | ||
|
|
||
| # Step 4: Write failed records from Splunk HEC writes to a Pub/Sub deadletter topic | ||
| - type: WriteToPubSub | ||
| name: WriteFailedRecords | ||
| input: WriteToSplunk.write_errors | ||
| config: | ||
| topic: "projects/apache-beam-testing/topics/deadletter-topic" | ||
| format: JSON | ||
|
|
||
| options: | ||
| streaming: true | ||
|
|
||
| # Expected: | ||
| # Row(time=1700000000, host='test-host', source='apache-beam', sourcetype='test-type', index='test-index', event='Event for label 37a with rank 1') | ||
| # Row(time=1700000000, host='test-host', source='apache-beam', sourcetype='test-type', index='test-index', event='Event for label 37b with rank 4') | ||
| # Row(time=1700000000, host='test-host', source='apache-beam', sourcetype='test-type', index='test-index', event='Event for label 37c with rank 3') | ||
| # Row(time=1700000000, host='test-host', source='apache-beam', sourcetype='test-type', index='test-index', event='Event for label 37d with rank 2') |
143 changes: 143 additions & 0 deletions
143
sdks/python/apache_beam/yaml/extended_tests/e2e/pubsub_to_splunk.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,143 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| fixtures: | ||
| - name: PUBSUB_VARS | ||
| type: "apache_beam.yaml.integration_tests.temp_pubsub_subscriptions" | ||
| config: | ||
| project_id: "apache-beam-testing" | ||
| - name: FAKE_SPLUNK_SERVER | ||
| type: "apache_beam.yaml.test_utils.splunk_test_utils.temp_fake_splunk_server" | ||
| config: | ||
| expected_records: | ||
| - { time: 1700000000, host: "test-host", source: "apache-beam-11a", sourcetype: "test-type", index: "test-index", event: "Event for label 11a with rank 1" } | ||
| - { time: 1700000000, host: "test-host", source: "apache-beam-37a", sourcetype: "test-type", index: "test-index", event: "Event for label 37a with rank 2" } | ||
| - { time: 1700000000, host: "test-host", source: "apache-beam-389a", sourcetype: "test-type", index: "test-index", event: "Event for label 389a with rank 3" } | ||
| - { time: 1700000000, host: "test-host", source: "apache-beam-3821b", sourcetype: "test-type", index: "test-index", event: "Event for label 3821b with rank 4" } | ||
|
|
||
| pipelines: | ||
| # Pipeline 1: Publish test messages (valid and invalid) to Pub/Sub input topic | ||
| - pipeline: | ||
| type: chain | ||
| transforms: | ||
| - type: Create | ||
| config: | ||
| elements: | ||
| - {label: "11a", rank: 1} | ||
| - {label: "37a", rank: 2} | ||
| - {label: "389a", rank: 3} | ||
| - {label: "3821b", rank: 4} | ||
| - {label: "broken", rank: -1} | ||
| - type: WriteToPubSub | ||
| config: | ||
| topic: "{PUBSUB_VARS[INPUT_TOPIC]}" | ||
| format: JSON | ||
|
|
||
| # Pipeline 2: Read from Pub/Sub subscription, transform and write to Splunk HEC, | ||
| # and route failed records to Pub/Sub deadletter topic | ||
| - pipeline: | ||
| type: composite | ||
| transforms: | ||
| - type: ReadFromPubSub | ||
| name: ReadMessages | ||
| config: | ||
| subscription: "{PUBSUB_VARS[INPUT_SUBSCRIPTION]}" | ||
| format: JSON | ||
| schema: | ||
| type: object | ||
| properties: | ||
| label: {type: string} | ||
| rank: {type: integer} | ||
| required: | ||
| - label | ||
| - rank | ||
|
|
||
| - type: MapToFields | ||
| name: ConvertToSplunkEvents | ||
| input: ReadMessages | ||
| config: | ||
| language: python | ||
| fields: | ||
| time: 1700000000 | ||
| host: "'test-host'" | ||
| source: | ||
| expression: "'apache-beam-' + label" | ||
| output_type: string | ||
| sourcetype: "'test-type'" | ||
| index: "'test-index'" | ||
| event: | ||
| callable: | | ||
| from typing import Optional | ||
| def format_event(row) -> Optional[str]: | ||
| if row.rank < 0: | ||
| return None | ||
| return str("Event for label " + row.label + " with rank " + str(row.rank)) | ||
|
|
||
| - type: WriteToSplunk | ||
| name: WriteToSplunk | ||
| input: ConvertToSplunkEvents | ||
| config: | ||
| url: "{FAKE_SPLUNK_SERVER.url}" | ||
| token: "{FAKE_SPLUNK_SERVER.token}" | ||
| batch_count: 2 | ||
| parallelism: 1 | ||
| disable_certificate_validation: false | ||
| enable_batch_logs: true | ||
| enable_gzip_http_compression: true | ||
| error_handling: | ||
| output: write_errors | ||
|
|
||
| - type: MapToFields | ||
| name: FormatWriteErrors | ||
| input: WriteToSplunk.write_errors | ||
| config: | ||
| language: python | ||
| fields: | ||
| failed_source: | ||
| expression: "failed_row.source if failed_row else ''" | ||
| output_type: string | ||
| error_message: | ||
| expression: "statusMessage" | ||
| output_type: string | ||
|
|
||
| - type: WriteToPubSub | ||
| name: WriteFailedRecords | ||
| input: FormatWriteErrors | ||
| config: | ||
| topic: "{PUBSUB_VARS[DEADLETTER_TOPIC]}" | ||
| format: JSON | ||
|
|
||
| # Pipeline 3: Read from Pub/Sub deadletter subscription and verify failed records | ||
| - pipeline: | ||
| type: chain | ||
| transforms: | ||
| - type: ReadFromPubSub | ||
| config: | ||
| subscription: "{PUBSUB_VARS[DEADLETTER_SUBSCRIPTION]}" | ||
| format: JSON | ||
| schema: | ||
| type: object | ||
| properties: | ||
| failed_source: {type: string} | ||
| error_message: {type: string} | ||
| required: | ||
| - failed_source | ||
| - error_message | ||
| - type: AssertEqual | ||
| config: | ||
| elements: | ||
| - {failed_source: "apache-beam-broken", error_message: "Event is required."} | ||
Oops, something went wrong.
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.