discourse.plugins.discourse-prometheus: Init

This commit is contained in:
Tobias Stenzel 2021-09-29 00:16:02 +02:00
parent 9ede32d45c
commit 7584343790
8 changed files with 115 additions and 0 deletions

View File

@ -15,6 +15,7 @@ in
discourse-math = callPackage ./discourse-math {}; discourse-math = callPackage ./discourse-math {};
discourse-migratepassword = callPackage ./discourse-migratepassword {}; discourse-migratepassword = callPackage ./discourse-migratepassword {};
discourse-openid-connect = callPackage ./discourse-openid-connect {}; discourse-openid-connect = callPackage ./discourse-openid-connect {};
discourse-prometheus = callPackage ./discourse-prometheus {};
discourse-solved = callPackage ./discourse-solved {}; discourse-solved = callPackage ./discourse-solved {};
discourse-spoiler-alert = callPackage ./discourse-spoiler-alert {}; discourse-spoiler-alert = callPackage ./discourse-spoiler-alert {};
discourse-yearly-review = callPackage ./discourse-yearly-review {}; discourse-yearly-review = callPackage ./discourse-yearly-review {};

View File

@ -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'

View File

@ -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

View File

@ -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";
};
}

View File

@ -0,0 +1,12 @@
{
prometheus_exporter = {
groups = ["default"];
platforms = [];
source = {
remotes = ["https://rubygems.org"];
sha256 = "1kmabnxz466zqnyqlzc693ny4l7i0rxvmc0znswvizc0zg4pri80";
type = "gem";
};
version = "0.5.0";
};
}

View File

@ -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

View File

@ -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

View File

@ -212,6 +212,9 @@ def update_plugins():
{'name': 'discourse-ldap-auth', 'owner': 'jonmbake'}, {'name': 'discourse-ldap-auth', 'owner': 'jonmbake'},
{'name': 'discourse-math'}, {'name': 'discourse-math'},
{'name': 'discourse-migratepassword', 'owner': 'discoursehosting'}, {'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-solved'},
{'name': 'discourse-spoiler-alert'}, {'name': 'discourse-spoiler-alert'},
{'name': 'discourse-yearly-review'}, {'name': 'discourse-yearly-review'},