Google Cloud Storage “exploder” #2

Golang Cloud Functions

Daz Wilkin
Google Cloud - Community
3 min readSep 3, 2018

--

Gophers and Explosions!?

Reference: Hallmark Caddyshack Gopher Ornament

Not quite but I’m still alright…

Almost one year ago, I wrote a proof-of-concept Node.JS Cloud Function (is that the correct singular form?) that unzipped files triggered by uploaded to GCS: exploder.

With the availability of Golang Cloud Functions Alpha (early access) and inspired by JBD post (link), herewith a simple (single-threaded) rewrite in Golang.

Setup

And:

Then, find yourself a zipped file, upload it to ${BUCKET_SRC}, slurp coffee (red wine, depending on the time of day), then check ${BUCKET_DST}:

Or using Cloud Console’s Storage Browser:

Source

And:

Destination

And then, slightly more involved:

And:

Update: 2018–09–05 — Added OpenCensus

Since JBD wrote about using OpenCensus, I thought I’d revisit this story, the code and add a stat for the count of unzipped files (link) and a trace for the GCS object creates.

Stackdriver Metric Explorer

And some results though I’m perplexed by the apparent low rate :-(

The trace was more problematic for me to get working but I think it was because I was not reliably vgo build && go mod vendor between deployments. So, please, bear that in mind as you develop code.

Stackdriver Trace

The coding changes are trivial.

Conclusion

The Golang runtime for Cloud Functions is a compelling (albeit overdue) addition to the set of runtimes. One noteworthy benefit with Golang over Node.JS and Python is that your Functions may be multi-threaded. This example is a mostly direct transliteration of the Node.JS example. A good evolution of this would be make this code multi-threaded (and async).

That’s all!

--

--