Welcome to the Linux Foundation Forum!

Lab 9.1: Workaround Instrumentation Exercise in Python and Go

kino1994
kino1994 Posts: 6
edited February 2023 in LFS241 Class Forum

For those of you who didn't get the 9.2 lab to work for me, I've found a workaround in Python:

  1. Change to instrumentation code working branch:

git checkout instrumented

  1. Check if python2 is installed with pip:

python2 --version

if python2 is no installed:

sudo apt-get install python2.7

if pip points to python3-pip and pip2.7 is no installed:

wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
pip2.7 install prometheus-client

Or

pip install prometheus-client -> only if pip points to a python2 version

  1. Then run the server:

python2 server.py

That worked for me

It would be nice if the examples were updated to python3...

Comments

  • kino1994
    kino1994 Posts: 6
    edited February 2023

    For go I've tried this with no luck.

    go env -w GO111MODULE=off
    go get -d
    go run main.go

    But found this error:

    github.com/prometheus/common/expfmt
    ../../go/src/github.com/prometheus/common/expfmt/decode.go:89:38: cannot use v (variable of type *io_prometheus_client.MetricFamily) as protoreflect.ProtoMessage value in argument to pbutil.ReadDelimited: *io_prometheus_client.MetricFamily does not implement protoreflect.ProtoMessage (missing method ProtoReflect)
    ../../go/src/github.com/prometheus/common/expfmt/encode.go:120:40: cannot use v (variable of type *io_prometheus_client.MetricFamily) as protoreflect.ProtoMessage value in argument to pbutil.WriteDelimited: *io_prometheus_client.MetricFamily does not implement protoreflect.ProtoMessage (missing method ProtoReflect)

    It would be fine if examples were updated and fixed...

  • You can also run the python script with python3. But you have to change the imports to this:
    from http.server import BaseHTTPRequestHandler
    from http.server import HTTPServer
    from socketserver import ThreadingMixIn

Categories

Upcoming Training