Skip to content

barebitcoin/logdna-gcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This repo contains source code for a GCP Cloud Function. It listens for log lines over Pub/Sub, and forwards them to Mezmo (previously called LogDNA).

The Cloud Function currently expects log lines from Cloud Run Service or Jobs. No idea how it fares on log lines from other GCP sources.

You need to set up a logging sink that exports to a Pub/Sub topic. Docs on this can be found here.

Deploy:

$ INGESTION_KEY=<LOGDNA ingestion key>
$ PUBSUB_LOG_TOPIC=<Pub/Sub log topic name>
$ REGION=<Desired GCP Region>
$ gcloud functions deploy logdna-gcp \
      --runtime=go120 \
      --gen2 \
      --region=$REGION \
      --source=. \
      --entry-point=LogDNAUpload \
      --set-env-vars=INGESTION_KEY=$INGESTION_KEY \
      --trigger-topic=$PUBSUB_LOG_TOPIC

Run locally:

$ make dev

Call locally:

See docs.

# Assumes you have a file called data.json
$ set data (cat data.json | jq --compact-output | base64 --wrap 0)
$ curl localhost:8080 \
  -X POST \
  -H "Content-Type: application/json" \
  -H "ce-id: 123451234512345" \
  -H "ce-specversion: 1.0" \
  -H "ce-time: 2020-01-02T12:34:56.789Z" \
  -H "ce-type: google.cloud.pubsub.topic.v1.messagePublished" \
  -H "ce-source: //pubsub.googleapis.com/projects/MY-PROJECT/topics/MY-TOPIC" \
  -d '{
        "message": {
          "data": "'$data'",
        },
        "subscription": "projects/MY-PROJECT/subscriptions/MY-SUB"
      }'

About

Mezmo (LogDNA) GCP Cloud Function

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published