├── LICENSE ├── README.md └── data-pipelines ├── github-to-discord.md ├── github-to-slack.md ├── hackernews-reader.md └── webhook-to-slack.md /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # InfinyOn Labs Projects 2 | 3 | InfinyOn Labs is a collection of projects that helps the community accelerate the pace of innovation through experimentation. The projects here use various components, some of which may be custom connectors and smartmodules that InfinyOn does not guarantee to run in production environments. 4 | 5 | ## Community Engagement 6 | 7 | Smartmodules and Connectors referenced in this repo must have two components: 8 | 9 | * **binary** published in `InfinyOn Hub` 10 | * **public repo** in `github` 11 | 12 | As a member of the Fluvio community, you are encouraged to contribute to these projects or submit new ones. 13 | 14 | ## Voting 15 | 16 | The InfinyOn team is committed to working with the community and turning the most popular `labs` projects into `certified` modules. Certified modules are integrated into the InfinyOn CI/CD pipeline and are safe for production workloads. 17 | 18 | [Vote Here] if you want you want a project to be promoted to `certified`, and we'll prioritize accordingly. 19 | 20 | ## Data Pipelines 21 | 22 | Configuration files that provision data pipelines using a combination of connectors and smartmodules. The projects are defined by configuration file operated via DSL, and should not require coding. 23 | 24 | | Pipeline Project | Description | 25 | | ------------------- | ------------------------------------------- | 26 | | [hackernews-reader] | Reads Hackernews XML feed and converts each article into a JON record | 27 | | [webhook-to-slack] | Convert events receives from the InfinyOn webhook API and notify on Slack | 28 | | [github-to-slack] | Periodically checks a github repo for changes in starts/forks, and notifies on Slack | 29 | | [github-to-discord] | Checks a github repo for starts/forks, and notifies on Discord | 30 | 31 | ## SmartModules 32 | 33 | Smartmodule projects built by `labs`. You may clone, and enhance: 34 | 35 | | Smartmodule Project | Record Type | Description | 36 | | ----------------------------- | ----------- | ------------------------------------- | 37 | | [labs-rss-json-sm] | xml | Parses RSS XML input into JSON format | 38 | | [labs-json-formatter-sm] | json | Generated a formatted string from JSON values | 39 | | [labs-key-gen-json-sm] | json | Generates a unique key (digest) from JSON values | 40 | | [labs-array-map-json-sm] | json | Splits an JSON array into individual records | 41 | | [labs-regex-map-json-sm] | json | Applies Regex transformations on JSON values | 42 | | [labs-stars-forks-changes-sm] | json | Detects changes in github stars & forks, and generates an emoji string | 43 | | [labs-regex-map-sm] | text | Applies Regex transformations on arbitrary text | 44 | | [labs-cvs-json-sm] | csv | Turns a CVS file into an array of json records | 45 | 46 | For additional examples, checkout [fluvio/smartmodules]. 47 | 48 | ## Connectors 49 | 50 | Connectors in development as incubated labs projects: 51 | 52 | | Connector Project | Status | Description | 53 | | ---------------------------- | ------------ | ------------------------------------- | 54 | | [labs-redis-sink-connector] | experimental | Fluvio to Redis | 55 | | labs-s3-sink-connector | roadmap | Fluvio to S3 | 56 | 57 | Note, all certified connectors are available for use in labs projects: 58 | 59 | | Connector Project | Status | Description | 60 | | ---------------------------- | ------------ | ------------------------------------- | 61 | | [http-source-connector] | certified | HTTP (POST/GET) to fluvio | 62 | | [http-sink-connector] | certified | fluvio to HTTP (POST) | 63 | | [kafka-source-connector] | certified | Kafka to fluvio | 64 | | [kafka-sink-connector] | certified | fluvio to Kafka | 65 | | [mqtt-source-connector] | certified | mqtt to fluvio | 66 | | [sql-sink-connector] | certified | fluvio to SQL | 67 | 68 | 69 | Connector **status** definition: 70 | * `roadmap` - requested by the community, 71 | * `experimental` - under development (compile and run on your own) 72 | * `stable` - proven to work, but not yet certified (compile and run on your own) 73 | * `certified` - certified and available on InfinyOn Cloud and local environments 74 | 75 | 76 | 77 | [Vote Here]: https://docs.google.com/forms/d/1yK8k-7Udq2wteNw-ZJm8Q59pvpwqduzUexSSUmgsYzI/ 78 | 79 | [hackernews-reader]: data-pipelines/hackernews-reader.md 80 | [github-to-discord]: data-pipelines/github-to-discord.md 81 | [github-to-slack]: data-pipelines/github-to-slack.md 82 | [webhook-to-slack]: data-pipelines/webhook-to-slack.md 83 | 84 | [labs-rss-json-sm]: https://github.com/infinyon/labs-rss-json-sm 85 | [labs-json-formatter-sm]: https://github.com/infinyon/labs-json-formatter-sm 86 | [labs-key-gen-json-sm]: https://github.com/infinyon/labs-key-gen-json-sm 87 | [labs-array-map-json-sm]: https://github.com/infinyon/labs-array-map-json-sm 88 | [labs-regex-map-json-sm]: https://github.com/infinyon/labs-regex-map-json-sm 89 | [labs-stars-forks-changes-sm]: https://github.com/infinyon/labs-stars-forks-changes-sm 90 | [labs-regex-map-sm]: https://github.com/infinyon/labs-regex-map-sm 91 | [labs-cvs-json-sm]: https://github.com/infinyon/labs-csv-json-sm 92 | 93 | [labs-redis-sink-connector]: https://github.com/infinyon/labs-redis-sink-connector 94 | [http-source-connector]: https://github.com/infinyon/http-source-connector 95 | [http-sink-connector]: https://github.com/infinyon/http-sink-connector 96 | [kafka-sink-connector]: https://github.com/infinyon/kafka-connector/tree/main/crates/kafka-sink 97 | [kafka-source-connector]: https://github.com/infinyon/kafka-connector/tree/main/crates/kafka-source 98 | [sql-sink-connector]: https://github.com/infinyon/sql-connector 99 | [mqtt-source-connector]: https://github.com/infinyon/mqtt-connector 100 | 101 | [fluvio/smartmodules]: https://github.com/infinyon/fluvio/tree/master/smartmodule/examples 102 | -------------------------------------------------------------------------------- /data-pipelines/github-to-discord.md: -------------------------------------------------------------------------------- 1 | # Github to Discord 2 | 3 | This project creates an end-to-end event pipeline that detects changes in github stars & forks and publishes the result to Discord using connectors: 4 | 5 | * [http-source]: to read periodically from a github, parse the fields from the `json` output, and publish the result to a topic. 6 | 7 | * [http-sink]: to listen to the same topic, detect changes, and publish the result to Discord. 8 | 9 | ## Objective 10 | 11 | Show an example on how to create a data streaming pipeline that reads from an HTTP API, transforms the output, and invokes a webhook to generate an alert. 12 | 13 | ## Prerequsites 14 | 15 | * [Fluvio CLI] running locally 16 | * Account on [InfinyOn Cloud] 17 | 18 | ## Step-by-Step 19 | 20 | 1. [Create http-source configuration file](#create-http-source-configuration-file) 21 | 2. [Create http-sink configuration file](#create-http-sink-configuration-file) 22 | 3. [Download smartmodules](#download-smartmodules) 23 | 4. [Start Connectors](#start-connectors) 24 | 5. [Test Data Pipeline](#test-data-pipeline) 25 | 26 | 27 | ### Create http-source configuration file 28 | 29 | Create an HTTP source connector configuration file called `github.yaml` : 30 | 31 | ```yaml 32 | apiVersion: 0.1.0 33 | meta: 34 | version: 0.3.6 35 | name: github-stars-in 36 | type: http-source 37 | topic: stars-forks 38 | secrets: 39 | - name: GITHUB_TOKEN 40 | http: 41 | endpoint: 'https://api.github.com/repos/infinyon/fluvio' 42 | method: GET 43 | headers: 44 | - 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' 45 | interval: 30s 46 | transforms: 47 | - uses: infinyon/jolt@0.4.1 48 | with: 49 | spec: 50 | - operation: shift 51 | spec: 52 | "stargazers_count": "stars" 53 | "forks_count": "forks" 54 | ``` 55 | 56 | Github rate-limits API requests to 60 per hour, which you an extend to 5000 by creating an application token. Check out github documentation on how to create an [Access Tokens]. 57 | 58 | Add the access token `secret` in [InfinyOn Cloud] : 59 | 60 | ``` 61 | fluvio cloud secret set GITHUB_TOKEN 62 | ``` 63 | 64 | ### Create http-sink configuration file 65 | 66 | Create an HTTP source connector configuration file called `discord.yaml` : 67 | 68 | ```yaml 69 | apiVersion: 0.1.0 70 | meta: 71 | version: 0.2.8 72 | name: discord-stars-out 73 | type: http-sink 74 | topic: stars-forks 75 | secrets: 76 | - name: DISCORD_TOKEN 77 | http: 78 | endpoint: "https://discord.com/api/webhooks/${{ secrets.DISCORD_TOKEN }}" 79 | headers: 80 | - "Content-Type: application/json" 81 | transforms: 82 | - uses: infinyon-labs/stars-forks-changes@0.1.4 83 | lookback: 84 | last: 1 85 | - uses: infinyon/jolt@0.4.1 86 | with: 87 | spec: 88 | - operation: shift 89 | spec: 90 | "result": "content" 91 | ``` 92 | 93 | Check out [Discord Webhooks] on how to create a channel webhook token. 94 | 95 | Add the access token `secret` in [InfinyOn Cloud] : 96 | 97 | ``` 98 | fluvio cloud secret set DISCORD_TOKEN 99 | ``` 100 | 101 | ### Download Smartmodules 102 | 103 | Download the smartmodules used by the connectors to your cluster: 104 | 105 | ```bash 106 | fluvio hub sm download infinyon/jolt@0.4.1 107 | fluvio hub sm download infinyon-labs/stars-forks-changes@0.1.4 108 | ``` 109 | 110 | Check `fluvio smartmodule list` to ensure they've been downloaded. 111 | 112 | 113 | ### Start Connectors 114 | 115 | Start source & sink connectors: 116 | 117 | ```bash 118 | fluvio cloud connector create -config github.yaml 119 | fluvio cloud connector create -config discord.yaml 120 | ``` 121 | 122 | Check `fluvio cloud connector log` to ensure they have been successfully provisioned. 123 | 124 | ### Test Data Pipeline 125 | 126 | Check the last values generated by the github connector: 127 | 128 | ```bash 129 | $ fluvio consume -dT 1 stars-forks 130 | {"stars":1770,"forks":138} 131 | ``` 132 | 133 | Produce a new value 134 | 135 | ```bash 136 | $ fluvio produce stars-forks 137 | > {"stars":1769,"forks":138} 138 | OK 139 | ``` 140 | 141 | An alert with `:star2: 1769` will show-up in your discord channel. 142 | 143 | 144 | ### References 145 | 146 | * [Create a Github Stars/Forks Event Pipeline (Blog)] 147 | * [labs-stars-forks-changes-sm](https://github.com/infinyon/labs-stars-forks-changes-sm) 148 | 149 | 150 | --- 151 | 152 | [Fluvio CLI]: https://www.fluvio.io/download 153 | [InfinyOn Cloud]: https://infinyon.cloud/signup 154 | [http-sink]: https://fluvio.io/connectors/outbound/http/ 155 | [http-source]: https://fluvio.io/connectors/inbound/http/ 156 | [Access Tokens]: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token 157 | [Discord Webhooks]: https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks 158 | [Create a Github Stars/Forks Event Pipeline (Blog)]: https://infinyon.com/blog/2023/07/github-stars-to-slack/ 159 | -------------------------------------------------------------------------------- /data-pipelines/github-to-slack.md: -------------------------------------------------------------------------------- 1 | # Github to Slack 2 | 3 | This project creates an end-to-end event pipeline that detects changes in github stars & forks and publishes the result to Slack using connectors: 4 | 5 | * [http-source]: to read periodically from a github, parse the fields from the `json` output, and publishes the result to a topic. 6 | 7 | * [http-sink]: to listen to the same topic, detect changes, and publish the result to Slack. 8 | 9 | ## Objective 10 | 11 | Show an example on how to create a data streaming pipeline that reads from an HTTP API, transforms the output, and invokes a webhook to generate an alert. 12 | 13 | ## Prerequsites 14 | 15 | * [Fluvio CLI] running locally 16 | * Account on [InfinyOn Cloud] 17 | 18 | ## Step-by-Step 19 | 20 | 1. [Create http-source configuration file](#create-http-source-configuration-file) 21 | 2. [Create http-sink configuration file](#create-http-sink-configuration-file) 22 | 3. [Download smartmodules](#download-smartmodules) 23 | 4. [Start Connectors](#start-connectors) 24 | 5. [Test Data Pipeline](#test-data-pipeline) 25 | 26 | ### Create http-source configuration file 27 | 28 | Create an HTTP source connector configuration file called `github.yaml` : 29 | 30 | ```yaml 31 | apiVersion: 0.1.0 32 | meta: 33 | version: 0.3.6 34 | name: github-stars-in 35 | type: http-source 36 | topic: stars-forks 37 | secrets: 38 | - name: GITHUB_TOKEN 39 | http: 40 | endpoint: 'https://api.github.com/repos/infinyon/fluvio' 41 | method: GET 42 | headers: 43 | - 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' 44 | interval: 30s 45 | transforms: 46 | - uses: infinyon/jolt@0.4.1 47 | with: 48 | spec: 49 | - operation: shift 50 | spec: 51 | "stargazers_count": "stars" 52 | "forks_count": "forks" 53 | ``` 54 | 55 | Github rate-limits API requests to 60 per hour, which you an extend to 5000 by creating an application token. Check out github documentation on how to create an [Access Tokens]. 56 | 57 | Add the access token `secret` in [InfinyOn Cloud] : 58 | 59 | ``` 60 | fluvio cloud secret set GITHUB_TOKEN 61 | ``` 62 | 63 | ### Create http-sink configuration file 64 | 65 | Create an HTTP source connector configuration file called `slack.yaml` : 66 | 67 | ```yaml 68 | apiVersion: 0.1.0 69 | meta: 70 | version: 0.2.8 71 | name: slack-stars-out 72 | type: http-sink 73 | topic: stars-forks 74 | secrets: 75 | - name: SLACK_TOKEN 76 | http: 77 | endpoint: "https://hooks.slack.com/services/${{ secrets.SLACK_TOKEN }}" 78 | headers: 79 | - "Content-Type: application/json" 80 | transforms: 81 | - uses: infinyon-labs/stars-forks-changes@0.1.4 82 | lookback: 83 | last: 1 84 | - uses: infinyon/jolt@0.4.1 85 | with: 86 | spec: 87 | - operation: shift 88 | spec: 89 | "result": "text" 90 | ``` 91 | 92 | Check out [Slack Webhooks] on how to create a channel webhook token. 93 | 94 | Add the access token `secret` in [InfinyOn Cloud] : 95 | 96 | ``` 97 | fluvio cloud secret set SLACK_TOKEN 98 | ``` 99 | 100 | ### Download Smartmodules 101 | 102 | Download the smartmodules used by the connectors to your cluster: 103 | 104 | ```bash 105 | fluvio hub sm download infinyon/jolt@0.4.1 106 | fluvio hub sm download infinyon-labs/stars-forks-changes@0.1.4 107 | ``` 108 | 109 | Check `fluvio smartmodule list` to ensure they've been downloaded. 110 | 111 | 112 | ### Start Connectors 113 | 114 | Start source & sink connectors: 115 | 116 | ```bash 117 | fluvio cloud connector create -config github.yaml 118 | fluvio cloud connector create -config slack.yaml 119 | ``` 120 | 121 | Check `fluvio cloud connector log` to ensure they have been successfully provisioned. 122 | 123 | ### Test Data Pipeline 124 | 125 | Check the last values generated by the github connector: 126 | 127 | ```bash 128 | $ fluvio consume -dT 1 stars-forks 129 | {"stars":1770,"forks":138} 130 | ``` 131 | 132 | Produce a new value 133 | 134 | ```bash 135 | $ fluvio produce stars-forks 136 | > {"stars":1769,"forks":138} 137 | OK 138 | ``` 139 | 140 | An alert with `:star2: 1769` will show-up in your slack channel. 141 | 142 | 143 | ### References 144 | 145 | * [Create a Github Stars/Forks Event Pipeline (Blog)] 146 | * [labs-stars-forks-changes-sm] 147 | 148 | 149 | --- 150 | 151 | [Fluvio CLI]: https://www.fluvio.io/download 152 | [InfinyOn Cloud]: https://infinyon.cloud/signup 153 | [http-sink]: https://fluvio.io/connectors/outbound/http/ 154 | [http-source]: https://fluvio.io/connectors/inbound/http/ 155 | [labs-stars-forks-changes-sm]: (https://github.com/infinyon/labs-stars-forks-changes-sm) 156 | [Access Tokens]: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token 157 | [Slack Webhooks]: https://api.slack.com/messaging/webhooks 158 | [Create a Github Stars/Forks Event Pipeline (Blog)]: https://infinyon.com/blog/2023/07/github-stars-to-slack/ 159 | -------------------------------------------------------------------------------- /data-pipelines/hackernews-reader.md: -------------------------------------------------------------------------------- 1 | # Hackernews Reader 2 | 3 | Hackernews Reader uses [http-source] to build an XML reader that ingests hackernews articles, converts them to `json`, divides them into records, and publishes each record to a topic. 4 | 5 | ## Objective 6 | 7 | Show an example on how to query XML RSS feeds and convert each article into an individual JSON event for downstream processing. 8 | 9 | ## Prerequsites 10 | 11 | * [Fluvio CLI] running locally 12 | * Account on [InfinyOn Cloud] 13 | 14 | ## Step-by-Step 15 | 16 | 1. [Create http-source configuration file](#create-http-source-configuration-file) 17 | 2. [Download smartmodules](#download-startmodules) 18 | 3. [Start Connector](#start-connector) 19 | 4. [Check Results](#check-results) 20 | 21 | ### Create http-source configuration file 22 | 23 | Create an HTTP source connector configuration file called `hackernews.yaml` : 24 | 25 | ```yaml 26 | apiVersion: 0.1.0 27 | meta: 28 | version: 0.3.6 29 | name: hackernews 30 | type: http-source 31 | topic: hackernews 32 | http: 33 | method: GET 34 | endpoint: 'https://hnrss.org/newest' 35 | interval: 600s 36 | transforms: 37 | - uses: infinyon-labs/rss-json@0.1.1 38 | - uses: infinyon/jolt@0.4.1 39 | with: 40 | spec: 41 | - operation: shift 42 | spec: 43 | items: "" 44 | - uses: infinyon-labs/array-map-json@0.1.1 45 | ``` 46 | 47 | ### Download startmodules 48 | 49 | Download the smartmodules used by the connectors to your cluster: 50 | 51 | ```bash 52 | fluvio hub sm download infinyon/jolt@0.4.1 53 | fluvio hub sm download infinyon-labs/rss-json@0.1.1 54 | fluvio hub sm download infinyon-labs/array-map-json@0.1.1 55 | ``` 56 | 57 | Check `fluvio smartmodule list` to ensure they've been downloaded. 58 | 59 | 60 | ### Start Connector 61 | 62 | ```bash 63 | fluvio cloud connector create --config hackernews.yaml 64 | ``` 65 | 66 | ### Check Results 67 | 68 | Connector logs: 69 | 70 | ```bash 71 | fluvio cloud connector log hackernews 72 | ``` 73 | 74 | Records produced: 75 | 76 | ```bash 77 | fluvio consume hackernews -T 10 78 | ``` 79 | 80 | ### References 81 | 82 | * [How to Stream and Transform Data from Hacker News RSS Feed (YouTube Video)] 83 | * [labs-rss-json-sm](https://github.com/infinyon/labs-rss-json-sm) 84 | * [labs-array-map-json-sm](https://github.com/infinyon/labs-array-map-json-sm) 85 | 86 | 87 | --- 88 | [Fluvio CLI]: https://www.fluvio.io/download 89 | [InfinyOn Cloud]: https://infinyon.cloud/signup 90 | [http-source]: https://fluvio.io/connectors/inbound/http/ 91 | [rss-json]: https://github.com/infinyon/labs-rss-json-sm 92 | [jolt]: https://github.com/infinyon/fluvio-jolt 93 | [array-map-json]: https://github.com/infinyon/labs-array-map-json-sm 94 | [How to Stream and Transform Data from Hacker News RSS Feed (YouTube Video)]: https://www.youtube.com/watch?v=raV5q6paAPM&t=1s&ab_channel=InfinyOn 95 | -------------------------------------------------------------------------------- /data-pipelines/webhook-to-slack.md: -------------------------------------------------------------------------------- 1 | # Webhook Events to Slack Notifications 2 | 3 | This project creates an end-to-end event pipeline that reads event from a webhook, generates a formatted string, and publishes the result to Slack. While this is a simeple example, it has many event notification use cases, such as: 4 | 5 | * submission frpm website forms (via [Cloudflare workers] or your custom backend). 6 | * activity from ecommerce platforms on purchases and shopping carts. 7 | * notifications from github an your projects' activities. 8 | * alerts from financial products on your transactions. 9 | * notifications form any product that can invoke a webhook. 10 | 11 | This pipeline uses the following features: 12 | 13 | * [webhook]: that creates a public API to receive external events, transform and publish them to a topic. 14 | * [http-sink]: that listens the same topic, and publish them on Slack. 15 | 16 | 17 | ## Objective 18 | 19 | Show an example on how you build an event streaming pipeline that receies webhook evnts, transforms the input into a readable form, and generates an alert. We assume the events are generated by a user submitting a form, and we'll format accordingly. 20 | 21 | ## Prerequsites 22 | 23 | * [Fluvio CLI] running locally 24 | * Account on [InfinyOn Cloud] 25 | 26 | ## Step-by-Step 27 | 28 | 1. [Create webhook configuration file](#create-webhook-configuration-file) 29 | 2. [Create http-sink configuration file](#create-http-sink-configuration-file) 30 | 3. [Download SmartModules](#download-smartmodules) 31 | 4. [Start Webhook and Connector](#start-webhook-and-connector) 32 | 5. [Test Data Pipeline](#test-data-pipeline) 33 | 34 | ### Create webhook configuration file 35 | 36 | Create a webhook configuration file called `form-webhook.yaml` : 37 | 38 | ```yaml 39 | meta: 40 | name: form-webhook 41 | topic: form-events 42 | webhook: 43 | outputParts: body 44 | outputType: json 45 | transforms: 46 | - uses: infinyon-labs/json-formatter@0.1.3 47 | with: 48 | spec: 49 | match: 50 | - key: "/type" 51 | value: "subscribe" 52 | format: 53 | with: ":loudspeaker: {} ({}) subscribed on {}" 54 | using: 55 | - "/name" 56 | - "/email" 57 | - "/source" 58 | output: "/formatted" 59 | - key: "/type" 60 | value: "use-case" 61 | format: 62 | with: ":confetti_ball: {} ({}) wants to solve the following '{}' use-case:\n>{}" 63 | using: 64 | - "/name" 65 | - "/email" 66 | - "/source" 67 | - "/description" 68 | output: "/formatted" 69 | default: 70 | format: 71 | with: "{} ({}) submitted a request" 72 | using: 73 | - "/name" 74 | - "/email" 75 | output: "/formatted" 76 | ``` 77 | 78 | The webhook reads the JSON body, applies the `json-formatter` smartmodule to generate readable text, and writes the new record to a topic called `form-events`. Checkout [labs-json-formatter-sm] in github for additional information. 79 | 80 | 81 | ### Create http-sink configuration file 82 | 83 | Create an HTTP source connector configuration file called `slack-form-alerts.yaml` : 84 | 85 | ```yaml 86 | apiVersion: 0.1.0 87 | meta: 88 | version: 0.2.8 89 | name: slack-form-alerts 90 | type: http-sink 91 | topic: form-events 92 | secrets: 93 | - name: SLACK_USER_ALERTS 94 | http: 95 | endpoint: "https://hooks.slack.com/services/${{ secrets.SLACK_USER_ALERTS }}" 96 | headers: 97 | - "Content-Type: application/json" 98 | transforms: 99 | - uses: infinyon/jolt@0.4.1 100 | with: 101 | spec: 102 | - operation: shift 103 | spec: 104 | "formatted": "text" 105 | ``` 106 | 107 | The sink connector reads from the `form-events` topic and uses the `jolt` smartmodule to shift the formatted string into a field called `text` per the Slack instructions. Checkout [fluvio-jolt] in github for additional information. 108 | 109 | #### Add Slack webhook token to InfinyOn Secrets 110 | 111 | The Slack webhook link is sensitive information, let's add the access token part to `secret` in [InfinyOn Cloud] : 112 | 113 | ``` 114 | fluvio cloud secret set SLACK_USER_ALERTS 115 | ``` 116 | 117 | Check out [Slack Webhooks] on how to create the webhook token. 118 | 119 | 120 | ### Download SmartModules 121 | 122 | Download the smartmodules used by the webhook ad the connector: 123 | 124 | ```bash 125 | fluvio hub sm download infinyon/jolt@0.4.1 126 | fluvio hub sm download infinyon-labs/json-formatter@0.1.3 127 | ``` 128 | 129 | Check `fluvio smartmodule list` to ensure they've been downloaded. 130 | 131 | 132 | ### Start Webhook and Connector 133 | 134 | Start webhook listener: 135 | 136 | ```bash 137 | fluvio cloud webhook create --config form-webhook.yaml 138 | ``` 139 | Check `fluvio cloud webhook list` to ensure it has been successfully provisioned. In checkout the webhook link that we'll use to test the pipeline: `https://infinyon.cloud/webhooks/v1/[token]` 140 | 141 | 142 | Start sink connector: 143 | 144 | ```bash 145 | fluvio cloud connector create -config slack-form-alerts.yaml 146 | ``` 147 | 148 | Check `fluvio cloud connector list` to ensure it has been successfully provisioned. 149 | 150 | 151 | ### Test Data Pipeline 152 | 153 | Use `curl` to send a POST request with a fictious user request to our webhook link. In production environments, this iw what a website would send: 154 | 155 | ```bash 156 | curl -X POST https://infinyon.cloud/webhooks/v1/ \ 157 | -H "Content-Type: application/json" \ 158 | -d '{ "email": "alice@acme.com", "name": "Alice Liddell", "type": "subscribe", "source": "front-page" }' 159 | ``` 160 | 161 | The following alert is displayed in Slack: 162 | 163 | ```bash 164 | `:loudspeaker: Alice Liddell ("alice@acme.com) subscribed on front-page` will show-up in your slack channel. 165 | ``` 166 | 167 | That's all folks! 168 | 169 | ### References 170 | 171 | * [Webhook Basics] 172 | * [Connector Basics] 173 | * [Cloudflare workers] 174 | * [JSON formatter SmartModule] 175 | 176 | --- 177 | 178 | [webhook]: https://infinyon.com/docs/tutorials/webhook-basics/ 179 | [Webhook Basics]: https://infinyon.com/docs/tutorials/webhook-basics/ 180 | [http-sink]: https://fluvio.io/connectors/outbound/http/ 181 | [Connector Basics]: https://infinyon.com/docs/tutorials/connector-basics/ 182 | [labs-json-formatter-sm]: https://github.com/infinyon/labs-json-formatter-sm 183 | [JSON formatter SmartModule]: https://github.com/infinyon/labs-json-formatter-sm 184 | [fluvio-jolt]: https://github.com/infinyon/fluvio-jolt 185 | [Fluvio CLI]: https://www.fluvio.io/download 186 | [InfinyOn Cloud]: https://infinyon.cloud/signup 187 | [Access Tokens]: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token 188 | [Slack Webhooks]: https://api.slack.com/messaging/webhooks 189 | [Cloudflare workers]: https://infinyon.com/docs/tutorials/clodflare-workers/ 190 | --------------------------------------------------------------------------------