apkbuilds @ eed21034efae03ee661e06122f96dc01e53afaa4

feat: Add prometheus-postgres-exporter
diff --git a/README.md b/README.md
index aeb52dad969f92a0d436295aa5fc75a4c286184f..70f2fea3776faa738ba3bd30572f18bac0ca69a7 100644
--- a/README.md
+++ b/README.md
@@ -49,3 +49,10 @@ - **version**:    2.2.0
 - **reason**:     Remove edge repository and reddit-nextcloud-importer dependency
 - **releases**:   https://github.com/jsonpickle/jsonpickle/tags
 - **source**:     https://git.alpinelinux.org/aports/tree/testing/py3-jsonpickle?h=master
+
+## prometheus-postgres-exporter
+- **link**:       https://github.com/prometheus-community/postgres_exporter
+- **version**:    0.11.1
+- **reason**:     Remove edge repository and reddit-nextcloud-importer dependency
+- **releases**:   https://github.com/prometheus-community/postgres_exporter/releases
+- **source**:     https://git.alpinelinux.org/aports/tree/testing/prometheus-postgres-exporter?h=master
diff --git a/apks/prometheus-postgres-exporter/APKBUILD b/apks/prometheus-postgres-exporter/APKBUILD
new file mode 100644
index 0000000000000000000000000000000000000000..f323fea6cd1208695ddee63a5151377b842695b2
--- /dev/null
+++ b/apks/prometheus-postgres-exporter/APKBUILD
@@ -0,0 +1,48 @@
+# Contributor: Alex Denes <caskd@redxen.eu>
+# Maintainer: Alex Denes <caskd@redxen.eu>
+pkgname=prometheus-postgres-exporter
+_pkgname=postgres_exporter
+pkgver=0.11.1
+pkgrel=5
+pkgdesc="Prometheus exporter for PostgreSQL database"
+url="https://github.com/prometheus-community/postgres_exporter"
+license="Apache-2.0"
+arch="x86_64"
+makedepends="go>=1.14 bash sed"
+install="$pkgname.pre-install $pkgname.pre-upgrade"
+subpackages="$pkgname-openrc $pkgname-doc"
+source="$_pkgname-$pkgver.tar.gz::https://github.com/prometheus-community/postgres_exporter/archive/v$pkgver.tar.gz
+	postgres-exporter.initd
+	postgres-exporter.confd
+	disable-go-race-detector.patch
+	README.Alpine"
+builddir="$srcdir/$_pkgname-$pkgver"
+
+export GOFLAGS="$GOFLAGS -modcacherw -buildvcs=false"
+export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
+export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
+export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"
+
+build() {
+	make build
+}
+
+check() {
+	make test
+}
+
+package() {
+	install -Dm755 postgres_exporter "$pkgdir"/usr/bin/postgres_exporter
+
+	install -Dm755 "$srcdir"/postgres-exporter.initd "$pkgdir"/etc/init.d/postgres-exporter
+	install -Dm644 "$srcdir"/postgres-exporter.confd "$pkgdir"/etc/conf.d/postgres-exporter
+	install -Dm644 "$srcdir"/README.Alpine "$pkgdir"/usr/share/doc/postgres-exporter/README.Alpine
+}
+
+sha512sums="
+e5bd0ddaac53a8693017a174842831a9bddd1e555b10c1cf61d12d1e9585e1cdaedece378681afdfda46ba6db53aadc10ceecaca0396a330d181d7f06f2665fc  postgres_exporter-0.11.1.tar.gz
+e083183953fee8976765a872b7e21b859a4d907ef650e0320e63da4eff388b6c7f63c82a75cbd14e8f78e06018bae6d67666ebf2451adcbe7261e30f3889125f  postgres-exporter.initd
+14646244988a670caa12eb6cb5e8bea7259c27ec5fe8d89ee6f73675348a66fdfec68cc06304fcf1ce637737c3be7c38e25824e6efe302ed99ced73021d045c3  postgres-exporter.confd
+0e916a9216fbf21865a3672a1159836993048de1112dc8ddbd4e8283264d7fe12c5a5e2b08adeced2db6d4d35feb799c59eae7e55d010d045e825b4a524ae5e2  disable-go-race-detector.patch
+d4d8131a2d4787a50f4376cda01f52cc4d40e41088342db7a559e58d464fc92e3110bed542f8622259dd45990e1a95a73806310e1f80c212065e265181e22b32  README.Alpine
+"
diff --git a/apks/prometheus-postgres-exporter/README.Alpine b/apks/prometheus-postgres-exporter/README.Alpine
new file mode 100644
index 0000000000000000000000000000000000000000..6e0904919e48cf68e01daa5f4cf68e0a25a40868
--- /dev/null
+++ b/apks/prometheus-postgres-exporter/README.Alpine
@@ -0,0 +1,48 @@
+This document is adapted from README.Debian contained in Debian package.
+
+To use the PostgreSQL exporter, you need to connect to the database with
+superuser (postgres) privileges, or with an user that has been granted enough
+permissions.
+
+The recommended way to do this, is to create a `prometheus` user with no
+password, and then connect using UNIX domain sockets.
+
+To do that, set this connection string in
+/etc/conf.d/prometheus-postgres-exporter:
+
+  DATA_SOURCE_NAME='user=prometheus host=/run/postgresql dbname=postgres'
+
+And use psql (doas -u postgres psql) to execute these SQL commands to create
+the user:
+
+  CREATE USER prometheus;
+  ALTER USER prometheus SET SEARCH_PATH TO prometheus,pg_catalog;
+  
+  CREATE SCHEMA prometheus AUTHORIZATION prometheus;
+  
+  CREATE FUNCTION prometheus.f_select_pg_stat_activity()
+  RETURNS setof pg_catalog.pg_stat_activity
+  LANGUAGE sql
+  SECURITY DEFINER
+  AS $$
+    SELECT * from pg_catalog.pg_stat_activity;
+  $$;
+  
+  CREATE FUNCTION prometheus.f_select_pg_stat_replication()
+  RETURNS setof pg_catalog.pg_stat_replication
+  LANGUAGE sql
+  SECURITY DEFINER
+  AS $$
+    SELECT * from pg_catalog.pg_stat_replication;
+  $$;
+  
+  CREATE VIEW prometheus.pg_stat_replication
+  AS
+    SELECT * FROM prometheus.f_select_pg_stat_replication();
+  
+  CREATE VIEW prometheus.pg_stat_activity
+  AS
+    SELECT * FROM prometheus.f_select_pg_stat_activity();
+  
+  GRANT SELECT ON prometheus.pg_stat_replication TO prometheus;
+  GRANT SELECT ON prometheus.pg_stat_activity TO prometheus;
diff --git a/apks/prometheus-postgres-exporter/disable-go-race-detector.patch b/apks/prometheus-postgres-exporter/disable-go-race-detector.patch
new file mode 100644
index 0000000000000000000000000000000000000000..9ba76a3100014cc7f0b839201caa7f54e8951382
--- /dev/null
+++ b/apks/prometheus-postgres-exporter/disable-go-race-detector.patch
@@ -0,0 +1,16 @@
+--- a/Makefile.common
++++ b/Makefile.common
+@@ -111,13 +111,6 @@
+ PUBLISH_DOCKER_ARCHS = $(addprefix common-docker-publish-,$(DOCKER_ARCHS))
+ TAG_DOCKER_ARCHS = $(addprefix common-docker-tag-latest-,$(DOCKER_ARCHS))
+ 
+-ifeq ($(GOHOSTARCH),amd64)
+-        ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux freebsd darwin windows))
+-                # Only supported on amd64
+-                test-flags := -race
+-        endif
+-endif
+-
+ # This rule is used to forward a target like "build" to "common-build".  This
+ # allows a new "build" target to be defined in a Makefile which includes this
+ # one and override "common-build" without override warnings.
diff --git a/apks/prometheus-postgres-exporter/postgres-exporter.confd b/apks/prometheus-postgres-exporter/postgres-exporter.confd
new file mode 100644
index 0000000000000000000000000000000000000000..cbc18de585ea2946dd63b430a1af8eca294da893
--- /dev/null
+++ b/apks/prometheus-postgres-exporter/postgres-exporter.confd
@@ -0,0 +1,22 @@
+# /etc/conf.d/postgres-exporter
+
+# Connection string for the PostgreSQL database. You need to either connect as
+# superuser, or create a user with enough rights, as described in
+# /usr/share/doc/prometheus-postgres-exporter/README.Alpine
+
+# DATA_SOURCE_NAME='postgresql://login:password@hostname:port/'
+# DATA_SOURCE_NAME='user=prometheus host=/run/postgresql dbname=postgres'
+
+DATA_SOURCE_NAME=''
+
+# Set the command-line arguments to pass to the server.
+
+ARGS=''
+
+# Available flags:
+#  --web.listen-address=":9187"  Address to listen on for web interface and telemetry.
+#  --web.telemetry-path="/metrics"
+#                                Path under which to expose metrics.
+#  --extend.query-path=""        Path to custom queries to run.
+#  --log.level="info"            Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal]
+#  --log.format="logger:stderr"  Set the log target and format. Example: "logger:syslog?appname=bob&local=7" or "logger:stdout?json=true"
diff --git a/apks/prometheus-postgres-exporter/postgres-exporter.initd b/apks/prometheus-postgres-exporter/postgres-exporter.initd
new file mode 100755
index 0000000000000000000000000000000000000000..8955c15c542f26c706400b6d86a27950cfc18e0a
--- /dev/null
+++ b/apks/prometheus-postgres-exporter/postgres-exporter.initd
@@ -0,0 +1,22 @@
+#!/sbin/openrc-run
+supervisor=supervise-daemon
+
+command="/usr/bin/postgres_exporter"
+command_args="$ARGS"
+command_background="yes"
+command_user="prometheus:prometheus"
+
+export DATA_SOURCE_NAME
+logdir="/var/log/prometheus"
+error_log="$logdir/${SVCNAME}.log"
+pidfile="/var/run/${SVCNAME}.pid"
+
+depend() {
+	need net
+	after firewall
+}
+
+start_pre() {
+	checkpath -d -o $command_user -m755 $logdir
+	checkpath -f -o $command_user -m644 $error_log
+}
diff --git a/apks/prometheus-postgres-exporter/prometheus-postgres-exporter.pre-install b/apks/prometheus-postgres-exporter/prometheus-postgres-exporter.pre-install
new file mode 100755
index 0000000000000000000000000000000000000000..120995cf35351d604d1aeeafb04ad551607b835a
--- /dev/null
+++ b/apks/prometheus-postgres-exporter/prometheus-postgres-exporter.pre-install
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+addgroup -S prometheus 2>/dev/null
+adduser -S -D -h /var/lib/prometheus -s /sbin/nologin -G prometheus -g prometheus prometheus 2>/dev/null
+
+exit 0
diff --git a/apks/prometheus-postgres-exporter/prometheus-postgres-exporter.pre-upgrade b/apks/prometheus-postgres-exporter/prometheus-postgres-exporter.pre-upgrade
new file mode 120000
index 0000000000000000000000000000000000000000..4bb179f511f2528347b928f4eeb624acfe8c4fe7
--- /dev/null
+++ b/apks/prometheus-postgres-exporter/prometheus-postgres-exporter.pre-upgrade
@@ -0,0 +1 @@
+prometheus-postgres-exporter.pre-install
\ No newline at end of file