Module: Labkit::Fields::Deprecated

Defined in:
lib/labkit/fields.rb

Constant Summary collapse

MAPPINGS =

This module tracks deprecated field names and maps them to their standard replacements. These mappings are used by the field scanner to identify and track usage of deprecated fields in the codebase.

{
  Fields::CORRELATION_ID => %w[tags.correlation_id],
  Fields::GL_USER_ID => %w[user_id userid extra.user_id extra.current_user_id meta.user_id],
  Fields::GL_USER_NAME => %w[username extra.user meta.user],
  Fields::ERROR_MESSAGE => %w[error err error.message exception.message graphql_errors],
  Fields::HTTP_STATUS_CODE => %w[status_code extra.status status_text http_status],
  Fields::HTTP_URL => %w[req_url],
  Fields::DURATION_S => %w[duration duration_ms elapsed_time actual_duration time_ms total_time gitaly.duration],
  Fields::REMOTE_IP => %w[ip source_ip ip_address meta.remote_ip],
  Fields::HTTP_HOST => %w[hostname request_host gitlab_host kubernetes.host],
  Fields::GL_PROJECT_ID => %w[extra.project_id meta.project_id meta.search.project_id job_project_id target_project_id],
  Fields::GL_PIPELINE_ID => %w[extra.pipeline_id meta.pipeline_id root_pipeline_id],
  Fields::TIMESTAMP => %w[start_time],
  Fields::SEVERITY => %w[level],
  Fields::LOG_MESSAGE => %w[msg custom_message extra.message fields.message graphql.message reason color_message exception.gitaly],
  Fields::CLASS_NAME => %w[class author_class exception.class extra.class extra.class_name],
  Fields::SERVICE_NAME => %w[service grpc.service_name auth_service type component subcomponent],
  Fields::GL_ORGANIZATION_ID => %w[organization_id],
  Fields::GL_PROJECT_PATH => %w[project_path full_path root_pipeline_project_path requested_project_path auth_project_path extra.gl_project_path],
}.freeze

Class Method Summary collapse

Class Method Details

.allHash{String => String}

Get all deprecated fields as a lookup hash

Returns:

  • (Hash{String => String})

    Hash mapping deprecated field names to standard field names



162
163
164
165
166
# File 'lib/labkit/fields.rb', line 162

def all
  @all ||= MAPPINGS.each_with_object({}) do |(key, values), result|
    values.each { |v| result[v] = key }
  end
end

.deprecated?(field_name) ⇒ Boolean

Check if a field is deprecated

Parameters:

  • field_name (String, Symbol)

    The field name to check

Returns:

  • (Boolean)

    true if the field is deprecated



172
173
174
# File 'lib/labkit/fields.rb', line 172

def deprecated?(field_name)
  all.key?(field_name.to_s)
end

.standard_field_for(deprecated_field) ⇒ String?

Get the standard field for a deprecated field

Parameters:

  • deprecated_field (String, Symbol)

    The deprecated field name

Returns:

  • (String, nil)

    The standard field name, or nil if not found



180
181
182
# File 'lib/labkit/fields.rb', line 180

def standard_field_for(deprecated_field)
  all[deprecated_field.to_s]
end