fluent-plugin-google-cloud 0.7.23 → 0.7.24

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: 9750420a63d27c1e40553ca6f4a81cfc372e5ad88b72b838136e24deb3f15b1e
4
- data.tar.gz: c8b06e1d2e0c47b59127393ad90e7c846956708b0137b86b568a697b91a58e9a
3
+ metadata.gz: 527f693c53835e46491da82100bf40d63c512ff8bbc1a5d087c9b3371ed11df8
4
+ data.tar.gz: 293ae1af2b793cbc199a112bffe3491f4ef7dbb1e99776ffe4cb3268db662186
5
5
  SHA512:
6
- metadata.gz: 6fd32eccca522aa89331bbf553bcd1efd9d09d3f8f4e1f4632257a45f5f29007630eda81956c702c3ee4db32a804c8e51864d70a6f2a9c86b5b3c4c9f2eb60ca
7
- data.tar.gz: 4f1b6d55766b0938d2c71f6f26bc76b9294448fc2d341be769a7f61dfc68d88940d2e85174a5d54d6db865f1b8d7d1e8d8226dffad5e113156b407e25d23a199
6
+ metadata.gz: 410f93cf504d5fb3aada4121cf4531ff9e8aa152ab71bdb6f6a35e9d42394bd5becd69352cdb21fcf6b08a86c94a23e8782dfaca016415e8b22a1b6e008080e7
7
+ data.tar.gz: a9665e0d2755ceb29cf1ea5a83e9f21a67384c4cf4d582cb4ef6db64d8931178325c6a94fa811c12e9c0e6b4d54d2a2cb7cd2334bf9e3b3f568a7a93a9d24a4e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-google-cloud (0.7.23)
4
+ fluent-plugin-google-cloud (0.7.24)
5
5
  fluentd (= 1.6.3)
6
6
  google-api-client (= 0.30.8)
7
7
  google-cloud-logging (= 1.6.6)
@@ -45,7 +45,7 @@ GEM
45
45
  representable (~> 3.0)
46
46
  retriable (>= 2.0, < 4.0)
47
47
  signet (~> 0.10)
48
- google-cloud-core (1.4.0)
48
+ google-cloud-core (1.4.1)
49
49
  google-cloud-env (~> 1.0)
50
50
  google-cloud-env (1.3.0)
51
51
  faraday (~> 0.11)
@@ -10,7 +10,7 @@ eos
10
10
  gem.homepage =
11
11
  'https://github.com/GoogleCloudPlatform/fluent-plugin-google-cloud'
12
12
  gem.license = 'Apache-2.0'
13
- gem.version = '0.7.23'
13
+ gem.version = '0.7.24'
14
14
  gem.authors = ['Stackdriver Agents Team']
15
15
  gem.email = ['stackdriver-agents@google.com']
16
16
  gem.required_ruby_version = Gem::Requirement.new('>= 2.2')
@@ -33,13 +33,15 @@ module Monitoring
33
33
 
34
34
  # OpenCensus implementation of counters.
35
35
  class OpenCensusCounter < BaseCounter
36
- def initialize(recorder, measure)
36
+ def initialize(recorder, measure, translator)
37
37
  raise ArgumentError, 'measure must not be nil' if measure.nil?
38
38
  @recorder = recorder
39
39
  @measure = measure
40
+ @translator = translator
40
41
  end
41
42
 
42
43
  def increment(by: 1, labels: {})
44
+ labels = @translator.translate_labels(labels)
43
45
  tag_map = OpenCensus::Tags::TagMap.new(
44
46
  labels.map { |k, v| [k.to_s, v.to_s] }.to_h)
45
47
  @recorder.record(@measure.create_measurement(value: by, tags: tag_map))
@@ -74,8 +76,12 @@ module Monitoring
74
76
  end
75
77
 
76
78
  # Exception-driven behavior to avoid synchronization errors.
77
- def counter(name, labels, docstring)
78
- return PrometheusCounter.new(@registry.counter(name, docstring, labels))
79
+ def counter(name, _labels, docstring)
80
+ # When we upgrade to Prometheus client 0.10.0 or higher, pass the
81
+ # labels in the metric constructor. The 'labels' field in
82
+ # Prometheus client 0.9.0 has a different function and will not
83
+ # work as intended.
84
+ return PrometheusCounter.new(@registry.counter(name, docstring))
79
85
  rescue Prometheus::Client::Registry::AlreadyRegisteredError
80
86
  return PrometheusCounter.new(@registry.get(name))
81
87
  end
@@ -105,48 +111,28 @@ module Monitoring
105
111
  end
106
112
 
107
113
  def counter(name, labels, docstring)
108
- name = OpenCensusMonitoringRegistry.translate_metric_name(name)
109
- measure = OpenCensus::Stats::MeasureRegistry.get(name)
114
+ translator = MetricTranslator.new(name, labels)
115
+ measure = OpenCensus::Stats::MeasureRegistry.get(translator.name)
110
116
  if measure.nil?
111
117
  measure = OpenCensus::Stats.create_measure_int(
112
- name: name,
118
+ name: translator.name,
113
119
  unit: OpenCensus::Stats::Measure::UNIT_NONE,
114
120
  description: docstring
115
121
  )
116
122
  end
117
123
  OpenCensus::Stats.create_and_register_view(
118
- name: name,
124
+ name: translator.name,
119
125
  measure: measure,
120
126
  aggregation: OpenCensus::Stats.create_sum_aggregation,
121
127
  description: docstring,
122
- columns: labels.map(&:to_s)
128
+ columns: translator.view_labels.map(&:to_s)
123
129
  )
124
- OpenCensusCounter.new(@recorder, measure)
130
+ OpenCensusCounter.new(@recorder, measure, translator)
125
131
  end
126
132
 
127
133
  def export
128
134
  @exporter.export @recorder.views_data
129
135
  end
130
-
131
- class << self
132
- # Translate the internal metrics to the curated metrics in Stackdriver.
133
- # The Prometheus metrics are collected by Google Kubernetes Engine's
134
- # monitoring, so we can't redefine them.
135
- def translate_metric_name(name)
136
- case name
137
- when :stackdriver_successful_requests_count,
138
- :stackdriver_failed_requests_count
139
- :request_count
140
- when :stackdriver_ingested_entries_count,
141
- :stackdriver_dropped_entries_count
142
- :log_entry_count
143
- when :stackdriver_retried_entries_count
144
- :log_entry_retry_count
145
- else
146
- name
147
- end
148
- end
149
- end
150
136
  end
151
137
 
152
138
  # Factory that is used to create a monitoring registry based on
@@ -168,4 +154,39 @@ module Monitoring
168
154
  registry.new(project_id, monitored_resource)
169
155
  end
170
156
  end
157
+
158
+ # Translate the internal metrics to the curated metrics in Stackdriver. The
159
+ # Prometheus metrics are collected by Google Kubernetes Engine's monitoring,
160
+ # so we can't redefine them.
161
+ # Avoid this mechanism for new metrics by defining them in their final form,
162
+ # so they don't need translation.
163
+ class MetricTranslator
164
+ attr_reader :name
165
+ attr_reader :view_labels
166
+
167
+ def initialize(name, metric_labels)
168
+ @legacy = true
169
+ case name
170
+ when :stackdriver_successful_requests_count,
171
+ :stackdriver_failed_requests_count
172
+ @name = :request_count
173
+ when :stackdriver_ingested_entries_count,
174
+ :stackdriver_dropped_entries_count
175
+ @name = :log_entry_count
176
+ when :stackdriver_retried_entries_count
177
+ @name = :log_entry_retry_count
178
+ else
179
+ @name = name
180
+ @legacy = false
181
+ end
182
+ # Collapsed from [:response_code, :grpc]
183
+ @view_labels = @legacy ? [:response_code] : metric_labels
184
+ end
185
+
186
+ def translate_labels(labels)
187
+ return labels unless @legacy
188
+ translation = { code: :response_code, grpc: :grpc }
189
+ labels.map { |k, v| [translation[k], v] }.to_h
190
+ end
191
+ end
171
192
  end
@@ -2734,8 +2734,15 @@ module BaseTest
2734
2734
  end
2735
2735
 
2736
2736
  def assert_opencensus_metric_value(metric_name, expected_value, labels = {})
2737
- metric_name = Monitoring::OpenCensusMonitoringRegistry
2738
- .translate_metric_name(metric_name)
2737
+ translator = Monitoring::MetricTranslator.new(metric_name, labels)
2738
+ metric_name = translator.name
2739
+ labels = translator.translate_labels(labels)
2740
+ # The next line collapses the labels to assert against the aggregated data,
2741
+ # which can have some labels removed. Without this, it would test against
2742
+ # the raw data. The view is more representative of the user experience, even
2743
+ # though both tests should work because currently we only aggregate away one
2744
+ # label that never changes during runtime.
2745
+ labels.select! { |k, _| translator.view_labels.include? k }
2739
2746
  labels = labels.map { |k, v| [k.to_s, v.to_s] }.to_h
2740
2747
  stats_recorder = OpenCensus::Stats.ensure_recorder
2741
2748
  view_data = stats_recorder.view_data metric_name
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-google-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.23
4
+ version: 0.7.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stackdriver Agents Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-26 00:00:00.000000000 Z
11
+ date: 2019-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd