Commit 61302615 authored by Hercules Merscher's avatar Hercules Merscher 🌴 Committed by Bob Van Landuyt
Browse files

feat(metrics): add the metrics labkit module

This adds the metrics module as a wrapper around `Prometheus::Client`
from our own `prometheus-client-mmap` gem. 

This makes initialization much easier for the implementing applications
and should always be threadsafe to use.

Having the metrics library in Labkit allows us to build on top of this
for Covered Experiences that will also need to emit metrics and logs.

Related to gitlab-com/gl-infra/observability/team#4125
parent c51bab6f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ LabKit-Ruby provides functionality in a number of areas:
1. `Labkit::Correlation` For accessing the correlation id. (Generated and propagated by `Labkit::Context`)
1. `Labkit::FIPS` for checking for FIPS mode and using FIPS-compliant algorithms.
1. `Labkit::Logging` for sanitizing log messages.
1. `Labkit::Metrics` for metrics. More on the [README](./lib/labkit/metrics/README.md).
1. `Labkit::Tracing` for handling and propagating distributed traces.

## Developing
+9 −0
Original line number Diff line number Diff line
@@ -26,3 +26,12 @@ task :fix => ["rubocop:autocorrect"]
task :verify => %w[spec rubocop]

task :default => %w[verify build]

desc "Start an IRB console with gem pre-loaded"
task :console do
  $LOAD_PATH.unshift(File.expand_path("lib", __dir__))
  require "irb"
  require "gitlab-labkit"
  ARGV.clear
  IRB.start
end
+3 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
  spec.add_runtime_dependency "jaeger-client", "~> 1.1.0"
  spec.add_runtime_dependency "opentracing", "~> 0.4"
  spec.add_runtime_dependency "pg_query", ">= 6.1.0", "< 7.0"
  spec.add_runtime_dependency "prometheus-client-mmap", "~> 1.2.9"
  spec.add_runtime_dependency "redis", "> 3.0.0", "< 6.0.0"

  # Please maintain alphabetical order for dev dependencies
@@ -36,7 +37,9 @@ Gem::Specification.new do |spec|
  spec.add_development_dependency "grpc-tools", ">= 1.62"
  spec.add_development_dependency "httparty", "~> 0.22.0"
  spec.add_development_dependency "httpclient", "~> 2.9.0"
  spec.add_development_dependency "irb", "~> 1.15.2"
  spec.add_development_dependency "pry", "~> 0.12"
  spec.add_development_dependency "pry-byebug", "~> 3.11"
  spec.add_development_dependency "rack", "~> 2.0"
  spec.add_development_dependency "rake", "~> 13.2"
  spec.add_development_dependency "rest-client", "~> 2.1.0"
+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ module Labkit
  autoload :FIPS, "labkit/fips"
  autoload :Tracing, "labkit/tracing"
  autoload :Logging, "labkit/logging"
  autoload :Metrics, "labkit/metrics"
  autoload :Middleware, "labkit/middleware"

  # Publishers to publish notifications whenever a HTTP reqeust is made.

lib/labkit/metrics.rb

0 → 100644
+19 −0
Original line number Diff line number Diff line
# frozen_string_literal: true

require "prometheus/client/formats/text"

module Labkit
  # Metrics provides functionality for producing metrics
  module Metrics
    autoload :Client, "labkit/metrics/client"
    autoload :RackExporter, "labkit/metrics/rack_exporter"
    autoload :Null, "labkit/metrics/null"

    class << self
      def prometheus_metrics_text
        dir = Client.configuration.multiprocess_files_dir
        ::Prometheus::Client::Formats::Text.marshal_multiprocess(dir)
      end
    end
  end
end
Loading