Piloterr
Destinations

Google Cloud Pub/Sub

Publish Dataflow's events to a Google Cloud Pub/Sub topic, with a service account that only has the Publisher role on it.

Each event becomes one message on your topic. Dataflow signs in with a service account key whose account may only publish to that topic.

Set up the topic

Create the topic

In the console, Pub/Sub → Topics → Create topic, or:

gcloud pubsub topics create dataflow-events --project my-project

Add a subscription to it, so the messages are kept until you read them.

Create a service account with the Publisher role on that topic

gcloud iam service-accounts create dataflow-publisher --project my-project

gcloud pubsub topics add-iam-policy-binding dataflow-events --project my-project \
  --member "serviceAccount:dataflow-publisher@my-project.iam.gserviceaccount.com" \
  --role roles/pubsub.publisher

Grant the role on the topic, not on the project: the account can then publish to this topic and nothing else.

Create a key

gcloud iam service-accounts keys create key.json \
  --iam-account dataflow-publisher@my-project.iam.gserviceaccount.com

If your organization blocks key creation (iam.disableServiceAccountKeyCreation), an administrator needs to allow it for this project.

Add the destination

The key goes in credentials.service_account_json as a string: the file's content, as Google downloads it.

Request body
{
  "type": "gcp_pubsub",
  "config": { "project_id": "my-project", "topic": "dataflow-events" },
  "credentials": {
    "service_account_json": "{\"type\": \"service_account\", \"project_id\": \"my-project\", \"private_key_id\": \"KEY_ID\", \"private_key\": \"-----BEGIN PRIVATE KEY-----\\n…\\n-----END PRIVATE KEY-----\\n\", \"client_email\": \"dataflow-publisher@my-project.iam.gserviceaccount.com\", \"token_uri\": \"https://oauth2.googleapis.com/token\"}"
  },
  "topics": ["*"]
}

With jq, the key file goes in as it is:

jq -n --rawfile key key.json '{
  type: "gcp_pubsub",
  config: { project_id: "my-project", topic: "dataflow-events" },
  credentials: { service_account_json: $key },
  topics: ["*"]
}' | curl https://dataflow.piloterr.com/v1/destinations \
  -H "x-api-key: YOUR_API_KEY" -H "content-type: application/json" --data @-
FieldRequiredSecretHolds
config.project_idyesnoThe topic's project id, such as my-project.
config.topicyesnoThe topic's id, dataflow-events, not its full path.
credentials.service_account_jsonyesyesThe service account key file's JSON, as a string. It must hold type: "service_account", client_email and private_key.

The key is stored encrypted and shown as …. To change it, send it again with PATCH. See Credentials.

Network

Messages go to the Pub/Sub API over TLS (443), from our egress address, 116.203.84.164 (exit_ips of GET /v1/destinations/types). There is nothing to open on your side.

What the topic receives

  • Data: the event payload, as JSON.
  • Attributes: event-id (the payload's id: deduplicate on it), topic (such as run.completed) and timestamp (when it was sent, RFC 3339).

A subscription filter can keep some topics only, for example attributes.topic = "run.completed".

Test it

Send a test event from the dashboard, or POST /v1/destinations/{id}/test (details), then pull it:

gcloud pubsub subscriptions pull YOUR_SUBSCRIPTION --project my-project --auto-ack

The delivery log's code is OK, or ERR for any failure.

ProblemFix
422 validation_failed on credentials.service_account_jsonPaste the whole key file, as a string.
422 validation_failed on config.topicGive the topic's id, without projects/…/topics/.
ERR on every deliveryCheck, in this order: the service account has roles/pubsub.publisher on this topic; the key is not deleted or disabled; the project id and topic id are the topic's.
OK but no message to pullThe subscription was created after the event, or its filter leaves it out.

Other errors: Errors.

On this page