Class: GitLab::Exporter::Database::CiBuildsCollector
- Defined in:
- lib/gitlab_exporter/database/ci_builds.rb
Overview
A helper class to collect CI builds metrics.
Constant Summary collapse
- SET_RANDOM_PAGE_COST =
rubocop:disable Metrics/ClassLength
"SET LOCAL random_page_cost TO 1".freeze
- BUILDS_QUERY_EE =
"SELECT\n projects.namespace_id,\n p_ci_builds.status,\n projects.shared_runners_enabled,\n (COALESCE(namespaces.shared_runners_minutes_limit, application_settings.shared_runners_minutes, 0) = 0 OR\n COALESCE(namespace_statistics.shared_runners_seconds, 0) < COALESCE(namespaces.shared_runners_minutes_limit, application_settings.shared_runners_minutes, 0) * 60) as has_minutes,\n COUNT(*) AS count\nFROM p_ci_builds\nJOIN projects\n ON projects.id = p_ci_builds.project_id\nJOIN namespaces\n ON namespaces.id = projects.namespace_id\nLEFT JOIN namespace_statistics\n ON namespace_statistics.namespace_id = namespaces.id\nJOIN application_settings ON (TRUE)\nWHERE p_ci_builds.type = 'Ci::Build'\n AND p_ci_builds.status = '%s'\n -- The created_at filter has been introduced for performance reasons only\n AND p_ci_builds.created_at > NOW() - INTERVAL '7 days'\n AND projects.pending_delete = 'f'\nGROUP BY\n projects.namespace_id,\n p_ci_builds.status,\n projects.shared_runners_enabled,\n namespaces.shared_runners_minutes_limit,\n namespace_statistics.shared_runners_seconds,\n application_settings.shared_runners_minutes\n".freeze
- BUILDS_QUERY_CE =
"SELECT\n projects.namespace_id,\n p_ci_builds.status,\n projects.shared_runners_enabled,\n COUNT(*) AS count\nFROM p_ci_builds\nJOIN projects\n ON projects.id = p_ci_builds.project_id\nWHERE p_ci_builds.type = 'Ci::Build'\n AND p_ci_builds.status = '%s'\n -- The created_at filter has been introduced for performance reasons only\n AND p_ci_builds.created_at > NOW() - INTERVAL '7 days'\n AND projects.pending_delete = 'f'\nGROUP BY\n projects.namespace_id,\n p_ci_builds.status,\n projects.shared_runners_enabled\n".freeze
- STALE_BUILDS_QUERY =
"SELECT\n COUNT(*) AS count\nFROM p_ci_builds\nJOIN projects\n ON projects.id = p_ci_builds.project_id\nWHERE p_ci_builds.type = 'Ci::Build'\n AND p_ci_builds.status = 'running'\n AND p_ci_builds.updated_at < NOW() - INTERVAL '1 hour'\n AND projects.pending_delete = 'f'\n".freeze
- PER_RUNNER_QUERY_EE =
"SELECT\n p_ci_builds.runner_id,\n ci_runners.runner_type,\n projects.namespace_id,\n projects.mirror,\n projects.mirror_trigger_builds,\n p_ci_pipelines.pipeline_schedule_id,\n p_ci_pipelines.trigger_id,\n (COALESCE(namespaces.shared_runners_minutes_limit, application_settings.shared_runners_minutes, 0) = 0 OR\n COALESCE(namespace_statistics.shared_runners_seconds, 0) < COALESCE(namespaces.shared_runners_minutes_limit, application_settings.shared_runners_minutes, 0) * 60) as has_minutes,\n COUNT(*) AS count\nFROM p_ci_builds\nJOIN ci_runners\n ON ci_runners.id = p_ci_builds.runner_id\nJOIN projects\n ON projects.id = p_ci_builds.project_id\nJOIN p_ci_pipelines\n ON p_ci_pipelines.id = p_ci_builds.commit_id\nJOIN namespaces\n ON namespaces.id = projects.namespace_id\nLEFT JOIN namespace_statistics\n ON namespace_statistics.namespace_id = namespaces.id\nJOIN application_settings ON (TRUE)\nWHERE p_ci_builds.type = 'Ci::Build'\n AND p_ci_builds.status = 'running'\n -- The created_at filter has been introduced for performance reasons only\n AND p_ci_builds.created_at > NOW() - INTERVAL '7 days'\n AND projects.pending_delete = 'f'\nGROUP BY\n p_ci_builds.runner_id,\n ci_runners.runner_type,\n projects.namespace_id,\n projects.mirror,\n projects.mirror_trigger_builds,\n p_ci_pipelines.pipeline_schedule_id,\n p_ci_pipelines.trigger_id,\n namespaces.shared_runners_minutes_limit,\n namespace_statistics.shared_runners_seconds,\n application_settings.shared_runners_minutes\n".freeze
- PER_RUNNER_QUERY_CE =
"SELECT\n p_ci_builds.runner_id,\n ci_runners.runner_type,\n projects.namespace_id,\n p_ci_pipelines.pipeline_schedule_id,\n p_ci_pipelines.trigger_id,\n COUNT(*) AS count\nFROM p_ci_builds\nJOIN ci_runners\n ON ci_runners.id = p_ci_builds.runner_id\nJOIN projects\n ON projects.id = p_ci_builds.project_id\nJOIN p_ci_pipelines\n ON p_ci_pipelines.id = p_ci_builds.commit_id\nWHERE p_ci_builds.type = 'Ci::Build'\n AND p_ci_builds.status = 'running'\n -- The created_at filter has been introduced for performance reasons only\n AND p_ci_builds.created_at > NOW() - INTERVAL '7 days'\n AND projects.pending_delete = 'f'\nGROUP BY\n p_ci_builds.runner_id,\n ci_runners.runner_type,\n projects.namespace_id,\n p_ci_pipelines.pipeline_schedule_id,\n p_ci_pipelines.trigger_id\n".freeze
- EE_CHECK_QUERY =
"SELECT COUNT(*) FROM licenses\n".freeze
- UNARCHIVED_TRACES_QUERY =
"SELECT\n COUNT(*) as count\nFROM p_ci_builds\nJOIN ci_build_trace_chunks\n ON ci_build_trace_chunks.build_id = p_ci_builds.id\nLEFT JOIN p_ci_job_artifacts\n ON p_ci_job_artifacts.job_id = p_ci_builds.id\n AND p_ci_job_artifacts.file_type = 3\nWHERE p_ci_builds.type = 'Ci::Build'\n AND p_ci_builds.status IN ('success', 'failed', 'canceled')\n AND p_ci_builds.finished_at < '%s'\n AND p_ci_job_artifacts.job_id IS NULL\n".freeze
- STATUS_CREATED =
"created".freeze
- STATUS_PENDING =
"pending".freeze
- DEFAULT_UNARCHIVED_TRACES_OFFSET_MINUTES =
1440
Constants inherited from Base
Base::POOL_SIZE, Base::POOL_TIMEOUT
Instance Method Summary collapse
-
#initialize(**opts) ⇒ CiBuildsCollector
constructor
A new instance of CiBuildsCollector.
- #run ⇒ Object
Methods inherited from Base
configure_type_map_for_results, connection_pool, #connection_pool, #with_connection_pool
Constructor Details
#initialize(**opts) ⇒ CiBuildsCollector
Returns a new instance of CiBuildsCollector.
171 172 173 174 175 176 |
# File 'lib/gitlab_exporter/database/ci_builds.rb', line 171 def initialize(**opts) super @created_builds_counting_disabled = opts[:created_builds_counting_disabled] @unarchived_traces_offset_minutes = opts[:unarchived_traces_offset_minutes] end |
Instance Method Details
#run ⇒ Object
178 179 180 181 182 183 184 185 186 |
# File 'lib/gitlab_exporter/database/ci_builds.rb', line 178 def run results = {} results[:created_builds] = builds(STATUS_CREATED) unless @created_builds_counting_disabled results[:pending_builds] = builds(STATUS_PENDING) results[:stale_builds] = stale_builds results[:per_runner] = per_runner_builds results[:unarchived_traces] = unarchived_traces results end |