prometheus_exporter 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90eab18dd3dce6c0862b9bc14bf42f905a2a06516dfb023a4a081ce1ecb9a5d3
4
- data.tar.gz: 22fb28a7ab4f7dacfe28c1267b4158783d9c44de8bd5a798df122a6112b51090
3
+ metadata.gz: e93d3054e02dcc5bc4dc87df3be0b87ce3715850d4d116465f31ee525bb9c9f6
4
+ data.tar.gz: 681a91ab3490d12b095b5bde5a9eb303202e5c6b688cf57afe38752e49b2d9d4
5
5
  SHA512:
6
- metadata.gz: 4adae339d6e3ddb430f1615aa6077a83fd87cc90aaed6eb2fd3c2e4392834c3864dcac22929825f46c55a8e45e3bf7b5228b852a09731925a9a03223de0cc04d
7
- data.tar.gz: 53a1f43c7ebc8e5f7891d1784f5a41381c785beda2e0172bbc25202ee5a703c60bbab7c00d85f03c6bbe39f6dac4ef722a6959bae678b5e21da7325dc1d4f5fe
6
+ metadata.gz: b4b875a1d7799aab1ec0c6ec69570a070a730774cd58cd7a61e54d19bf4f327ddf0f47e6fa10e33084b86fbdcbd407a0e0e715bb190f9bf412b59ce17b9963dd
7
+ data.tar.gz: 1face6bafbf0da750d2b88f3d5ed010cb136fad3da776928f7a327db20cc81fd972208f7cbfeb298dd72492489a8838c76429cbe448b87d478dfff79292c2f00
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  Gemfile.lock
10
+
11
+ .rubocop-https---raw-githubusercontent-com-discourse-discourse-master--rubocop-yml
data/.rubocop.yml CHANGED
@@ -1,113 +1 @@
1
- AllCops:
2
- TargetRubyVersion: 2.4
3
- DisabledByDefault: true
4
- Exclude:
5
- - 'db/schema.rb'
6
- - 'bundle/**/*'
7
- - 'vendor/**/*'
8
- - 'node_modules/**/*'
9
- - 'public/**/*'
10
-
11
- # Prefer &&/|| over and/or.
12
- Style/AndOr:
13
- Enabled: true
14
-
15
- # Do not use braces for hash literals when they are the last argument of a
16
- # method call.
17
- Style/BracesAroundHashParameters:
18
- Enabled: true
19
-
20
- # Align `when` with `case`.
21
- Layout/CaseIndentation:
22
- Enabled: true
23
-
24
- # Align comments with method definitions.
25
- Layout/CommentIndentation:
26
- Enabled: true
27
-
28
- # No extra empty lines.
29
- Layout/EmptyLines:
30
- Enabled: true
31
-
32
- # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
33
- Style/HashSyntax:
34
- Enabled: true
35
-
36
- # Two spaces, no tabs (for indentation).
37
- Layout/IndentationWidth:
38
- Enabled: true
39
-
40
- Layout/SpaceAfterColon:
41
- Enabled: true
42
-
43
- Layout/SpaceAfterComma:
44
- Enabled: true
45
-
46
- Layout/SpaceAroundEqualsInParameterDefault:
47
- Enabled: true
48
-
49
- Layout/SpaceAroundKeyword:
50
- Enabled: true
51
-
52
- Layout/SpaceAroundOperators:
53
- Enabled: true
54
-
55
- Layout/SpaceBeforeFirstArg:
56
- Enabled: true
57
-
58
- # Defining a method with parameters needs parentheses.
59
- Style/MethodDefParentheses:
60
- Enabled: true
61
-
62
- # Use `foo {}` not `foo{}`.
63
- Layout/SpaceBeforeBlockBraces:
64
- Enabled: true
65
-
66
- # Use `foo { bar }` not `foo {bar}`.
67
- Layout/SpaceInsideBlockBraces:
68
- Enabled: true
69
-
70
- # Use `{ a: 1 }` not `{a:1}`.
71
- Layout/SpaceInsideHashLiteralBraces:
72
- Enabled: true
73
-
74
- Layout/SpaceInsideParens:
75
- Enabled: true
76
-
77
- # Detect hard tabs, no hard tabs.
78
- Layout/Tab:
79
- Enabled: true
80
-
81
- # Blank lines should not have any spaces.
82
- Layout/TrailingBlankLines:
83
- Enabled: true
84
-
85
- # No trailing whitespace.
86
- Layout/TrailingWhitespace:
87
- Enabled: true
88
-
89
- Lint/Debugger:
90
- Enabled: true
91
-
92
- Lint/BlockAlignment:
93
- Enabled: true
94
-
95
- # Align `end` with the matching keyword or starting expression except for
96
- # assignments, where it should be aligned with the LHS.
97
- Lint/EndAlignment:
98
- Enabled: true
99
- EnforcedStyleAlignWith: variable
100
-
101
- # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
102
- Lint/RequireParentheses:
103
- Enabled: true
104
-
105
- Layout/MultilineMethodCallIndentation:
106
- Enabled: true
107
- EnforcedStyle: indented
108
-
109
- Layout/AlignHash:
110
- Enabled: true
111
-
112
- Bundler/OrderedGems:
113
- Enabled: false
1
+ inherit_from: https://raw.githubusercontent.com/discourse/discourse/master/.rubocop.yml
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 0.4.3 - 11-02-2019
2
+
3
+ - Feature: Add alias for Gauge #observe called #set, this makes it a bit easier to migrate from prom
4
+ - Feature: Add increment and decrement to Counter
5
+
1
6
  0.4.2 - 30-11-2018
2
7
 
3
8
  - Fix/Feature: setting a Gauge to nil will remove Gauge (setting to non numeric will raise)
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in prometheus_exporter.gemspec
6
6
  gemspec
data/Guardfile CHANGED
@@ -4,4 +4,3 @@ guard :minitest do
4
4
  watch(%r{^lib/prometheus_exporter/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
5
5
  watch(%r{^test/test_helper\.rb$}) { 'test' }
6
6
  end
7
-
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList["test/**/*_test.rb"]
8
8
  end
9
9
 
10
- task :default => :test
10
+ task default: :test
@@ -15,11 +15,8 @@ module PrometheusExporter::Instrumentation
15
15
  result
16
16
  ensure
17
17
  duration = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start
18
- class_name = if worker.class.to_s == 'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper'
19
- msg['wrapped']
20
- else
21
- worker.class.to_s
22
- end
18
+ class_name = worker.class.to_s == 'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper' ?
19
+ msg['wrapped'] : worker.class.to_s
23
20
 
24
21
  @client.send_json(
25
22
  type: "sidekiq",
@@ -23,5 +23,15 @@ module PrometheusExporter::Metric
23
23
  @data[labels] ||= 0
24
24
  @data[labels] += increment
25
25
  end
26
+
27
+ def increment(labels = {}, value = 1)
28
+ @data[labels] ||= 0
29
+ @data[labels] += value
30
+ end
31
+
32
+ def decrement(labels = {}, value = 1)
33
+ @data[labels] ||= 0
34
+ @data[labels] -= value
35
+ end
26
36
  end
27
37
  end
@@ -30,6 +30,8 @@ module PrometheusExporter::Metric
30
30
  end
31
31
  end
32
32
 
33
+ alias_method :set, :observe
34
+
33
35
  def increment(labels = {}, value = 1)
34
36
  @data[labels] ||= 0
35
37
  @data[labels] += value
@@ -52,7 +52,7 @@ module PrometheusExporter::Metric
52
52
  @counts[labels] ||= 0
53
53
  buckets = @observations[labels]
54
54
  if buckets.nil?
55
- buckets = @buckets.map{|b| [b, 0]}.to_h
55
+ buckets = @buckets.map { |b| [b, 0] }.to_h
56
56
  @observations[labels] = buckets
57
57
  end
58
58
  buckets
@@ -66,7 +66,7 @@ module PrometheusExporter::Metric
66
66
  end
67
67
 
68
68
  def with_bucket(labels, bucket)
69
- labels.merge({"le" => bucket})
69
+ labels.merge("le" => bucket)
70
70
  end
71
71
 
72
72
  end
@@ -85,6 +85,6 @@ class PrometheusExporter::Middleware
85
85
  # this method takes care to convert both into a proper second + fractions timestamp
86
86
  def convert_header_to_ms(str)
87
87
  str = str.gsub(/t=|\./, '')
88
- "#{str[0,10]}.#{str[10,13]}".to_f
88
+ "#{str[0, 10]}.#{str[10, 13]}".to_f
89
89
  end
90
90
  end
@@ -48,13 +48,19 @@ module PrometheusExporter::Server
48
48
  if !metric
49
49
  metric = register_metric_unsafe(obj)
50
50
  end
51
+
52
+ keys = obj["keys"] || {}
53
+ if obj["custom_labels"]
54
+ keys = obj["custom_labels"].merge(keys)
55
+ end
56
+
51
57
  case obj["prometheus_exporter_action"]
52
58
  when 'increment'
53
- metric.increment(obj["keys"], obj["value"])
59
+ metric.increment(keys, obj["value"])
54
60
  when 'decrement'
55
- metric.decrement(obj["keys"], obj["value"])
61
+ metric.decrement(keys, obj["value"])
56
62
  else
57
- metric.observe(obj["value"], obj["keys"])
63
+ metric.observe(obj["value"], keys)
58
64
  end
59
65
  end
60
66
  end
@@ -47,7 +47,7 @@ module PrometheusExporter::Server
47
47
  @timeout = timeout
48
48
 
49
49
  @server.mount_proc '/' do |req, res|
50
- res['ContentType'] = 'text/plain; charset=utf-8'
50
+ res['Content-Type'] = 'text/plain; charset=utf-8'
51
51
  if req.path == '/metrics'
52
52
  res.status = 200
53
53
  if req.header["accept-encoding"].to_s.include?("gzip")
@@ -1,3 +1,3 @@
1
1
  module PrometheusExporter
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus_exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-30 00:00:00.000000000 Z
11
+ date: 2019-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -208,8 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
208
  - !ruby/object:Gem::Version
209
209
  version: '0'
210
210
  requirements: []
211
- rubyforge_project:
212
- rubygems_version: 2.7.6
211
+ rubygems_version: 3.0.1
213
212
  signing_key:
214
213
  specification_version: 4
215
214
  summary: Prometheus Exporter