Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gcp-quotas-checks.rb « review_apps « scripts - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 187277f87eae65df90315996051f6d261bd95ba7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

# We created this because we could not monitor k8s resource count directly in GCP monitoring (see
# https://gitlab.com/gitlab-org/quality/engineering-productivity-infrastructure/-/issues/37)
#
# If this functionality ever becomes available, please replace this script with GCP monitoring!

require 'json'

class QuotaChecker
  def initialize
    @exit_with_error = false
  end

  def check_quotas(quotas, threshold: 0.8)
    quotas.each do |quota|
      print "Checking quota #{quota['metric']}..."
      quota_percent_usage = quota['usage'].to_f / quota['limit']
      if quota_percent_usage > threshold
        puts "❌ #{quota['metric']} is above the #{threshold * 100}% threshold! (current value: #{quota_percent_usage})"
        @exit_with_error = true
      else
        puts "✅"
      end
    end
  end

  def failed?
    @exit_with_error
  end
end

quota_checker = QuotaChecker.new

puts "Checking regional quotas:"
gcloud_command_output = `gcloud compute regions describe us-central1 --format=json`
quotas = JSON.parse(gcloud_command_output)['quotas']
quota_checker.check_quotas(quotas)
puts

puts "Checking project-wide quotas:"
gcloud_command_output = `gcloud compute project-info describe --format=json`
quotas = JSON.parse(gcloud_command_output)['quotas']
quota_checker.check_quotas(quotas)

exit 1 if quota_checker.failed?