Go Stackdriver debugger error loading program

4/2/2019

I am trying to set up Stackdriver debugging using Go. Using the article and this great medium post I came up with this solution.

Key parts, in cloudbuild.yaml

- name: gcr.io/cloud-builders/wget
  args: [
    "-O",
    "go-cloud-debug",
    "https://storage.googleapis.com/cloud-debugger/compute-go/go-cloud-debug"
  ]

...

Dockerfile I have

...

COPY gopath/bin/stackdriver-demo /stackdriver-demo

ADD go-cloud-debug /
ADD source-context.json /

CMD ["/go-cloud-debug","-sourcecontext=./source-context.json", "-appmodule=go-errrep","-appversion=1.0","--","/stackdriver-demo"]

...

However the pods keeps crashing, the container logs show this error:

Error loading program: decoding dwarf section info at offset 0x0: too short

EDIT: Using https://storage.googleapis.com/cloud-debugger/compute-go/go-cloud-debug may be outdated as I haven't seen it used outside Daz's medium post. The official docs uses the package cloud.google.com/go/cmd/go-cloud-debug-agent

I have update cloudbuild.yaml file to install this package:

- name: 'gcr.io/cloud-builders/go'
  args: ["get", "-u", "cloud.google.com/go/cmd/go-cloud-debug-agent"]
  env: ['PROJECT_ROOT=github.com/roberson34/stackdriver-demo', 'CGO_ENABLED=0', 'GOOS=linux']

- name: 'gcr.io/cloud-builders/go'
  args: ["install", "cloud.google.com/go/cmd/go-cloud-debug-agent"]
  env: ['PROJECT_ROOT=github.com/roberson34/stackdriver-demo', 'CGO_ENABLED=0', 'GOOS=linux']

And in the Dockerfile I can get access to the binary in gopath/bin/go-cloud-debug-agent

When I execute the gopath/bin/go-cloud-debug-agent with my own program as an argument:

/go-cloud-debug-agent -sourcecontext=./source-context.json -appmodule=go-errrep -appversion=1.0 -- /stackdriver-demo

I get another opaque error:

Error loading program: AttrStmtList not present or not int64 for unit 88

So basically using the cloud-debug binary from https://storage.googleapis.com/cloud-debugger/compute-go/go-cloud-debug and cloud-debug-agent binary from the package cloud.google.com/go/cmd/go-cloud-debug-agent both don't work and give different errors.

Would appreciate any tips on what I'm doing wrong and how to fix it.

-- robertson
google-cloud-stackdriver
google-kubernetes-engine
kubernetes
stackdriver

1 Answer

4/3/2019

OK :-)

Yes, you should follow the current Stackdriver documentation, e.g. go-cloud-debug-agent

Unfortunately, there are now various issues with my post including a (currently broken) gcr.io/cloud-builders/kubectl for regions.

I think your issue pertains to your use of golang:alpine. Alpine uses musl rather than the glibc that you find on most other Linux distro's and so, you really must compile for Alpine to ensure your binaries reference the correct libc.

I'm able to get your solution working primarily by switching your Dockerfile to pull the Cloud Debug Agent while on Alpine and to compile your source on Alpine:

FROM golang:alpine

RUN apk add git
RUN go get -u cloud.google.com/go/cmd/go-cloud-debug-agent

ADD main.go src
RUN CGO_ENABLED=0 go build -gcflags=all='-N -l' src/main.go

ADD source-context.json /

CMD ["bin/go-cloud-debug-agent","-sourcecontext=/source-context.json", "-appmodule=stackdriver-demo","-appversion=1.0","--","main"]

I think that should get you beyond the errors that you documented and you should be able to deploy your container to Kubernetes.

I've made my version of your image publicly available (and will retain it for a few days for you):

gcr.io/dazwilkin-190402-55473323/roberson34@sha256:17cb45f1320e2fe04e0681310506f4c229896429192b0d1c2c8dc20ed54adb0d

You may wish to reference it (by that digest) in your deployment.yaml

NB For Error Reporting to be "interesting", your code needs to generate errors and, with your example, this is going to be challenging (usually a good thing). You may consider adding another errorful handler that always results in errors so that you may test the service.

-- DazWilkin
Source: StackOverflow