From 0728b72459757c04f57dc864ffc700e2d50d3e9d Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Sun, 8 Jan 2023 00:55:20 +0100 Subject: Add WIP prometheus-json-exporter and most dependencies --- tw/packages/monitoring.scm | 385 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 385 insertions(+) create mode 100644 tw/packages/monitoring.scm (limited to 'tw/packages/monitoring.scm') diff --git a/tw/packages/monitoring.scm b/tw/packages/monitoring.scm new file mode 100644 index 00000000..af7c3726 --- /dev/null +++ b/tw/packages/monitoring.scm @@ -0,0 +1,385 @@ +(define-module (tw packages monitoring) + #:use-module (gnu packages golang) + #:use-module ((gnu packages syncthing) + #:select (go-github-com-prometheus-common + go-github-com-prometheus-client-golang + go-github-com-prometheus-client-model)) + #:use-module (guix build-system go) + #:use-module (guix git-download) + #:use-module ((guix licenses) #:prefix license:) + #:use-module (guix packages)) + +(define-public go-github-com-go-logfmt-logfmt + (package + (name "go-github-com-go-logfmt-logfmt") + (version "0.5.1") + (home-page "https://github.com/go-logfmt/logfmt") + (source + (origin + (method git-fetch) + (uri (git-reference (url home-page) (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 (base32 "01fs4x2aqw2qcsz18s4nfvyqv3rcwz5xmgpk3bic6nzgyzsjd7dp")))) + (build-system go-build-system) + (arguments '(#:import-path "github.com/go-logfmt/logfmt")) + (synopsis "Marshals and unmarshals logfmt messages.") + (description "Package logfmt implements utilities to marshal and unmarshal +data in the @url{https://brandur.org/logfmt, logfmt format}. It provides an +API similar to @url{https://pkg.go.dev/encoding/json, @code{encoding/json}} +and @url{https://pkg.go.dev/encoding/xml, @code{encoding/xml}}.") + (license license:expat))) + +(define-public go-github-com-go-kit-log + (package + (name "go-github-com-go-kit-log") + (version "0.2.1") + (home-page "https://github.com/go-kit/log") + (source + (origin + (method git-fetch) + (uri (git-reference (url home-page) (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 (base32 "1xjv2g1cd1iaghhm1c1zw0lcz89a9zq5xradyjipvrbqxbxckqm6")))) + (build-system go-build-system) + (arguments '(#:import-path "github.com/go-kit/log")) + (propagated-inputs (list go-github-com-go-logfmt-logfmt)) + (synopsis "A minimal and extensible structured logger in Go") + (description "@code{package log} provides a minimal interface for +structured logging in services. It may be wrapped to encode conventions, +enforce type-safety, provide leveled logging, and so on. It can be used for +both typical application log events, and log-structured data streams.") + (license license:expat))) + +(define-public go-github-com-go-kit-kit-log + (package + (name "go-github-com-go-kit-kit-log") + (version "0.12.0") + (home-page (string-append "https://github.com/go-kit/kit/tree/v" version "/log")) + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/go-kit/kit") + (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 (base32 "15cm24sjyvwxpprfha2k0s3c1hhpg5y2kljnw04hayfyazqc79wl")))) + (build-system go-build-system) + (arguments '(#:import-path "github.com/go-kit/kit/log" + #:unpack-path "github.com/go-kit/kit")) + (propagated-inputs (list go-github-com-go-kit-log + go-github-com-go-logfmt-logfmt)) + (synopsis "A minimal and extensible structured logger in Go") + (description "@emph{Deprecation notice:} The core Go kit log packages +(@code{log}, @code{log/level}, @code{log/term}, and @code{log/syslog}) have +been moved to their own repository at @url{https://github.com/go-kit/log}. +The corresponding packages in this directory remain for backwards +compatibility. Their types alias the types and their functions call the +functions provided by the new repository. Using either import path should be +equivalent. Prefer the new import path when practical. + +@code{package log} provides a minimal interface for +structured logging in services. It may be wrapped to encode conventions, +enforce type-safety, provide leveled logging, and so on. It can be used for +both typical application log events, and log-structured data streams.") + (license license:expat))) + +(define-public go-github-com-coreos-go-systemd-v22-activation + (package + (name "go-github-com-coreos-go-systemd-v22-activation") + (version "22.5.0") + (home-page (string-append "https://github.com/coreos/go-systemd/tree/v" + version "/activation")) + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/coreos/go-systemd") + (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 (base32 "1vhb4cw8nw9nx8mprx829xv8w4jnwhc2lcyjljzlfafsn8nx5nyf")))) + (build-system go-build-system) + (arguments '(#:import-path "github.com/coreos/go-systemd/v22/activation" + #:unpack-path "github.com/coreos/go-systemd/v22")) + (synopsis "Go bindings to systemd socket activation") + (description "Go bindings to systemd. Of the several packages, only the +@code{activation} package is supplied here. It is used for writing and using +systemd socket activation from Go. + +An example HTTP server using socket activation can be quickly set up by +following this README on a Linux machine running systemd: + +@url{https://github.com/coreos/go-systemd/tree/main/examples/activation/httpserver}") + (license license:asl2.0))) + +;; For some reason, the google.golang.org/protobuf package does not install +;; anything, so we have to install its subpackages individually. +(define (protobuf-subpackage subpath) + (package + (name (string-append + "go-google-golang-org-protobuf-" + (string-map (lambda (ch) + (if (char=? ch #\/) #\- ch)) + subpath))) + ;; github.com/golang/protobuf v1.5.2 requires google.golang.org/protobuf v1.26.0 + (version "1.26.0") + (home-page "https://github.com/protocolbuffers/protobuf-go") + (source + (origin + (method git-fetch) + (uri (git-reference (url home-page) (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 (base32 "0xq6phaps6d0vcv13ga59gzj4306l0ki9kikhmb52h6pq0iwfqlz")))) + (build-system go-build-system) + (arguments `(#:import-path ,(string-append "google.golang.org/protobuf/" subpath) + #:unpack-path "google.golang.org/protobuf")) + (native-inputs (list go-github-com-google-go-cmp-cmp)) ; for unit tests + (synopsis "Go support for Google's protocol buffers") + (description "This project hosts the Go implementation for +@url{https://developers.google.com/protocol-buffers, protocol buffers}, which +is a language-neutral, platform-neutral, extensible mechanism for serializing +structured data. The protocol buffer language is a language for specifying +the schema for structured data. This schema is compiled into language +specific bindings. This project provides both a tool to generate Go code for +the protocol buffer language, and also the runtime implementation to handle +serialization of messages in Go. See the +@url{https://developers.google.com/protocol-buffers/docs/overview, protocol +buffer developer guide} for more information about protocol buffers +themselves.") + (license license:bsd-3))) + +;; TODO: github.com/golang/protobuf/ptypes/timestamp required by github.com/prometheus/exporter-toolkit/web +(define-public go-github-com-golang-protobuf-proto-latest + (package + (inherit go-github-com-golang-protobuf-proto) + (version "1.5.2") + (source + (origin + (method git-fetch) + (uri (git-reference + (url (package-home-page + go-github-com-golang-protobuf-proto)) + (commit (string-append "v" version)))) + (file-name (git-file-name + (package-name go-github-com-golang-protobuf-proto) version)) + (sha256 (base32 "1mh5fyim42dn821nsd3afnmgscrzzhn3h8rag635d2jnr23r1zhk")))) + (arguments '(#:import-path "github.com/golang/protobuf/proto" + #:unpack-path "github.com/golang/protobuf")) + (propagated-inputs + (map protobuf-subpackage + '("encoding/prototext" + "encoding/protowire" + "internal/descfmt" + "internal/descopts" + "internal/detrand" + "internal/encoding/defval" + "internal/encoding/messageset" + "internal/encoding/tag" + "internal/encoding/text" + "internal/errors" + "internal/filedesc" + "internal/filetype" + "internal/flags" + "internal/genid" + "internal/impl" + "internal/order" + "internal/pragma" + "internal/set" + "internal/strs" + "internal/version" + "reflect/protodesc" + "reflect/protoreflect" + "reflect/protoregistry" + "runtime/protoiface" + "runtime/protoimpl" + "types/descriptorpb" + "proto"))) + (native-inputs + (cons* go-github-com-google-go-cmp-cmp + (map protobuf-subpackage + '("testing/protopack" + "types/known/anypb" + "types/known/timestamppb")))))) + +(define-public go-github-com-prometheus-client-model-latest + (package + (inherit go-github-com-prometheus-client-model) + (version "0.3.0") + (source + (origin + (method git-fetch) + (uri (git-reference + (url (package-home-page go-github-com-prometheus-client-model)) + (commit (string-append "v" version)))) + (file-name (git-file-name + (package-name go-github-com-prometheus-client-model) version)) + (sha256 (base32 "199qx1hz28gjva9sx0zhfs7hq43fzz687bnp3daax87cjy4adzxw")))) + (propagated-inputs + (modify-inputs (package-propagated-inputs go-github-com-prometheus-client-model) + (replace "go-github-com-golang-protobuf-proto" + go-github-com-golang-protobuf-proto-latest))))) + +(define-public go-github-com-prometheus-common-latest + (package + (inherit go-github-com-prometheus-common) + (version "0.39.0") + (source + (origin + (method git-fetch) + (uri (git-reference + (url (package-home-page go-github-com-prometheus-common)) + (commit (string-append "v" version)))) + (file-name (git-file-name + (package-name go-github-com-prometheus-common) version)) + (sha256 (base32 "1i3kx3b3v5y0xbyc0n434x3qshk0fl738110lbfslxhvsidhpq1l")))) + (propagated-inputs + (modify-inputs (package-propagated-inputs go-github-com-prometheus-common) + (replace "go-github-com-prometheus-client-model" + go-github-com-prometheus-client-model-latest) + (append go-golang-org-x-oauth2) + (append go-golang-org-x-text))))) + +(define-public go-github-com-prometheus-exporter-toolkit-web + (package + (name "go-github-com-prometheus-exporter-toolkit-web") + (version "0.8.2") + (home-page (string-append "https://github.com/prometheus/exporter-toolkit/tree/v" version "/web")) + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/prometheus/exporter-toolkit") + (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 (base32 "07qib1prcrzdl2p1w5icq5mvw796q2aadhps3m7rj72mn08wv97f")))) + (build-system go-build-system) + (arguments '(#:import-path "github.com/prometheus/exporter-toolkit/web" + #:unpack-path "github.com/prometheus/exporter-toolkit")) + (propagated-inputs (list go-github-com-go-kit-log + go-golang-org-x-crypto + go-golang-org-x-sync + go-gopkg-in-yaml-v2 + go-github-com-coreos-go-systemd-v22-activation + go-github-com-mwitkow-go-conntrack + ;; The version from (gnu packages syncthing) is much too old, so update. + go-github-com-prometheus-common-latest)) + (synopsis "Utility package to build Prometheus exporters") + (description "This is a Go library for +@url{https://prometheus.io/docs/introduction/glossary/#exporter, Prometheus +exporters}. + +This repository is meant to be used in combination with the +@url{https://github.com/prometheus/client_golang, @code{client_golang}} +repository. If you are +@url{https://prometheus.io/docs/introduction/glossary/#direct-instrumentation, +instrumenting} an existing Go application, @code{client_golang} is the +repository you are looking for. + +@emph{This repository is currently WIP and experimental.}") + (license license:asl2.0))) + +(define-public go-github-com-mwitkow-go-conntrack + (let ((commit "2f068394615f73e460c2f3d2c158b0ad9321cadb") + (revision "0")) + (package + (name "go-github-com-mwitkow-go-conntrack") + (version (git-version "0.0.0" revision commit)) + (home-page "https://github.com/mwitkow/go-conntrack") + (source + (origin + (method git-fetch) + (uri (git-reference (url home-page) (commit commit))) + (file-name (git-file-name name version)) + (sha256 (base32 "0ymjmy12ks7smgwmrwsa5kf07d9w5kpk1dn650azlzr61b561aw7")))) + (build-system go-build-system) + (arguments '(#:import-path "github.com/mwitkow/go-conntrack")) + (propagated-inputs (list go-github-com-jpillora-backoff + go-golang-org-x-net + go-github-com-prometheus-client-golang)) + (native-inputs (list go-github-com-stretchr-testify)) ; for unit tests + (synopsis "Go middleware for net.Conn tracking (Prometheus/trace)") + (description "Prometheus monitoring and @code{x/net/trace} tracing +wrappers for @code{net.Conn}, both inbound (@code{net.Listener}) and outbound +(@code{net.Dialer}).") + (license license:asl2.0)))) + +(when (string>=? (package-version go) "1.18.0") + (warn "go-k8s-io-client-go-util-jsonpath can be updated to at least 0.26.0 now.")) + +(define-public go-k8s-io-client-go-util-jsonpath + (package + (name "go-k8s-io-client-go-util-jsonpath") + ;; Nothing significant changed in jsonpath between 0.23.0 and 0.26.0, but + ;; versions >0.23.0 require Go >=1.18 while Guix' default Go is 1.17. + ;; With k8s.io/client-go/util/jsonpath >0.23.0, same build error as: + ;; https://github.com/pelletier/go-toml/issues/812#issuecomment-1228430719 + (version "0.23.0") + (home-page (string-append "https://github.com/kubernetes/client-go/tree/v" + version "/util/jsonpath")) + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/kubernetes/client-go") + (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 (base32 "0m33cvvz520ki0dh7ki9245si25g26wq2b77bw9jz7dcdjq1vqi8")))) + (build-system go-build-system) + (arguments '(#:import-path "k8s.io/client-go/util/jsonpath" + #:unpack-path "k8s.io/client-go")) + (synopsis "JSONPath module from Go client for Kubernetes") + (description "The @code{util/jsonpath} module taken from the Kubernetes Go +client.") + (license license:asl2.0))) + +;; `go-github-com-alecthomas-kingpin' doesn't work for json-exporter; we need +;; gopkg.in/alecthomas/kingpin.v2. We can reuse the existing package. +(define-public go-gopkg-in-alecthomas-kingpin + (package + (inherit go-github-com-alecthomas-kingpin) + (name "go-gopkg-in-alecthomas-kingpin") + (arguments '(#:import-path "gopkg.in/alecthomas/kingpin.v2")))) + +(define-public prometheus-json-exporter + (package + (name "prometheus-json-exporter") + (version "0.5.0") + (home-page "https://github.com/prometheus-community/json_exporter") + (source + (origin + (method git-fetch) + (uri (git-reference (url home-page) (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 (base32 "04nf3kgk5sjfj2zgc33alkpjmwkzzk93gnh3ap10r4ms67c2wxyz")))) + (build-system go-build-system) + (arguments '(#:import-path "github.com/prometheus-community/json_exporter/cmd/main" + #:unpack-path "github.com/prometheus-community/json_exporter" + #:install-source? #f)) + (inputs (list go-github-com-masterminds-sprig + go-github-com-masterminds-goutils + go-github-com-masterminds-semver + go-github-com-go-logfmt-logfmt + go-github-com-go-kit-log + go-github-com-go-kit-kit-log + go-github-com-google-uuid + go-github-com-huandu-xstrings + go-github-com-imdario-mergo + go-github-com-mitchellh-copystructure + go-github-com-mitchellh-reflectwalk + go-github-com-mwitkow-go-conntrack + go-github-com-pkg-errors + go-github-com-spf13-cast + go-golang-org-x-crypto + go-gopkg-in-yaml-v2 + go-gopkg-in-alecthomas-kingpin + go-k8s-io-client-go-util-jsonpath + go-github-com-prometheus-client-golang + go-github-com-prometheus-exporter-toolkit-web)) + (synopsis "Prometheus exporter which scrapes remote JSON by JSONPath") + (description "A Prometheus exporter which scrapes remote JSON by +JSONPath. For checking the JSONPath configuration supported by this exporter +please head over @url{https://kubernetes.io/docs/reference/kubectl/jsonpath/, here}. + +Check out the @url{https://github.com/prometheus-community/json_exporter/blob/master/examples, examples} +directory for sample exporter configuration, Prometheus configuration and +expected data format.") + (license license:asl2.0))) -- cgit v1.2.3