summaryrefslogtreecommitdiff
path: root/lib/api/circuit_breakers.rb
blob: 6eddc5e5b61cfeafbdb7da24f620ada85c520094 (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
47
48
49
50
51
52
# frozen_string_literal: true

module API
  class CircuitBreakers < Grape::API
    before { authenticated_as_admin! }

    resource :circuit_breakers do
      params do
        requires :type,
                 type: String,
                 desc: "The type of circuitbreaker",
                 values: ['repository_storage']
      end
      resource ':type' do
        namespace '', requirements: { type: 'repository_storage' } do
          helpers do
            def failing_storage_health
              @failing_storage_health ||= Gitlab::Git::Storage::Health.for_failing_storages
            end

            def storage_health
              @storage_health ||= Gitlab::Git::Storage::Health.for_all_storages
            end
          end

          desc 'Get all git storages' do
            detail 'This feature was introduced in GitLab 9.5'
            success Entities::RepositoryStorageHealth
          end
          get do
            present storage_health, with: Entities::RepositoryStorageHealth
          end

          desc 'Get all failing git storages' do
            detail 'This feature was introduced in GitLab 9.5'
            success Entities::RepositoryStorageHealth
          end
          get 'failing' do
            present failing_storage_health, with: Entities::RepositoryStorageHealth
          end

          desc 'Reset all storage failures and open circuitbreaker' do
            detail 'This feature was introduced in GitLab 9.5'
          end
          delete do
            Gitlab::Git::Storage::FailureInfo.reset_all!
          end
        end
      end
    end
  end
end