|
| 1 | +# GCP Dataflow PubSub to Better Stack |
| 2 | + |
| 3 | +A Google Cloud Dataflow Flex template that reads messages from PubSub and sends them to Better Stack. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This template provides a scalable solution for streaming data from Google Cloud PubSub to Better Stack. It uses Apache Beam's Python SDK and can be deployed as a Dataflow Flex template. |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +- Google Cloud Platform account with Dataflow and PubSub enabled |
| 12 | +- Better Stack account with a source token |
| 13 | +- Docker installed (for building the template) |
| 14 | +- Google Cloud SDK installed |
| 15 | + |
| 16 | +## Environment Variables |
| 17 | + |
| 18 | +The template requires two environment variables: |
| 19 | + |
| 20 | +- `BETTER_STACK_SOURCE_TOKEN`: Your Better Stack source token |
| 21 | +- `BETTER_STACK_INGEST_HOST`: The Better Stack ingest host URL |
| 22 | + |
| 23 | +## Building the Template |
| 24 | + |
| 25 | +1. Clone this repository: |
| 26 | +```bash |
| 27 | +git clone https://github.com/your-org/gcp-dataflow-pubsub-to-telemetry.git |
| 28 | +cd gcp-dataflow-pubsub-to-telemetry |
| 29 | +``` |
| 30 | + |
| 31 | +2. Build the Docker image: |
| 32 | +```bash |
| 33 | +docker build -t gcr.io/YOUR_PROJECT/pubsub-to-betterstack . |
| 34 | +``` |
| 35 | + |
| 36 | +3. Push the image to Google Container Registry: |
| 37 | +```bash |
| 38 | +docker push gcr.io/YOUR_PROJECT/pubsub-to-betterstack |
| 39 | +``` |
| 40 | + |
| 41 | +## Deploying the Template |
| 42 | + |
| 43 | +You can deploy the template using the Google Cloud Console or the gcloud CLI: |
| 44 | + |
| 45 | +### Using gcloud CLI |
| 46 | + |
| 47 | +```bash |
| 48 | +gcloud dataflow flex-template run "pubsub-to-betterstack-$(date +%Y%m%d-%H%M%S)" \ |
| 49 | + --template-file-gcs-location=gs://YOUR_BUCKET/templates/pubsub-to-betterstack.json \ |
| 50 | + --parameters input_subscription=projects/YOUR_PROJECT/subscriptions/YOUR_SUBSCRIPTION \ |
| 51 | + --region=YOUR_REGION \ |
| 52 | + --additional-experiments=use_runner_v2 |
| 53 | +``` |
| 54 | + |
| 55 | +### Using Google Cloud Console |
| 56 | + |
| 57 | +1. Go to the Dataflow section in the Google Cloud Console |
| 58 | +2. Click "Create Job from Template" |
| 59 | +3. Select "Custom Template" |
| 60 | +4. Enter the path to your template in Cloud Storage |
| 61 | +5. Fill in the required parameters: |
| 62 | + - `input_subscription`: Your PubSub subscription to read from |
| 63 | +6. Set the environment variables: |
| 64 | + - `BETTER_STACK_SOURCE_TOKEN` |
| 65 | + - `BETTER_STACK_INGEST_HOST` |
| 66 | +7. Click "Run Job" |
| 67 | + |
| 68 | +## Message Format |
| 69 | + |
| 70 | +The template expects messages in JSON format. Each message will be sent to Better Stack as-is. For example: |
| 71 | + |
| 72 | +```json |
| 73 | +{ |
| 74 | + "message": "Hello from PubSub", |
| 75 | + "timestamp": "2024-02-11T12:00:00Z", |
| 76 | + "severity": "INFO" |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +## Error Handling |
| 81 | + |
| 82 | +The template includes error handling that: |
| 83 | +- Logs errors but continues processing |
| 84 | +- Retries failed requests to Better Stack |
| 85 | +- Maintains message ordering |
| 86 | + |
| 87 | +## License |
| 88 | + |
| 89 | +ISC License. See [LICENSE.md](LICENSE.md) for details. |
0 commit comments