gitlab-labkit 0.41.2 → 0.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.pre-commit-config.yaml +1 -1
- data/lib/gitlab-labkit.rb +1 -0
- data/lib/labkit/context.rb +11 -4
- data/lib/labkit/correlation/correlation_id.rb +3 -3
- data/lib/labkit/fields.rb +41 -0
- data/lib/labkit/logging/json_logger.rb +1 -1
- data/lib/labkit/logging/sanitizer.rb +8 -1
- data/lib/labkit/middleware/rack.rb +1 -1
- data/lib/labkit/middleware/sidekiq/context/client.rb +1 -1
- metadata +2 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 869346480f346d49795eaf4f80e028c4cdbbdb8826345cfcfdff8ddf8e1887fd
         | 
| 4 | 
            +
              data.tar.gz: 63ce86b345417ab4c6ad076dd6f83baca61d4e127c478b857e509c4b34814000
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: c18e81580f71d9d6833e5d7c07d58fb699ec82df5d8707af38adbedabe6e7a197d0fe1e3cef00f0df7afa740dc5f343c100faf283e97d586419a1134bcf0501b
         | 
| 7 | 
            +
              data.tar.gz: c5d346b9f186a33faa420e5e6fe8513f7af58c829748fe98470c5b6d45d27cb0c2620f56f4cca56729e896ea3daf59d9caa3bdca4aad95b79c3fed5b0052635c
         | 
    
        data/.pre-commit-config.yaml
    CHANGED
    
    | @@ -25,7 +25,7 @@ repos: | |
| 25 25 | 
             
              # Documentation available at
         | 
| 26 26 | 
             
              # https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks/-/blob/main/docs/pre-commit.md
         | 
| 27 27 | 
             
              - repo: https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks
         | 
| 28 | 
            -
                rev: v2. | 
| 28 | 
            +
                rev: v2.94  # renovate:managed
         | 
| 29 29 |  | 
| 30 30 | 
             
                hooks:
         | 
| 31 31 | 
             
                  - id: shellcheck  # Run shellcheck for changed Shell files
         | 
    
        data/lib/gitlab-labkit.rb
    CHANGED
    
    | @@ -15,6 +15,7 @@ module Labkit | |
| 15 15 | 
             
              autoload :Logging, "labkit/logging"
         | 
| 16 16 | 
             
              autoload :Metrics, "labkit/metrics"
         | 
| 17 17 | 
             
              autoload :Middleware, "labkit/middleware"
         | 
| 18 | 
            +
              autoload :Fields, "labkit/fields"
         | 
| 18 19 |  | 
| 19 20 | 
             
              # Publishers to publish notifications whenever a HTTP reqeust is made.
         | 
| 20 21 | 
             
              # A broadcasted notification's payload in topic "request.external_http" includes:
         | 
    
        data/lib/labkit/context.rb
    CHANGED
    
    | @@ -7,6 +7,8 @@ require "active_support/core_ext/string/starts_ends_with" | |
| 7 7 | 
             
            require "active_support/core_ext/string/inflections"
         | 
| 8 8 | 
             
            require "active_support/core_ext/object/blank"
         | 
| 9 9 |  | 
| 10 | 
            +
            require_relative "fields"
         | 
| 11 | 
            +
             | 
| 10 12 | 
             
            module Labkit
         | 
| 11 13 | 
             
              # A context can be used to provide structured information on what resources
         | 
| 12 14 | 
             
              # GitLab is working on within a service.
         | 
| @@ -24,9 +26,14 @@ module Labkit | |
| 24 26 | 
             
              #   end
         | 
| 25 27 | 
             
              #
         | 
| 26 28 | 
             
              class Context
         | 
| 29 | 
            +
                # The meta log key is used to effectively aggregate
         | 
| 30 | 
            +
                # the attributes that we should be associating with
         | 
| 31 | 
            +
                # the logs that we emit.
         | 
| 32 | 
            +
                # These fields will get propagated across all services
         | 
| 33 | 
            +
                # which will allow us to correlate logs across these
         | 
| 34 | 
            +
                # different services.
         | 
| 27 35 | 
             
                LOG_KEY = "meta"
         | 
| 28 | 
            -
                 | 
| 29 | 
            -
                RAW_KEYS = [CORRELATION_ID_KEY].freeze
         | 
| 36 | 
            +
                RAW_KEYS = [Fields::CORRELATION_ID].freeze
         | 
| 30 37 |  | 
| 31 38 | 
             
                class << self
         | 
| 32 39 | 
             
                  def with_context(attributes = {})
         | 
| @@ -92,7 +99,7 @@ module Labkit | |
| 92 99 | 
             
                end
         | 
| 93 100 |  | 
| 94 101 | 
             
                def correlation_id
         | 
| 95 | 
            -
                  data[ | 
| 102 | 
            +
                  data[Fields::CORRELATION_ID]
         | 
| 96 103 | 
             
                end
         | 
| 97 104 |  | 
| 98 105 | 
             
                def get_attribute(attribute)
         | 
| @@ -113,7 +120,7 @@ module Labkit | |
| 113 120 |  | 
| 114 121 | 
             
                  # Assign a correlation if it was missing in the first context or when
         | 
| 115 122 | 
             
                  # explicitly removed
         | 
| 116 | 
            -
                  data[ | 
| 123 | 
            +
                  data[Fields::CORRELATION_ID] ||= new_id
         | 
| 117 124 |  | 
| 118 125 | 
             
                  data
         | 
| 119 126 | 
             
                end
         | 
| @@ -5,11 +5,11 @@ module Labkit | |
| 5 5 | 
             
                # CorrelationId module provides access the Correlation-ID
         | 
| 6 6 | 
             
                # of the current request
         | 
| 7 7 | 
             
                module CorrelationId
         | 
| 8 | 
            -
                  LOG_KEY = Labkit::Context::CORRELATION_ID_KEY
         | 
| 9 | 
            -
             | 
| 10 8 | 
             
                  class << self
         | 
| 11 9 | 
             
                    def use_id(correlation_id)
         | 
| 12 | 
            -
                      Labkit::Context.with_context( | 
| 10 | 
            +
                      Labkit::Context.with_context(
         | 
| 11 | 
            +
                        Labkit::Fields::CORRELATION_ID => correlation_id
         | 
| 12 | 
            +
                      ) do |context|
         | 
| 13 13 | 
             
                        yield(context.correlation_id)
         | 
| 14 14 | 
             
                      end
         | 
| 15 15 | 
             
                    end
         | 
| @@ -0,0 +1,41 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Labkit
         | 
| 4 | 
            +
              ##
         | 
| 5 | 
            +
              # Fields is intended to be a SSOT for all of the common field names that
         | 
| 6 | 
            +
              # we emit via any observability we add to our systems.
         | 
| 7 | 
            +
              #
         | 
| 8 | 
            +
              # These fields should span multiple services. This is
         | 
| 9 | 
            +
              #
         | 
| 10 | 
            +
              # The goal of this package is to reduce the likelihood for typos or
         | 
| 11 | 
            +
              # subtly different naming conventions. This will help to ensure we
         | 
| 12 | 
            +
              # are able to marry up logs between different systems as a request
         | 
| 13 | 
            +
              # is being processed.
         | 
| 14 | 
            +
              #
         | 
| 15 | 
            +
              # Usage:
         | 
| 16 | 
            +
              #   require 'labkit/fields'
         | 
| 17 | 
            +
              #   ...
         | 
| 18 | 
            +
              #   data[Labkit::Fields::GL_USER_ID] = user.id
         | 
| 19 | 
            +
              #   ...
         | 
| 20 | 
            +
              #
         | 
| 21 | 
            +
              module Fields
         | 
| 22 | 
            +
                # correlation_id - string
         | 
| 23 | 
            +
                #
         | 
| 24 | 
            +
                # This field is used to correlate
         | 
| 25 | 
            +
                # the logs emitted by all of our systems.
         | 
| 26 | 
            +
                #
         | 
| 27 | 
            +
                # This should be present in all log line
         | 
| 28 | 
            +
                # emissions.
         | 
| 29 | 
            +
                CORRELATION_ID = "correlation_id"
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                # We'll need to add the rest of the top
         | 
| 32 | 
            +
                # level fields here:
         | 
| 33 | 
            +
                # [endpoint_id, duration_s, status_code]
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                # gl_user_id - integer
         | 
| 36 | 
            +
                GL_USER_ID = "gl_user_id"
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                # gl_user_name - string
         | 
| 39 | 
            +
                GL_USER_NAME = "gl_user_name"
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
            end
         | 
| @@ -42,7 +42,7 @@ module Labkit | |
| 42 42 | 
             
                    data[:time] = timestamp.utc.iso8601(3)
         | 
| 43 43 |  | 
| 44 44 | 
             
                    if self.class.exclude_context?
         | 
| 45 | 
            -
                      data[Labkit:: | 
| 45 | 
            +
                      data[Labkit::Fields::CORRELATION_ID] = Labkit::Correlation::CorrelationId.current_id
         | 
| 46 46 | 
             
                    else
         | 
| 47 47 | 
             
                      data.merge!(Labkit::Context.current.to_h)
         | 
| 48 48 | 
             
                    end
         | 
| @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 3 | 
             
            require "pg_query"
         | 
| 4 | 
            +
            require "uri"
         | 
| 4 5 |  | 
| 5 6 | 
             
            module Labkit
         | 
| 6 7 | 
             
              module Logging
         | 
| @@ -47,8 +48,14 @@ module Labkit | |
| 47 48 | 
             
                    #     URI::RFC2396_PARSER.parse('ssh://') => raise URI::InvalidURIError
         | 
| 48 49 | 
             
                    return "" if p.host.empty?
         | 
| 49 50 |  | 
| 50 | 
            -
                     | 
| 51 | 
            +
                    # Starting from v1.0.4, the `uri` gem clears the `password` instance variable
         | 
| 52 | 
            +
                    # when the `user` setter is called. To preserve the current behavior,
         | 
| 53 | 
            +
                    # we store the `password` in a temporary variable.
         | 
| 54 | 
            +
                    password = p.password
         | 
| 55 | 
            +
             | 
| 51 56 | 
             
                    p.user = "*****" if p.user.present?
         | 
| 57 | 
            +
                    p.password = "*****" if password.present?
         | 
| 58 | 
            +
             | 
| 52 59 | 
             
                    p.to_s
         | 
| 53 60 | 
             
                  rescue URI::InvalidURIError
         | 
| 54 61 | 
             
                    ""
         | 
| @@ -18,7 +18,7 @@ module Labkit | |
| 18 18 | 
             
                  end
         | 
| 19 19 |  | 
| 20 20 | 
             
                  def call(env)
         | 
| 21 | 
            -
                    Labkit::Context.with_context(Labkit:: | 
| 21 | 
            +
                    Labkit::Context.with_context(Labkit::Fields::CORRELATION_ID => correlation_id(env)) do |context|
         | 
| 22 22 | 
             
                      status, headers, response = @app.call(env)
         | 
| 23 23 |  | 
| 24 24 | 
             
                      headers[HEADER] = context_to_json(context)
         | 
| @@ -15,7 +15,7 @@ module Labkit | |
| 15 15 | 
             
                        # will always generate a new correlation_id and we'd rather carry
         | 
| 16 16 | 
             
                        # through the correlation_id from the previous job if it is
         | 
| 17 17 | 
             
                        # present (eg. for retries).
         | 
| 18 | 
            -
                        attributes[Labkit:: | 
| 18 | 
            +
                        attributes[Labkit::Fields::CORRELATION_ID] = job["correlation_id"] if job["correlation_id"]
         | 
| 19 19 |  | 
| 20 20 | 
             
                        Labkit::Context.with_context(attributes) do |context|
         | 
| 21 21 | 
             
                          job.merge!(context.to_h)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: gitlab-labkit
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.42.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Andrew Newdigate
         | 
| @@ -466,6 +466,7 @@ files: | |
| 466 466 | 
             
            - lib/labkit/covered_experience/null.rb
         | 
| 467 467 | 
             
            - lib/labkit/covered_experience/registry.rb
         | 
| 468 468 | 
             
            - lib/labkit/excon_publisher.rb
         | 
| 469 | 
            +
            - lib/labkit/fields.rb
         | 
| 469 470 | 
             
            - lib/labkit/fips.rb
         | 
| 470 471 | 
             
            - lib/labkit/httpclient_publisher.rb
         | 
| 471 472 | 
             
            - lib/labkit/logging.rb
         |