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

disk_stats.go « server « service « praefect « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 700bdfb2317b59552b0d2aabc74b0b0e7b516fbb (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
package server

import (
	"context"
	"fmt"

	"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)

// DiskStatistics sends DiskStatisticsRequest to all of a praefect server's internal gitaly nodes and aggregates the
// results into a response
func (s *Server) DiskStatistics(ctx context.Context, _ *gitalypb.DiskStatisticsRequest) (*gitalypb.DiskStatisticsResponse, error) {
	var storageStatuses [][]*gitalypb.DiskStatisticsResponse_StorageStatus

	for _, virtualStorage := range s.conf.VirtualStorages {
		shard, err := s.nodeMgr.GetShard(virtualStorage.Name)
		if err != nil {
			return nil, err
		}

		primary, err := shard.GetPrimary()
		if err != nil {
			return nil, err
		}
		secondaries, err := shard.GetSecondaries()
		if err != nil {
			return nil, err
		}

		for _, node := range append(secondaries, primary) {
			client := gitalypb.NewServerServiceClient(node.GetConnection())
			resp, err := client.DiskStatistics(ctx, &gitalypb.DiskStatisticsRequest{})
			if err != nil {
				return nil, fmt.Errorf("error when requesting disk statistics from internal storage %v", node.GetStorage())
			}

			storageStatuses = append(storageStatuses, resp.GetStorageStatuses())
		}
	}

	var response gitalypb.DiskStatisticsResponse

	for _, storageStatus := range storageStatuses {
		response.StorageStatuses = append(response.StorageStatuses, storageStatus...)
	}

	return &response, nil
}