about summary refs log tree commit diff
path: root/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus')
-rw-r--r--nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/Gemfile7
-rw-r--r--nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/Gemfile.lock16
-rw-r--r--nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/default.nix26
-rw-r--r--nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/gemset.nix23
-rw-r--r--nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/no-git-version.patch34
-rw-r--r--nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/prometheus_exporter_version1
-rw-r--r--nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/spec-import-fix-abi-version.patch20
7 files changed, 127 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/Gemfile b/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/Gemfile
new file mode 100644
index 000000000000..54a39883d060
--- /dev/null
+++ b/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/Gemfile
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+source "https://rubygems.org"
+
+# gem "rails"
+gem "webrick", "1.7.0"
+gem "prometheus_exporter", "2.0.6"
diff --git a/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/Gemfile.lock b/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/Gemfile.lock
new file mode 100644
index 000000000000..88a3a3c8d654
--- /dev/null
+++ b/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/Gemfile.lock
@@ -0,0 +1,16 @@
+GEM
+  remote: https://rubygems.org/
+  specs:
+    prometheus_exporter (2.0.6)
+      webrick
+    webrick (1.7.0)
+
+PLATFORMS
+  ruby
+
+DEPENDENCIES
+  prometheus_exporter (= 2.0.6)
+  webrick (= 1.7.0)
+
+BUNDLED WITH
+   2.4.13
diff --git a/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/default.nix b/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/default.nix
new file mode 100644
index 000000000000..95bf4c5a679a
--- /dev/null
+++ b/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/default.nix
@@ -0,0 +1,26 @@
+{ lib, stdenv, mkDiscoursePlugin, fetchFromGitHub }:
+
+ mkDiscoursePlugin {
+  bundlerEnvArgs.gemdir = ./.;
+  name = "discourse-prometheus";
+  src = fetchFromGitHub {
+    owner = "discourse";
+    repo = "discourse-prometheus";
+    rev = "8a7a46a80cc65aa0839bc5e3c3b6f8ef6544089f";
+    sha256 = "sha256-TL+pbP26LvRMKdy8CAuBEK+LZfAs8HfggMeUDaBu9hc=";
+  };
+
+  patches = [
+    # The metrics collector tries to run git to get the commit id but fails
+    # because we don't run Discourse from a Git repository.
+    ./no-git-version.patch
+    ./spec-import-fix-abi-version.patch
+  ];
+
+  meta = with lib; {
+    homepage = "https://github.com/discourse/discourse-prometheus";
+    maintainers = with maintainers; [ dpausp ];
+    license = licenses.mit;
+    description = "Official Discourse Plugin for Prometheus Monitoring";
+  };
+}
diff --git a/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/gemset.nix b/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/gemset.nix
new file mode 100644
index 000000000000..b6f3158174c1
--- /dev/null
+++ b/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/gemset.nix
@@ -0,0 +1,23 @@
+{
+  prometheus_exporter = {
+    dependencies = ["webrick"];
+    groups = ["default"];
+    platforms = [];
+    source = {
+      remotes = ["https://rubygems.org"];
+      sha256 = "0pb4k6px8b36bvnw3d14j31s33ns60dcwxixbcgvhpzavd7fparb";
+      type = "gem";
+    };
+    version = "2.0.6";
+  };
+  webrick = {
+    groups = ["default"];
+    platforms = [];
+    source = {
+      remotes = ["https://rubygems.org"];
+      sha256 = "1d4cvgmxhfczxiq5fr534lmizkhigd15bsx5719r5ds7k7ivisc7";
+      type = "gem";
+    };
+    version = "1.7.0";
+  };
+}
diff --git a/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/no-git-version.patch b/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/no-git-version.patch
new file mode 100644
index 000000000000..9aebfd8aa794
--- /dev/null
+++ b/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/no-git-version.patch
@@ -0,0 +1,34 @@
+diff --git a/lib/internal_metric/global.rb b/lib/internal_metric/global.rb
+index 682571b..7bdd431 100644
+--- a/lib/internal_metric/global.rb
++++ b/lib/internal_metric/global.rb
+@@ -30,28 +30,7 @@ module DiscoursePrometheus::InternalMetric
+       @active_app_reqs = 0
+       @queued_app_reqs = 0
+       @fault_logged = {}
+-
+-      begin
+-        @@version = nil
+-
+-        out, error, status = Open3.capture3("git rev-parse HEAD")
+-
+-        if status.success?
+-          @@version ||= out.chomp
+-        else
+-          raise error
+-        end
+-      rescue => e
+-        if defined?(::Discourse)
+-          Discourse.warn_exception(e, message: "Failed to calculate discourse_version_info metric")
+-        else
+-          STDERR.puts "Failed to calculate discourse_version_info metric: #{e}\n#{e.backtrace.join("\n")}"
+-        end
+-
+-        @@retries ||= 10
+-        @@retries -= 1
+-        @@version = -1 if @@retries < 0
+-      end
++      @@version = -1
+     end
+ 
+     def collect
diff --git a/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/prometheus_exporter_version b/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/prometheus_exporter_version
new file mode 100644
index 000000000000..157e54f3e4d5
--- /dev/null
+++ b/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/prometheus_exporter_version
@@ -0,0 +1 @@
+2.0.6
diff --git a/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/spec-import-fix-abi-version.patch b/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/spec-import-fix-abi-version.patch
new file mode 100644
index 000000000000..de3a5c718f00
--- /dev/null
+++ b/nixpkgs/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/spec-import-fix-abi-version.patch
@@ -0,0 +1,20 @@
+diff --git a/bin/collector b/bin/collector
+index 6bd04a8caffb..119526fc6ea3 100644
+--- a/bin/collector
++++ b/bin/collector
+@@ -3,12 +3,14 @@
+ 
+ Process.setproctitle("discourse prometheus-collector")
+ 
++# We need the ABI version {MAJOR}.{MINOR}.0 here.
++abi_version = ENV['GEM_PATH'].split("/")[-1]
+ [
+   "webrick-#{ENV["WEBRICK_VERSION"]}",
+   "prometheus_exporter-#{ENV["PROMETHEUS_EXPORTER_VERSION"]}",
+ ].each do |spec_name|
+   spec_file =
+-    File.expand_path("../../gems/#{RUBY_VERSION}/specifications/#{spec_name}.gemspec", __FILE__)
++    File.expand_path("../../gems/#{abi_version}/specifications/#{spec_name}.gemspec", __FILE__)
+   spec = Gem::Specification.load(spec_file)
+   spec.activate
+ end