Commit a7b7f5ae authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'cat-add-geo-proxied-requests-service-ping' into 'master'

Add geo proxied requests metrics to service ping

See merge request gitlab-org/gitlab!76389
parents a451f456 b500b2cf
......@@ -7,6 +7,8 @@ class Geo::SecondaryUsageData < Geo::TrackingBase
GIT_FETCH_EVENT_COUNT_WEEKLY_QUERY = 'round(sum(increase(grpc_server_handled_total{grpc_method=~"SSHUploadPack|PostUploadPack"}[7d])))'
GIT_PUSH_EVENT_COUNT_WEEKLY_QUERY = 'round(sum(increase(grpc_server_handled_total{grpc_method=~"SSHReceivePack|PostReceivePack"}[7d])))'
PROXY_REMOTE_REQUESTS_EVENT_COUNT_WEEKLY_QUERY = 'round(sum(increase(gitlab_workhorse_http_geo_proxied_requests_total[7d])))'
PROXY_LOCAL_REQUESTS_EVENT_COUNT_WEEKLY_QUERY = 'round(sum(increase(gitlab_workhorse_http_requests_total{route!="^/-/(readiness|liveness)$"}[7d])))'
# Eventually, we'll find a way to auto-load this
# from the metric yaml files that include something
......@@ -15,6 +17,8 @@ class Geo::SecondaryUsageData < Geo::TrackingBase
PAYLOAD_COUNT_FIELDS = %w(
git_fetch_event_count_weekly
git_push_event_count_weekly
proxy_remote_requests_event_count_weekly
proxy_local_requests_event_count_weekly
).freeze
store_accessor :payload, *PAYLOAD_COUNT_FIELDS
......@@ -40,6 +44,8 @@ class Geo::SecondaryUsageData < Geo::TrackingBase
with_prometheus_client(fallback: nil, verify: false) do |client|
self.git_fetch_event_count_weekly = client.query(GIT_FETCH_EVENT_COUNT_WEEKLY_QUERY).dig(0, "value", 1)&.to_i
self.git_push_event_count_weekly = client.query(GIT_PUSH_EVENT_COUNT_WEEKLY_QUERY).dig(0, "value", 1)&.to_i
self.proxy_remote_requests_event_count_weekly = client.query(PROXY_REMOTE_REQUESTS_EVENT_COUNT_WEEKLY_QUERY).dig(0, "value", 1)&.to_i
self.proxy_local_requests_event_count_weekly = client.query(PROXY_LOCAL_REQUESTS_EVENT_COUNT_WEEKLY_QUERY).dig(0, "value", 1)&.to_i
end
end
end
......@@ -93,10 +93,12 @@
"package_files_verification_failed_count": { "type": "number" },
"pages_deployments_checksum_failed_count": { "type": "number" },
"pipeline_artifacts_checksum_total_count": { "type": "number" },
"proxy_local_requests_event_count_weekly": { "type": "number" },
"terraform_state_versions_registry_count": { "type": "number" },
"terraform_state_versions_verified_count": { "type": "number" },
"merge_request_diffs_checksum_total_count": { "type": "number" },
"pipeline_artifacts_checksum_failed_count": { "type": "number" },
"proxy_remote_requests_event_count_weekly": { "type": "number" },
"repositories_retrying_verification_count": { "type": "number" },
"group_wiki_repositories_checksummed_count": { "type": "number" },
"merge_request_diffs_checksum_failed_count": { "type": "number" },
......
......@@ -166,6 +166,8 @@
"uploads_verified_in_percentage",
"git_fetch_event_count_weekly",
"git_push_event_count_weekly",
"proxy_remote_requests_event_count_weekly",
"proxy_local_requests_event_count_weekly",
"last_event_id",
"last_event_timestamp",
"cursor_last_event_id",
......@@ -350,6 +352,8 @@
"replication_slots_max_retained_wal_bytes": { "type": ["integer", "null"] },
"git_fetch_event_count_weekly": { "type": ["integer", "null"] },
"git_push_event_count_weekly": { "type": ["integer", "null"] },
"proxy_remote_requests_event_count_weekly": { "type": [ "integer", "null"] },
"proxy_local_requests_event_count_weekly": { "type": [ "integer", "null"] },
"last_event_id": { "type": ["integer", "null"] },
"last_event_timestamp": { "type": ["integer", "null"] },
"cursor_last_event_id": { "type": ["integer", "null"] },
......
......@@ -54,28 +54,28 @@ RSpec.describe Geo::SecondaryUsageData, :geo, type: :model do
allow(prometheus_client).to receive(:query).and_return([])
end
context 'metric git_fetch_event_count_weekly' do
shared_examples 'update specific metric' do |metric, query|
it 'gets metrics from prometheus' do
expected_result = 48
allow(prometheus_client).to receive(:query).with(Geo::SecondaryUsageData::GIT_FETCH_EVENT_COUNT_WEEKLY_QUERY).and_return([{ "value" => [1614029769.82, expected_result.to_s] }])
allow(prometheus_client).to receive(:query).with(query).and_return([{ "value" => [1614029769.82, expected_result.to_s] }])
expect do
described_class.update_metrics!
end.to change { described_class.count }.by(1)
expect(described_class.last).to be_valid
expect(described_class.last.git_fetch_event_count_weekly).to eq(expected_result)
expect(described_class.last.payload[metric]).to eq(expected_result)
end
it 'returns nil if metric is unavailable' do
allow(prometheus_client).to receive(:query).with(Geo::SecondaryUsageData::GIT_FETCH_EVENT_COUNT_WEEKLY_QUERY).and_return([])
allow(prometheus_client).to receive(:query).with(query).and_return([])
expect do
described_class.update_metrics!
end.to change { described_class.count }.by(1)
expect(described_class.last).to be_valid
expect(described_class.last.git_fetch_event_count_weekly).to be_nil
expect(described_class.last.payload[metric]).to be_nil
end
it 'returns nil if it cannot reach prometheus' do
......@@ -88,46 +88,24 @@ RSpec.describe Geo::SecondaryUsageData, :geo, type: :model do
end.to change { described_class.count }.by(1)
expect(described_class.last).to be_valid
expect(described_class.last.git_fetch_event_count_weekly).to be_nil
expect(described_class.last.payload[metric]).to be_nil
end
end
context 'metric git_push_event_count_weekly' do
it 'gets metrics from prometheus' do
expected_result = 48
allow(prometheus_client).to receive(:query).with(Geo::SecondaryUsageData::GIT_PUSH_EVENT_COUNT_WEEKLY_QUERY).and_return([{ "value" => [1614029769.82, expected_result.to_s] }])
expect do
described_class.update_metrics!
end.to change { described_class.count }.by(1)
expect(described_class.last).to be_valid
expect(described_class.last.git_push_event_count_weekly).to eq(expected_result)
end
it 'returns nil if metric is unavailable' do
allow(prometheus_client).to receive(:query).with(Geo::SecondaryUsageData::GIT_PUSH_EVENT_COUNT_WEEKLY_QUERY).and_return([])
expect do
described_class.update_metrics!
end.to change { described_class.count }.by(1)
expect(described_class.last).to be_valid
expect(described_class.last.git_push_event_count_weekly).to be_nil
end
context 'metric git_fetch_event_count_weekly' do
it_behaves_like 'update specific metric', 'git_fetch_event_count_weekly', Geo::SecondaryUsageData::GIT_FETCH_EVENT_COUNT_WEEKLY_QUERY
end
it 'returns nil if it cannot reach prometheus' do
expect_next_instance_of(described_class) do |instance|
expect(instance).to receive(:with_prometheus_client).and_return(nil)
end
context 'metric git_push_event_count_weekly' do
it_behaves_like 'update specific metric', 'git_push_event_count_weekly', Geo::SecondaryUsageData::GIT_PUSH_EVENT_COUNT_WEEKLY_QUERY
end
expect do
described_class.update_metrics!
end.to change { described_class.count }.by(1)
context 'metric proxy_remote_requests_event_count_weekly' do
it_behaves_like 'update specific metric', 'proxy_remote_requests_event_count_weekly', Geo::SecondaryUsageData::PROXY_REMOTE_REQUESTS_EVENT_COUNT_WEEKLY_QUERY
end
expect(described_class.last).to be_valid
expect(described_class.last.git_push_event_count_weekly).to be_nil
end
context 'metric proxy_local_requests_event_count_weekly' do
it_behaves_like 'update specific metric', 'proxy_local_requests_event_count_weekly', Geo::SecondaryUsageData::PROXY_LOCAL_REQUESTS_EVENT_COUNT_WEEKLY_QUERY
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