Skip to content
This repository was archived by the owner on Nov 20, 2022. It is now read-only.

Commit 936d4d6

Browse files
committed
Update prometheus-client. Use my fork with the :most_recent aggregation.
1 parent d72480c commit 936d4d6

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ gem "addressable"
1111
gem "rack-ssl-enforcer"
1212
gem "clogger"
1313
gem "encrypted_strings"
14-
gem "prometheus-client", require: "prometheus/middleware/exporter"
14+
gem "prometheus-client", require: "prometheus/middleware/exporter", git: "https://github.com/stefansundin/prometheus-client.git", branch: "add-most_recent-aggregation"
1515

1616
group :production do
1717
gem "airbrake", require: false

Gemfile.lock

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
GIT
2+
remote: https://github.com/stefansundin/prometheus-client.git
3+
revision: 5256cdfb78d5bfec1b8fbb78dcc1a2eee6c8989f
4+
branch: add-most_recent-aggregation
5+
specs:
6+
prometheus-client (1.0.0)
7+
18
GEM
29
remote: https://rubygems.org/
310
specs:
@@ -30,8 +37,6 @@ GEM
3037
nio4r (2.5.2)
3138
powder (0.4.0)
3239
thor (>= 0.11.5)
33-
prometheus-client (0.9.0)
34-
quantile (~> 0.2.1)
3540
pry (0.12.2)
3641
coderay (~> 1.1.0)
3742
method_source (~> 0.9.0)
@@ -41,7 +46,6 @@ GEM
4146
public_suffix (4.0.1)
4247
puma (4.3.1)
4348
nio4r (~> 2.0)
44-
quantile (0.2.1)
4549
rack (2.0.8)
4650
rack-protection (2.0.7)
4751
rack
@@ -78,7 +82,7 @@ DEPENDENCIES
7882
github-release-party
7983
newrelic_rpm
8084
powder
81-
prometheus-client
85+
prometheus-client!
8286
pry-remote
8387
puma
8488
rack

app/github.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def self.graphql(query, variables, token=nil)
164164
}.to_json, headers)
165165
response = HTTPResponse.new(raw_response, uri.to_s)
166166
if response.json && response.json["data"] && response.json["data"]["rateLimit"] && response.json["data"]["rateLimit"]["remaining"]
167-
$metrics[:ratelimit_remaining].set({}, response.json["data"]["rateLimit"]["remaining"])
167+
$metrics[:ratelimit_remaining].set(response.json["data"]["rateLimit"]["remaining"])
168168
end
169169
return response
170170
end
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
# The app is currently run with multiple processes, which means that the /metrics endpoint is not consistent.. That's fine for now, at least with this one metric.
1+
# frozen_string_literal: true
2+
3+
# Use DirectFileStore if we run multiple processes
4+
store_settings = {}
5+
if ENV["WEB_CONCURRENCY"]
6+
require "prometheus/client/data_stores/direct_file_store"
7+
app_path = File.expand_path("../../..", __FILE__)
8+
Prometheus::Client.config.data_store = Prometheus::Client::DataStores::DirectFileStore.new(dir: "#{app_path}/tmp/prometheus/")
9+
store_settings[:aggregation] = :most_recent
10+
11+
# Clean up old metric files
12+
Dir["#{app_path}/tmp/prometheus/*.bin"].each do |file_path|
13+
File.unlink(file_path)
14+
end
15+
end
216

317
prometheus = Prometheus::Client.registry
418

519
$metrics = {
6-
ratelimit_remaining: prometheus.gauge(:ratelimit_remaining, "Remaining GitHub ratelimit."),
20+
ratelimit_remaining: prometheus.gauge(:ratelimit_remaining, store_settings: store_settings, docstring: "Remaining GitHub ratelimit."),
721
}

config/puma.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@
2323
if ENV["LOG_ENABLED"]
2424
stdout_redirect("#{app_path}/log/puma-stdout.log", "#{app_path}/log/puma-stderr.log", true)
2525
end
26+
27+
if ENV["WEB_CONCURRENCY"]
28+
on_worker_shutdown do |index|
29+
# Delete stale metric files on worker shutdown
30+
Dir["#{app_path}/tmp/prometheus/*___#{Process.pid}.bin"].each do |file_path|
31+
File.unlink(file_path)
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)