# Send logs from Google Cloud to Epok

Updated Nov 22, 2026 · today

A Logs Router sink in your project sends log entries to a Pub/Sub topic. Pub/Sub pushes each entry to Epok over HTTPS and signs every push with a Google OIDC token for a service account in **your** project. Epok checks that signature against the binding you registered. This covers every service that writes to Cloud Logging: Cloud Run, GKE, Compute Engine, App Engine and Cloud Functions.

- Epok runs no code in your project.
- No Epok key goes into a URL or into GCP configuration. The key is used only by you, from your shell, to register the binding.
- Scope is one project: a project-level sink. For several projects, run setup once per project.
- Delivery is at least once. Epok drops the duplicates when Pub/Sub redelivers.

On this page: Before you start One command Terraform Check data arrived Troubleshooting Remove AI agents Metrics Traces

## Before you start

1. The `gcloud` CLI, logged in as someone with `roles/serviceusage.serviceUsageAdmin`, `roles/logging.configWriter`, `roles/pubsub.admin`, `roles/iam.serviceAccountAdmin`, `roles/iam.serviceAccountUser` and `roles/browser`. `roles/owner` on the project covers all of them.
2. An **ingest-scope** API key dedicated to this integration: [app.epok.cloud](https://app.epok.cloud) and open Settings, then API Keys, then New key (scope: ingest, name: `gcp-pubsub-<project>`).

```
export PROJECT_ID="my-project"
export EPOK_API_KEY="<ingest-scope key from Settings → API Keys>"
```

### Cost

Pub/Sub bills delivery at about **$40/TiB with a 1 KB minimum per message**. Push sends one message per log entry, so an entry under 1 KB bills as 1 KB. Routing logs with a sink adds no Cloud Logging charge, but the logs still count toward Logging ingestion if they are also stored in a log bucket. Epok bills the decoded log bytes per your plan. The sink filter (`EPOK_SINK_FILTER`, default `severity>=DEFAULT`, which is every entry) decides volume: estimate entries per day before you widen it.

## Set up with one command (gcloud)

Download the script, read it, then run it. Do not pipe it into bash. It is idempotent: re-running skips what already exists. The API key is never printed.

```
curl -fsSLo gcp.sh https://epok.cloud/setup/gcp.sh
less gcp.sh          # read it first
bash gcp.sh --dry-run  # optional: print every command, change nothing
bash gcp.sh
```

It creates, in your project, with the prefix `EPOK_RESOURCE_PREFIX` (default `epok`):

- Topic `epok-logs` and the sink `epok-sink` that routes to it.
- Service account `epok-push`, whose OIDC identity Pub/Sub presents to Epok. It gets no roles on project resources.
- Push subscription `epok-push` to your Epok endpoint. The token audience equals the push endpoint exactly.
- Dead-letter topic `epok-logs-dlq` and pull subscription `epok-logs-dlq-sub` (7-day retention), for messages Epok could not accept after 10 attempts. You can inspect and replay them.
- A binding in Epok that ties your project and service account to your account.

Optional inputs: `EPOK_SINK_FILTER` (which entries to send), `EPOK_RESOURCE_PREFIX`, `EPOK_PUSH_SA_EMAIL` (sign pushes with an existing service account; setup then never creates, grants on, or deletes it) and `EPOK_LABELS` (default `managed-by=epok`). The script prints progress to stderr. The last line on stdout is a JSON report: `"seen_at"` is set once a canary log reached Epok. Exit codes: `0` ok, `1` a step failed, `2` the data check timed out, `3` an input is missing or invalid.

## Or set up with Terraform

The Terraform module creates the same resources. First register the push service account with Epok to get your push endpoint. The call is idempotent: the same project and service account return the same binding.

```
export EPOK_RESOURCE_PREFIX=epok
SA_EMAIL="${EPOK_RESOURCE_PREFIX}-push@${PROJECT_ID}.iam.gserviceaccount.com"
curl -fsS -X POST \
  -H "X-API-Key: $EPOK_API_KEY" \
  -H "Content-Type: application/json" \
  --data "{\"gcp_project\":\"$PROJECT_ID\",\"sa_email\":\"$SA_EMAIL\",\"name\":\"$EPOK_RESOURCE_PREFIX\"}" \
  "https://ingest.epok.cloud/api/v1/integrations/gcp/bindings?format=env"
# prints EPOK_BINDING_ID=... and EPOK_PUSH_ENDPOINT=...; export both
```

```
curl -fsSLo epok-gcp.tgz https://epok.cloud/setup/terraform/epok-gcp.tgz && tar xzf epok-gcp.tgz
terraform -chdir=epok-gcp init
terraform -chdir=epok-gcp apply -var "project_id=$PROJECT_ID" -var "push_endpoint=$EPOK_PUSH_ENDPOINT"
```

Terraform needs `roles/iam.serviceAccountAdmin` to create the push service account, or pass `-var push_service_account_email=…` to use an existing one. Keep the Terraform state: uninstall needs it.

## Check that data arrived

Setup ends with this check. Run it on its own at any time:

```
bash gcp.sh --verify-only
```

It writes a canary entry to Cloud Logging that carries a one-time token, then asks Epok whether that token arrived. It writes a new canary every 60 seconds and keeps asking for up to 10 minutes, because a new sink drops entries for its first minutes. Success is a non-null `seen_at`. After Terraform, call the status endpoint yourself after writing a canary (repeat both if the first canary is dropped):

```
NONCE=$(openssl rand -hex 12)
gcloud logging write epok-canary "epok canary epok_canary=$NONCE" --project="$PROJECT_ID"
curl -fsS -H "X-API-Key: $EPOK_API_KEY" \
  "https://ingest.epok.cloud/api/v1/integrations/status?source=gcp_pubsub_push&nonce=$NONCE"
```

The response also counts pushes and records accepted or rejected in the last 24 hours, plus the last error reason. Then open [app.epok.cloud](https://app.epok.cloud) and go to **Live Tail** to watch your project's logs.

## Troubleshooting

Commands assume the default prefix `epok`.

1\. Wrong OIDC audience: the subscription's token audience is not the binding's push endpoint

**Seen as**

Epok answers 403 (token not valid for this binding). Pub/Sub retries, then dead-letters. The status call's requests\_24h stays 0.

**Check**

`gcloud pubsub subscriptions describe epok-push --format='value(pushConfig.oidcToken.audience,pushConfig.pushEndpoint)' # the two must be equal`

**Fix**

Re-run bash gcp.sh, or set the audience with gcloud pubsub subscriptions modify-push-config epok-push --push-auth-token-audience=$EPOK\_PUSH\_ENDPOINT.

2\. Missing publisher grant for the sink's writer identity on the topic

**Seen as**

Nothing reaches the topic. seen\_at stays null. Google may email a "sink configuration error".

**Check**

`gcloud pubsub topics get-iam-policy epok-logs # the sink writerIdentity must hold roles/pubsub.publisher`

**Fix**

Re-run bash gcp.sh. The grant steps are idempotent.

3\. PERMISSION\_DENIED on a setup step: the caller lacks a role

**Seen as**

Setup stops at that step with the gcloud error. Nothing after it ran.

**Check**

`The error names the missing permission, for example iam.serviceAccounts.create.`

**Fix**

Ask a project admin to grant the role from the list above, or set EPOK\_PUSH\_SA\_EMAIL to an existing service account. Never grant IAM roles to yourself.

4\. ALREADY\_EXISTS: a resource with the same name exists with a different configuration

**Seen as**

The create returns ALREADY\_EXISTS and setup stops.

**Check**

`gcloud logging sinks describe epok-sink --format='value(destination,filter)'`

**Fix**

Choose another EPOK\_RESOURCE\_PREFIX, or ask the owner of the existing resource. Never delete a resource you did not create.

5\. Propagation lag: a new sink drops entries for its first minutes

**Seen as**

seen\_at is null for the first canary. Later canaries arrive.

**Check**

`Wait 5 minutes, then check again.`

**Fix**

None needed. Run bash gcp.sh --verify-only.

If Epok is briefly unable to accept pushes, Pub/Sub keeps and retries the messages, so no data is lost.

## Remove

```
bash gcp.sh --uninstall
```

This deletes the sink first and waits until it is gone, so no sink is left pointing at a missing topic. Then it deletes the push subscription, the dead-letter subscription and topic (undelivered messages there are lost), the log topic and the push service account, and revokes the binding in Epok. A service account you supplied with `EPOK_PUSH_SA_EMAIL` is left alone. With Terraform:

```
terraform -chdir=epok-gcp destroy -var "project_id=$PROJECT_ID" -var "push_endpoint=$EPOK_PUSH_ENDPOINT"
# then revoke the Epok binding
curl -fsS -X DELETE -H "X-API-Key: $EPOK_API_KEY" \
  "https://ingest.epok.cloud/api/v1/integrations/gcp/bindings/$EPOK_BINDING_ID"
```

## For AI agents

The setup is published as a machine-readable manifest with every step, its idempotency check, the data check, the failure modes and the uninstall: `https://epok.cloud/setup/gcp-logs-pubsub-push.json` (gcloud) and `https://epok.cloud/setup/gcp-logs-pubsub-push-terraform.json` (Terraform). The script above is generated from the same manifest. An agent running it must:

- Ask a human for `EPOK_API_KEY`. Never create, guess, print, or write the key to a file or a commit.
- Stop and ask on PERMISSION\_DENIED. Never grant IAM roles to itself.
- Stop and ask on ALREADY\_EXISTS with a different configuration. Never delete what it did not create.
- Stop and ask before widening the sink filter, or for an org- or folder-level sink.
- Run the uninstall only when the user asked for removal.

## Metrics: Cloud Monitoring

For infra metrics (GCE CPU, Cloud SQL utilization, load-balancer latency, Pub/Sub backlog), run the OpenTelemetry Collector's `googlecloudmonitoring` receiver with a read-only service account and push to Epok over OTLP. The GCP credentials stay in your environment.

```
# otel-cloudmonitoring.yaml: pull Cloud Monitoring metrics to Epok
receivers:
  googlecloudmonitoring:
    project_id: PROJECT_ID
    collection_interval: 5m
    metrics_list:
      - metric_name: "compute.googleapis.com/instance/cpu/utilization"
      - metric_name: "cloudsql.googleapis.com/database/cpu/utilization"

processors:
  resource:
    attributes:
      - key: service.name        # the service these metrics belong to
        value: gcp-infra
        action: upsert

exporters:
  otlphttp/epok:
    metrics_endpoint: https://ingest.epok.cloud/v1/metrics
    compression: gzip               # the metrics path accepts gzip
    encoding: json
    headers: { Authorization: "Bearer ${EPOK_API_KEY}" }

service:
  pipelines:
    metrics:
      receivers: [googlecloudmonitoring]
      processors: [resource]
      exporters: [otlphttp/epok]
```

The collector's service account needs `roles/monitoring.viewer`. Cloud Monitoring bills per time series read, so list the metrics you care about. Confirm on the**Metrics** page in Epok within one collection interval.

## Traces: use OpenTelemetry

Send traces from Cloud Run, GKE or Compute Engine with OpenTelemetry over OTLP, not through Pub/Sub. See [Send traces](https://epok.cloud/docs/install/traces).

Next

- [Kubernetes](https://epok.cloud/docs/install/kubernetes): for GKE node and pod metrics with a DaemonSet.
- [Search syntax](https://epok.cloud/docs/search-syntax): query the logs you just routed.
- [Notification channels](https://app.epok.cloud) (Settings, then Notifications), so your alert rules can notify you when something breaks.
