lib/fluent/plugin/monitoring.rb in fluent-plugin-google-cloud-0.7.20 vs lib/fluent/plugin/monitoring.rb in fluent-plugin-google-cloud-0.7.21
- old
+ new
@@ -11,13 +11,31 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
module Monitoring
+ # Base class for the counter.
+ class BaseCounter
+ def increment(_by: 1, _labels: {})
+ nil
+ end
+ end
+
+ # Prometheus implementation of counters.
+ class PrometheusCounter < BaseCounter
+ def initialize(prometheus_counter)
+ @counter = prometheus_counter
+ end
+
+ def increment(by: 1, labels: {})
+ @counter.increment(labels, by)
+ end
+ end
+
# Base class for the monitoring registry.
class BaseMonitoringRegistry
- def counter(_name, _desc)
+ def counter(_name, _labels, _docstring)
nil
end
end
# Prometheus implementation of the monitoring registry, that uses the default
@@ -31,13 +49,13 @@
require 'prometheus/client'
@registry = Prometheus::Client.registry
end
# Exception-driven behavior to avoid synchronization errors.
- def counter(name, desc)
- return @registry.counter(name, desc)
+ def counter(name, labels, docstring)
+ return PrometheusCounter.new(@registry.counter(name, docstring, labels))
rescue Prometheus::Client::Registry::AlreadyRegisteredError
- return @registry.get(name)
+ return PrometheusCounter.new(@registry.get(name))
end
end
# Factory that is used to create a monitoring registry based on
# the monitoring solution name.