yabeda-prometheus 0.1.5 → 0.2.0

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: cf7f044078d39963972005e5dab30c8fa8d908ca9b1d667ce60fc36295e7fb91
4
- data.tar.gz: bd89b7fa736a501e417345951c642d601af60dd537a8c03a80a11678990e61d1
3
+ metadata.gz: c5e54ecad52d7b0afa0763c586097de00a8dda93c125116fb879fad20d7ce40c
4
+ data.tar.gz: 1f8dce2a20922f7a175191660ff5de7719893a6b741dffd8d06064867ec07cfe
5
5
  SHA512:
6
- metadata.gz: 2caa793706298308666cd8355eb8a04d7b56fd810fbd6ca57705246845e1cc229ce664fd70c284147fe998cf1e464580c7743af8e7aec28d569ec1f9a42c8fe8
7
- data.tar.gz: 8fcf2724292390d4115c2872c4bc1de2fc2f6d5435a9fb6a26eec06444b6b3a4428cee18fbf8cb7b4af14a61e175fc0aea9e46f9639acfc268259a1396496526
6
+ metadata.gz: b800c70319409c9d9afd4f88599c8e881f146825ccd5ed8ebd232efc16c5df78760c9adbe1b291747c6990d13f7c7703893344d0003954f5c902f119d779b672
7
+ data.tar.gz: c5c5f923c9a97d5633487998850dae2e1bac9a1e34ed3f0a0d679c5d414a14452fc33c910f853b09f4376e7dcf714fa58efa09cdb04cca1f062404e5f3f8dd65
data/CHANGELOG.md CHANGED
@@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 0.2.0 - 2020-01-14
9
+
10
+ ### Changed
11
+
12
+ - Support for new versions of the official prometheus-client gem. @Envek
13
+
14
+ It is now required to specify not only comments, but also `tags` option for all metrics as prometheus-client now enforces this.
15
+
16
+ Support for specifying tags for metrics was added to yabeda 0.2.
17
+
18
+ ### Removed
19
+
20
+ - Removed support for old versions of the official prometheus-client gem. @Envek
21
+
22
+ Due to incompatible changes in official client API
23
+
24
+ - Removed support for prometheus-client-mmap gem. @Envek
25
+
26
+ Support for multiprocess servers is now included in official Prometheus ruby client.
27
+
28
+
8
29
  ## 0.1.5 - 2019-10-15
9
30
 
10
31
  ### Fixed
data/README.md CHANGED
@@ -16,10 +16,9 @@ Adapter for easy exporting your collected metrics from your application to the [
16
16
 
17
17
  ## Installation
18
18
 
19
- Add this lines to your application's Gemfile:
19
+ Add this line to your application's Gemfile:
20
20
 
21
21
  ```ruby
22
- gem 'prometheus-client' # Or 'prometheus-client-mmap' if you need multi-process support
23
22
  gem 'yabeda-prometheus'
24
23
  ```
25
24
 
@@ -63,6 +62,17 @@ And then execute:
63
62
 
64
63
  Address of push gateway is configured with `PROMETHEUS_PUSH_GATEWAY` env variable.
65
64
 
65
+
66
+ ## Multi-process server support
67
+
68
+ To use Unicorn or Puma in clustered mode, you'll want to set up underlying prometheus-client gem to use `DirectFileStore`, which aggregates metrics across the processes.
69
+
70
+ ```ruby
71
+ Prometheus::Client.config.data_store = Prometheus::Client::DataStores::DirectFileStore.new(dir: '/tmp/prometheus_direct_file_store')
72
+ ```
73
+
74
+ See more information at [prometheus-client README](https://github.com/prometheus/client_ruby#data-stores).
75
+
66
76
  ## Development
67
77
 
68
78
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -5,36 +5,54 @@ require "yabeda/base_adapter"
5
5
 
6
6
  module Yabeda
7
7
  class Prometheus::Adapter < BaseAdapter
8
+ class UndeclaredMetricTags < RuntimeError
9
+ attr_reader :message
10
+
11
+ def initialize(metric_name, caused_exception)
12
+ @message = <<~MESSAGE.strip
13
+ Prometheus requires all used tags to be declared at metric registration time. \
14
+ Please add `tags` option to the declaration of metric `#{metric_name}`. \
15
+ Error: #{caused_exception.message}
16
+ MESSAGE
17
+ end
18
+ end
19
+
8
20
  def registry
9
21
  @registry ||= ::Prometheus::Client.registry
10
22
  end
11
23
 
12
24
  def register_counter!(metric)
13
25
  validate_metric!(metric)
14
- registry.counter(build_name(metric), metric.comment)
26
+ registry.counter(build_name(metric), docstring: metric.comment, labels: Array(metric.tags))
15
27
  end
16
28
 
17
29
  def perform_counter_increment!(metric, tags, value)
18
- registry.get(build_name(metric)).increment(tags, value)
30
+ registry.get(build_name(metric)).increment(by: value, labels: tags)
31
+ rescue ::Prometheus::Client::LabelSetValidator::InvalidLabelSetError => e
32
+ raise UndeclaredMetricTags.new(build_name(metric), e)
19
33
  end
20
34
 
21
35
  def register_gauge!(metric)
22
36
  validate_metric!(metric)
23
- registry.gauge(build_name(metric), metric.comment)
37
+ registry.gauge(build_name(metric), docstring: metric.comment, labels: Array(metric.tags))
24
38
  end
25
39
 
26
40
  def perform_gauge_set!(metric, tags, value)
27
- registry.get(build_name(metric)).set(tags, value)
41
+ registry.get(build_name(metric)).set(value, labels: tags)
42
+ rescue ::Prometheus::Client::LabelSetValidator::InvalidLabelSetError => e
43
+ raise UndeclaredMetricTags.new(build_name(metric), e)
28
44
  end
29
45
 
30
46
  def register_histogram!(metric)
31
47
  validate_metric!(metric)
32
48
  buckets = metric.buckets || ::Prometheus::Client::Histogram::DEFAULT_BUCKETS
33
- registry.histogram(build_name(metric), metric.comment, {}, buckets)
49
+ registry.histogram(build_name(metric), docstring: metric.comment, buckets: buckets, labels: Array(metric.tags))
34
50
  end
35
51
 
36
52
  def perform_histogram_measure!(metric, tags, value)
37
- registry.get(build_name(metric)).observe(tags, value)
53
+ registry.get(build_name(metric)).observe(value, labels: tags)
54
+ rescue ::Prometheus::Client::LabelSetValidator::InvalidLabelSetError => e
55
+ raise UndeclaredMetricTags.new(build_name(metric), e)
38
56
  end
39
57
 
40
58
  def build_name(metric)
@@ -1,19 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- begin
4
- # Try to load exporter from GitLab's prometheus-client-mmap gem
5
- require "prometheus/client/rack/exporter"
6
- BASE_EXPORTER_CLASS = ::Prometheus::Client::Rack::Exporter
7
- rescue LoadError
8
- # Try to load exporter from original prometheus-client
9
- require "prometheus/middleware/exporter"
10
- BASE_EXPORTER_CLASS = ::Prometheus::Middleware::Exporter
11
- end
3
+ require "prometheus/middleware/exporter"
12
4
 
13
5
  module Yabeda
14
6
  module Prometheus
15
7
  # Rack application or middleware that provides metrics exposition endpoint
16
- class Exporter < BASE_EXPORTER_CLASS
8
+ class Exporter < ::Prometheus::Middleware::Exporter
17
9
  NOT_FOUND_HANDLER = lambda do |_env|
18
10
  [404, { "Content-Type" => "text/plain" }, ["Not Found\n"]]
19
11
  end.freeze
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yabeda
4
4
  module Prometheus
5
- VERSION = "0.1.5"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
@@ -25,13 +25,10 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
27
 
28
- spec.add_dependency "yabeda"
28
+ spec.required_ruby_version = ">= 2.3"
29
29
 
30
- spec.post_install_message = <<~MESSAGE
31
- You need to have installed either prometheus-client or prometheus-client-mmap
32
- gem for yabeda-prometheus to work.
33
- Please make sure that you have added one of them to your Gemfile.
34
- MESSAGE
30
+ spec.add_dependency "prometheus-client", "~> 1.0"
31
+ spec.add_dependency "yabeda", "~> 0.2"
35
32
 
36
33
  spec.add_development_dependency "bundler", "~> 1.17"
37
34
  spec.add_development_dependency "rake", "~> 12.0"
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yabeda-prometheus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Novikov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-15 00:00:00.000000000 Z
11
+ date: 2020-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prometheus-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: yabeda
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - ">="
31
+ - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '0'
33
+ version: '0.2'
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - ">="
38
+ - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '0'
40
+ version: '0.2'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -96,10 +110,7 @@ metadata:
96
110
  homepage_uri: https://github.com/yabeda-rb/yabeda-prometheus
97
111
  source_code_uri: https://github.com/yabeda-rb/yabeda-prometheus
98
112
  changelog_uri: https://github.com/yabeda-rb/yabeda-prometheus/blob/master/CHANGELOG.md
99
- post_install_message: |
100
- You need to have installed either prometheus-client or prometheus-client-mmap
101
- gem for yabeda-prometheus to work.
102
- Please make sure that you have added one of them to your Gemfile.
113
+ post_install_message:
103
114
  rdoc_options: []
104
115
  require_paths:
105
116
  - lib
@@ -107,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
118
  requirements:
108
119
  - - ">="
109
120
  - !ruby/object:Gem::Version
110
- version: '0'
121
+ version: '2.3'
111
122
  required_rubygems_version: !ruby/object:Gem::Requirement
112
123
  requirements:
113
124
  - - ">="