diff --git a/pkgs/servers/web-apps/discourse/plugins/all-plugins.nix b/pkgs/servers/web-apps/discourse/plugins/all-plugins.nix index f54b53a3445b..224e5a82024f 100644 --- a/pkgs/servers/web-apps/discourse/plugins/all-plugins.nix +++ b/pkgs/servers/web-apps/discourse/plugins/all-plugins.nix @@ -15,6 +15,7 @@ in discourse-math = callPackage ./discourse-math {}; discourse-migratepassword = callPackage ./discourse-migratepassword {}; discourse-openid-connect = callPackage ./discourse-openid-connect {}; + discourse-prometheus = callPackage ./discourse-prometheus {}; discourse-solved = callPackage ./discourse-solved {}; discourse-spoiler-alert = callPackage ./discourse-spoiler-alert {}; discourse-yearly-review = callPackage ./discourse-yearly-review {}; diff --git a/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/Gemfile b/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/Gemfile new file mode 100644 index 000000000000..3a73fc55839d --- /dev/null +++ b/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/Gemfile @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } + +# gem "rails" +gem 'prometheus_exporter', '0.5.0' diff --git a/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/Gemfile.lock b/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/Gemfile.lock new file mode 100644 index 000000000000..75c139cbfc0e --- /dev/null +++ b/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/Gemfile.lock @@ -0,0 +1,13 @@ +GEM + remote: https://rubygems.org/ + specs: + prometheus_exporter (0.5.0) + +PLATFORMS + ruby + +DEPENDENCIES + prometheus_exporter (= 0.5.0) + +BUNDLED WITH + 2.1.4 diff --git a/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/default.nix b/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/default.nix new file mode 100644 index 000000000000..4c6c12f22b3f --- /dev/null +++ b/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 = "46260710e8770344af438f86b47409d864a1c499"; + sha256 = "0nmpi0nysp59x4hyn1c3niypvxw1jkz86acb6m8acacw0c6682k2"; + }; + + 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/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/gemset.nix b/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/gemset.nix new file mode 100644 index 000000000000..e62e01926837 --- /dev/null +++ b/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/gemset.nix @@ -0,0 +1,12 @@ +{ + prometheus_exporter = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "1kmabnxz466zqnyqlzc693ny4l7i0rxvmc0znswvizc0zg4pri80"; + type = "gem"; + }; + version = "0.5.0"; + }; +} diff --git a/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/no-git-version.patch b/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/no-git-version.patch new file mode 100644 index 000000000000..416386f4ecd3 --- /dev/null +++ b/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/no-git-version.patch @@ -0,0 +1,36 @@ +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,30 +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 +- if @@retries < 0 +- @@version = -1 +- end +- end ++ @@version = -1 + end + + def collect diff --git a/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/spec-import-fix-abi-version.patch b/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/spec-import-fix-abi-version.patch new file mode 100644 index 000000000000..7b1159d0a800 --- /dev/null +++ b/pkgs/servers/web-apps/discourse/plugins/discourse-prometheus/spec-import-fix-abi-version.patch @@ -0,0 +1,16 @@ +diff --git a/bin/collector b/bin/collector +index 4fec65e..e59eac7 100755 +--- a/bin/collector ++++ b/bin/collector +@@ -3,8 +3,10 @@ + + Process.setproctitle("discourse prometheus-collector") + ++# We need the ABI version {MAJOR}.{MINOR}.0 here. ++abi_version = ENV['GEM_PATH'].split("/")[-1] + version = File.read(File.expand_path("../../prometheus_exporter_version", __FILE__)).strip +-spec_file = File.expand_path("../../gems/#{RUBY_VERSION}/specifications/prometheus_exporter-#{version}.gemspec", __FILE__) ++spec_file = File.expand_path("../../gems/#{abi_version}/specifications/prometheus_exporter-#{version}.gemspec", __FILE__) + + spec = Gem::Specification.load spec_file + spec.activate diff --git a/pkgs/servers/web-apps/discourse/update.py b/pkgs/servers/web-apps/discourse/update.py index 74872e326f69..c6a74bc758ec 100755 --- a/pkgs/servers/web-apps/discourse/update.py +++ b/pkgs/servers/web-apps/discourse/update.py @@ -212,6 +212,9 @@ def update_plugins(): {'name': 'discourse-ldap-auth', 'owner': 'jonmbake'}, {'name': 'discourse-math'}, {'name': 'discourse-migratepassword', 'owner': 'discoursehosting'}, + # We can't update this automatically at the moment because the plugin.rb + # tries to load a version number which breaks bundler called by this script. + # {'name': 'discourse-prometheus'}, {'name': 'discourse-solved'}, {'name': 'discourse-spoiler-alert'}, {'name': 'discourse-yearly-review'},