New Upstream Release - ruby-gitlab-labkit

Ready changes

Summary

Merged new upstream version: 0.33.0 (was: 0.31.1).

Diff

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index df46015..812fdfd 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,5 +1,5 @@
 default:
-  image: ruby:2.7
+  image: ruby:3.1
 
 workflow:
   rules:
@@ -11,19 +11,22 @@ workflow:
     - if: '$CI_COMMIT_TAG'
 
 .test_template: &test_definition
+  image: ruby:${RUBY_VERSION}
   stage: test
   script:
-    - gem install bundler
+    - gem install bundler --no-document
+    - bundle config --local path vendor
     - bundle install
     - bundle exec rake verify build install
-
-test:3.0:
-  image: ruby:3.0
-  <<: *test_definition
-
-test:2.7:
-  image: ruby:2.7
+  cache:
+    key: ${CI_JOB_IMAGE}
+    paths:
+      - vendor/ruby
+ruby:
   <<: *test_definition
+  parallel:
+    matrix:
+      - RUBY_VERSION: ["2.7", "3.0", "3.1", "3.2"]
 
 static-analysis:
   before_script:
diff --git a/debian/changelog b/debian/changelog
index a73a6c9..8db73d9 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+ruby-gitlab-labkit (0.33.0-1) UNRELEASED; urgency=low
+
+  * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Thu, 08 Jun 2023 16:19:44 -0000
+
 ruby-gitlab-labkit (0.31.1-1) experimental; urgency=medium
 
   * Team upload.
diff --git a/debian/patches/relax-jaeger-client.patch b/debian/patches/relax-jaeger-client.patch
index 99f0724..d4b3ea3 100644
--- a/debian/patches/relax-jaeger-client.patch
+++ b/debian/patches/relax-jaeger-client.patch
@@ -1,11 +1,13 @@
---- a/gitlab-labkit.gemspec
-+++ b/gitlab-labkit.gemspec
-@@ -22,7 +22,7 @@
+Index: ruby-gitlab-labkit.git/gitlab-labkit.gemspec
+===================================================================
+--- ruby-gitlab-labkit.git.orig/gitlab-labkit.gemspec
++++ ruby-gitlab-labkit.git/gitlab-labkit.gemspec
+@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
    spec.add_runtime_dependency "actionpack", ">= 5.0.0", "< 8.0.0"
    spec.add_runtime_dependency "activesupport", ">= 5.0.0", "< 8.0.0"
    spec.add_runtime_dependency "grpc", ">= 1.37" # Be sure to update the "grpc-tools" dev_dependency too
 -  spec.add_runtime_dependency "jaeger-client", "~> 1.1.0"
 +  spec.add_runtime_dependency "jaeger-client", "~> 1.1"
    spec.add_runtime_dependency "opentracing", "~> 0.4"
-   spec.add_runtime_dependency "pg_query", "~> 2.1"
+   spec.add_runtime_dependency "pg_query", "~> 4.2.1"
    spec.add_runtime_dependency "redis", ">3.0.0", "<6.0.0"
diff --git a/debian/patches/remove-git-from-gemspec.patch b/debian/patches/remove-git-from-gemspec.patch
index 4e001f6..298fe3f 100644
--- a/debian/patches/remove-git-from-gemspec.patch
+++ b/debian/patches/remove-git-from-gemspec.patch
@@ -1,8 +1,10 @@
 debian source is not a git repo
 
---- a/gitlab-labkit.gemspec
-+++ b/gitlab-labkit.gemspec
-@@ -5,7 +5,7 @@
+Index: ruby-gitlab-labkit.git/gitlab-labkit.gemspec
+===================================================================
+--- ruby-gitlab-labkit.git.orig/gitlab-labkit.gemspec
++++ ruby-gitlab-labkit.git/gitlab-labkit.gemspec
+@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PAT
  
  Gem::Specification.new do |spec|
    spec.name = "gitlab-labkit"
diff --git a/gitlab-labkit.gemspec b/gitlab-labkit.gemspec
index 921226c..5493b57 100644
--- a/gitlab-labkit.gemspec
+++ b/gitlab-labkit.gemspec
@@ -24,12 +24,12 @@ Gem::Specification.new do |spec|
   spec.add_runtime_dependency "grpc", ">= 1.37" # Be sure to update the "grpc-tools" dev_dependency too
   spec.add_runtime_dependency "jaeger-client", "~> 1.1.0"
   spec.add_runtime_dependency "opentracing", "~> 0.4"
-  spec.add_runtime_dependency "pg_query", "~> 2.1"
+  spec.add_runtime_dependency "pg_query", "~> 4.2.1"
   spec.add_runtime_dependency "redis", ">3.0.0", "<6.0.0"
 
   # Please maintain alphabetical order for dev dependencies
   spec.add_development_dependency "excon", "~> 0.78.1"
-  spec.add_development_dependency "faraday", "~> 1.2.0"
+  spec.add_development_dependency "faraday", "~> 1.0"
   spec.add_development_dependency "gitlab-dangerfiles", "~> 2.11.0"
   spec.add_development_dependency "gitlab-styles", "~> 6.2.0"
   spec.add_development_dependency "grpc-tools", ">= 1.37"
@@ -39,8 +39,8 @@ Gem::Specification.new do |spec|
   spec.add_development_dependency "rack", "~> 2.0"
   spec.add_development_dependency "rake", "~> 12.3"
   spec.add_development_dependency "rest-client", "~> 2.1.0"
-  spec.add_development_dependency "rspec", "~> 3.10.0"
-  spec.add_development_dependency "rspec-parameterized", "~> 0.4"
+  spec.add_development_dependency "rspec", "~> 3.12.0"
+  spec.add_development_dependency "rspec-parameterized", "~> 1.0"
   spec.add_development_dependency "rufo", "0.9.0"
   spec.add_development_dependency "sidekiq", ">= 5.2", "< 7"
   spec.add_development_dependency "webrick", "~> 1.7.0"
diff --git a/lib/labkit/context.rb b/lib/labkit/context.rb
index 041462c..aaf8319 100644
--- a/lib/labkit/context.rb
+++ b/lib/labkit/context.rb
@@ -26,7 +26,6 @@ module Labkit
     LOG_KEY = "meta"
     CORRELATION_ID_KEY = "correlation_id"
     RAW_KEYS = [CORRELATION_ID_KEY].freeze
-    HEADER_PREFIX = "X-Gitlab-"
 
     class << self
       def with_context(attributes = {})
@@ -71,10 +70,6 @@ module Labkit
         @known_log_keys ||= (KNOWN_KEYS.map(&method(:log_key)) + RAW_KEYS).freeze
       end
 
-      def header_name(name)
-        HEADER_PREFIX + log_key(name).titlecase(keep_id_suffix: true).gsub(/\W/, "-")
-      end
-
       private
 
       def contexts
@@ -103,12 +98,6 @@ module Labkit
       data[CORRELATION_ID_KEY]
     end
 
-    def to_headers
-      to_h.except(CORRELATION_ID_KEY).transform_keys do |key|
-        self.class.header_name(key)
-      end
-    end
-
     def get_attribute(attribute)
       raw = call_or_value(data[log_key(attribute)])
 
diff --git a/lib/labkit/logging/json_logger.rb b/lib/labkit/logging/json_logger.rb
index 7f8145c..baac5a8 100644
--- a/lib/labkit/logging/json_logger.rb
+++ b/lib/labkit/logging/json_logger.rb
@@ -23,6 +23,15 @@ module Labkit
         ENV.fetch("GITLAB_LOG_LEVEL", fallback)
       end
 
+      def self.exclude_context!
+        @exclude_context = true
+        self
+      end
+
+      def self.exclude_context?
+        !!@exclude_context
+      end
+
       def initialize(path, level: JsonLogger.log_level)
         super
       end
@@ -31,7 +40,12 @@ module Labkit
         data = default_attributes
         data[:severity] = severity
         data[:time] = timestamp.utc.iso8601(3)
-        data[Labkit::Correlation::CorrelationId::LOG_KEY] = Labkit::Correlation::CorrelationId.current_id
+
+        if self.class.exclude_context?
+          data[Labkit::Correlation::CorrelationId::LOG_KEY] = Labkit::Correlation::CorrelationId.current_id
+        else
+          data.merge!(Labkit::Context.current.to_h)
+        end
 
         case message
         when String
diff --git a/lib/labkit/middleware/rack.rb b/lib/labkit/middleware/rack.rb
index a836c57..ea93f36 100644
--- a/lib/labkit/middleware/rack.rb
+++ b/lib/labkit/middleware/rack.rb
@@ -1,9 +1,12 @@
 # frozen_string_literal: true
 
 require "action_dispatch"
+require "json"
 
 module Labkit
   module Middleware
+    HEADER = "X-Gitlab-Meta"
+
     # This is a rack middleware to be inserted in GitLab-rails
     # It makes sure that there's always a root context containing the correlation
     # id.
@@ -15,8 +18,12 @@ module Labkit
       end
 
       def call(env)
-        Labkit::Context.with_context(Labkit::Context::CORRELATION_ID_KEY => correlation_id(env)) do
-          @app.call(env)
+        Labkit::Context.with_context(Labkit::Context::CORRELATION_ID_KEY => correlation_id(env)) do |context|
+          status, headers, response = @app.call(env)
+
+          headers[HEADER] = context_to_json(context)
+
+          [status, headers, response]
         end
       end
 
@@ -29,6 +36,14 @@ module Labkit
       def request(env)
         ActionDispatch::Request.new(env)
       end
+
+      def context_to_json(context)
+        context
+          .to_h
+          .transform_keys { |k| k.delete_prefix("meta.") }
+          .merge("version" => "1")
+          .to_json
+      end
     end
   end
 end

More details

Full run details

Historical runs