Class: Gitlab::Database::QueryAnalyzers::GitlabSchemasMetrics

Inherits:
Base
  • Object
show all
Defined in:
lib/gitlab/database/query_analyzers/gitlab_schemas_metrics.rb

Overview

The purpose of this analyzer is to observe via prometheus metrics all unique schemas observed on a given connection

This effectively allows to do sample 1% or 0.01% of queries hitting system and observe if on a given connection we observe queries that are misaligned (‘ci_replica` sees queries doing accessing only `gitlab_main`)

Constant Summary

Constants inherited from Base

Base::QueryAnalyzerError

Class Method Summary collapse

Methods inherited from Base

analyzer_key, begin!, context, context_key, end!, requires_tracking?, suppress=, suppress_key, suppressed?, with_suppressed

Class Method Details

.analyze(parsed) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gitlab/database/query_analyzers/gitlab_schemas_metrics.rb', line 20

def analyze(parsed)
  db_config_name = ::Gitlab::Database.db_config_name(parsed.connection)
  return unless db_config_name

  gitlab_schemas = ::Gitlab::Database::GitlabSchema.table_schemas!(parsed.pg.tables)
  return if gitlab_schemas.empty?

  # to reduce amount of labels sort schemas used
  gitlab_schemas = gitlab_schemas.to_a.sort.join(",")

  schemas_metrics.increment({
    gitlab_schemas: gitlab_schemas,
    db_config_name: db_config_name
  })
end

.enabled?Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/gitlab/database/query_analyzers/gitlab_schemas_metrics.rb', line 15

def enabled?
  ::Feature::FlipperFeature.table_exists? &&
    Feature.enabled?(:query_analyzer_gitlab_schema_metrics, type: :ops)
end

.schemas_metricsObject



36
37
38
39
40
41
# File 'lib/gitlab/database/query_analyzers/gitlab_schemas_metrics.rb', line 36

def schemas_metrics
  @schemas_metrics ||= ::Gitlab::Metrics.counter(
    :gitlab_database_decomposition_gitlab_schemas_used,
    'The number of observed schemas dependent on connection'
  )
end