Commit 47d2d9f5 authored by Ahmad Sherif's avatar Ahmad Sherif

Merge branch 'add-remote-mirrors-prober' into 'master'

Add RemoteMirrorsProber

See merge request gitlab-org/gitlab-monitor!90
parents 5a05b469 aa43c78d
Pipeline #110419 passed with stage
in 1 minute and 12 seconds
PATH PATH
remote: . remote: .
specs: specs:
gitlab-monitor (3.5.0) gitlab-monitor (3.6.0)
connection_pool (~> 2.2.1) connection_pool (~> 2.2.1)
pg (~> 1.1) pg (~> 1.1)
quantile (~> 0.2.0) quantile (~> 0.2.0)
......
...@@ -27,6 +27,8 @@ metrics. ...@@ -27,6 +27,8 @@ metrics.
* [Bloat](lib/gitlab_monitor/database/bloat.rb) -- * [Bloat](lib/gitlab_monitor/database/bloat.rb) --
`gitlab_database_bloat_$type_$key` with type `btree` (index bloat) or `table` `gitlab_database_bloat_$type_$key` with type `btree` (index bloat) or `table`
(table bloat) and keys `bloat_ratio bloat_size extra_size real_size` (see below) (table bloat) and keys `bloat_ratio bloat_size extra_size real_size` (see below)
* [Remote mirrors](lib/gitlab_monitor/database/remote_mirrors.rb) --
`project_remote_mirror_last_successful_update_time_seconds`
1. Git 1. Git
* [git pull/push timings](lib/gitlab_monitor/git.rb) -- * [git pull/push timings](lib/gitlab_monitor/git.rb) --
`git_pull_time_milliseconds`, `git_push_time_milliseconds` `git_pull_time_milliseconds`, `git_push_time_milliseconds`
......
...@@ -60,6 +60,13 @@ probes: ...@@ -60,6 +60,13 @@ probes:
- soft_deleted_projects - soft_deleted_projects
- orphaned_projects - orphaned_projects
- uploads - uploads
remote_mirrors:
class_name: Database::RemoteMirrors
<<: *db_common
opts:
<<: *db_common_opts
project_ids:
- 1
process: &process process: &process
methods: methods:
......
...@@ -7,6 +7,7 @@ module GitLab ...@@ -7,6 +7,7 @@ module GitLab
autoload :TuplesProber, "gitlab_monitor/database/tuple_stats" autoload :TuplesProber, "gitlab_monitor/database/tuple_stats"
autoload :RowCountProber, "gitlab_monitor/database/row_count" autoload :RowCountProber, "gitlab_monitor/database/row_count"
autoload :BloatProber, "gitlab_monitor/database/bloat" autoload :BloatProber, "gitlab_monitor/database/bloat"
autoload :RemoteMirrorsProber, "gitlab_monitor/database/remote_mirrors"
end end
end end
end end
module GitLab
module Monitor
module Database
# A helper class to collect remote mirrors metrics.
class RemoteMirrorsCollector < Base
QUERY = <<~SQL.freeze
SELECT project_id, url, EXTRACT(EPOCH FROM last_successful_update_at) AS last_successful_update_at
FROM remote_mirrors WHERE project_id IN (%s) AND enabled = 't'
SQL
def initialize(args)
super(args)
@project_ids = args[:project_ids]
end
def run
return if @project_ids.nil? || @project_ids.empty?
execute(QUERY % [@project_ids.join(",")]) # rubocop:disable Style/FormatString
end
private
def execute(query)
with_connection_pool do |conn|
conn.exec(query)
end
rescue PG::UndefinedTable, PG::UndefinedColumn
nil
end
end
# The prober which is called when gathering metrics
class RemoteMirrorsProber
def initialize(opts, metrics: PrometheusMetrics.new)
@metrics = metrics
@collector = RemoteMirrorsCollector.new(
connection_string: opts[:connection_string],
project_ids: opts[:project_ids]
)
end
def probe_db
results = @collector.run
results.to_a.each do |row|
last_successful_update_at = row.delete("last_successful_update_at").to_i
@metrics.add(
"project_remote_mirror_last_successful_update_time_seconds",
last_successful_update_at,
project_id: row["project_id"],
url: row["url"]
)
end
self
rescue PG::ConnectionBad
self
end
def write_to(target)
target.write(@metrics.to_s)
end
end
end
end
end
module GitLab module GitLab
module Monitor module Monitor
VERSION = "3.5.0".freeze VERSION = "3.6.0".freeze
end end
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment