Skip to content

Commit a340d61

Browse files
committed
Add template JSON
1 parent 82ef179 commit a340d61

File tree

3 files changed

+68
-23
lines changed

3 files changed

+68
-23
lines changed

README.md

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The template requires two environment variables:
2020
- `BETTER_STACK_SOURCE_TOKEN`: Your Better Stack source token
2121
- `BETTER_STACK_INGESTING_HOST`: The Better Stack ingest host URL
2222

23-
## Building the Template
23+
## Building and Deploying the Template
2424

2525
1. Clone this repository:
2626
```bash
@@ -37,27 +37,40 @@ gcloud projects list
3737
gcloud config set project PROJECT_ID
3838
```
3939

40-
2. Build the Docker image:
40+
3. Build the Docker image:
4141
```bash
4242
docker build -t gcr.io/$(gcloud config get-value project)/pubsub-to-betterstack .
4343
```
4444

45-
3. Push the image to Google Container Registry:
45+
4. Push the image to Google Container Registry:
4646
```bash
4747
gcloud auth configure-docker
4848
docker push gcr.io/$(gcloud config get-value project)/pubsub-to-betterstack
4949
```
5050

51-
## Deploying the Template
51+
5. Create a Cloud Storage bucket for the template (if you don't have one):
52+
```bash
53+
BUCKET_NAME="dataflow-templates-$(gcloud config get-value project)"
54+
gsutil mb -l us-central1 gs://${BUCKET_NAME}
55+
```
5256

53-
You can deploy the template using the Google Cloud Console or the gcloud CLI:
57+
6. Update the template specification with your project ID:
58+
```bash
59+
sed -i "s/PROJECT_ID/$(gcloud config get-value project)/g" pubsub-to-betterstack.json
60+
```
5461

55-
### Using gcloud CLI
62+
7. Upload the template specification to Cloud Storage:
63+
```bash
64+
gsutil cp pubsub-to-betterstack.json gs://${BUCKET_NAME}/templates/
65+
```
5666

67+
8. Deploy the template using gcloud CLI:
5768
```bash
5869
gcloud dataflow flex-template run "pubsub-to-betterstack-$(date +%Y%m%d-%H%M%S)" \
59-
--template-file-gcs-location=gs://YOUR_BUCKET/templates/pubsub-to-betterstack.json \
60-
--parameters input_subscription=projects/YOUR_PROJECT/subscriptions/YOUR_SUBSCRIPTION \
70+
--template-file-gcs-location=gs://${BUCKET_NAME}/templates/pubsub-to-betterstack.json \
71+
--parameters input_subscription=projects/$(gcloud config get-value project)/subscriptions/YOUR_SUBSCRIPTION \
72+
--parameters better_stack_source_token=YOUR_SOURCE_TOKEN \
73+
--parameters better_stack_ingesting_host=YOUR_INGESTING_HOST \
6174
--region=$(gcloud config get-value compute/region) \
6275
--additional-experiments=use_runner_v2
6376
```
@@ -67,13 +80,12 @@ gcloud dataflow flex-template run "pubsub-to-betterstack-$(date +%Y%m%d-%H%M%S)"
6780
1. Go to the Dataflow section in the Google Cloud Console
6881
2. Click "Create Job from Template"
6982
3. Select "Custom Template"
70-
4. Enter the path to your template in Cloud Storage
83+
4. Enter the path to your template in Cloud Storage: `gs://${BUCKET_NAME}/templates/pubsub-to-betterstack.json`
7184
5. Fill in the required parameters:
7285
- `input_subscription`: Your PubSub subscription to read from
73-
6. Set the environment variables:
74-
- `BETTER_STACK_SOURCE_TOKEN`
75-
- `BETTER_STACK_INGESTING_HOST`
76-
7. Click "Run Job"
86+
- `better_stack_source_token`: Your Better Stack source token
87+
- `better_stack_ingesting_host`: The Better Stack ingest host URL
88+
6. Click "Run Job"
7789

7890
## Message Format
7991

pipeline.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@ def run(argv=None):
4141
required=True,
4242
help='Input PubSub subscription to read from'
4343
)
44+
parser.add_argument(
45+
'--better_stack_source_token',
46+
required=True,
47+
help='Better Stack Telemetry source token'
48+
)
49+
parser.add_argument(
50+
'--better_stack_ingesting_host',
51+
required=True,
52+
help='Better Stack Telemetry source ingesting host'
53+
)
4454
known_args, pipeline_args = parser.parse_known_args(argv)
4555

46-
# Get Better Stack credentials from environment variables
47-
source_token = os.environ.get('BETTER_STACK_SOURCE_TOKEN')
48-
ingest_host = os.environ.get('BETTER_STACK_INGESTING_HOST')
49-
50-
if not source_token or not ingest_host:
51-
raise ValueError(
52-
"Environment variables BETTER_STACK_SOURCE_TOKEN and BETTER_STACK_INGESTING_HOST must be set"
53-
)
54-
5556
pipeline_options = PipelineOptions(
5657
pipeline_args,
5758
save_main_session=True
@@ -64,7 +65,10 @@ def run(argv=None):
6465
subscription=known_args.input_subscription
6566
)
6667
| 'Send to Better Stack' >> beam.ParDo(
67-
PubSubToBetterStack(source_token, ingest_host)
68+
PubSubToBetterStack(
69+
known_args.better_stack_source_token,
70+
known_args.better_stack_ingesting_host
71+
)
6872
)
6973
)
7074

pubsub-to-betterstack.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "pubsub-to-betterstack",
3+
"description": "Dataflow template to stream data from PubSub to Better Stack",
4+
"parameters": [
5+
{
6+
"name": "input_subscription",
7+
"label": "Input PubSub subscription",
8+
"helpText": "PubSub subscription to read from",
9+
"isOptional": false,
10+
"regexes": ["^projects/[^/]+/subscriptions/[^/]+$"]
11+
},
12+
{
13+
"name": "better_stack_source_token",
14+
"label": "Better Stack Source Token",
15+
"helpText": "Your Better Stack source token",
16+
"isOptional": false
17+
},
18+
{
19+
"name": "better_stack_ingesting_host",
20+
"label": "Better Stack Ingesting Host",
21+
"helpText": "The Better Stack ingest host URL",
22+
"isOptional": false
23+
}
24+
],
25+
"image": "gcr.io/PROJECT_ID/pubsub-to-betterstack:latest",
26+
"sdkInfo": {
27+
"language": "PYTHON"
28+
}
29+
}

0 commit comments

Comments
 (0)