-
Notifications
You must be signed in to change notification settings - Fork 54
/
process_stats.go
53 lines (46 loc) · 1.3 KB
/
process_stats.go
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
53
package actions
import (
"context"
"code.cloudfoundry.org/korifi/api/authorization"
"code.cloudfoundry.org/korifi/api/repositories"
)
type ProcessStats struct {
processRepo CFProcessRepository
podRepo PodRepository
appRepo CFAppRepository
}
func NewProcessStats(processRepo CFProcessRepository, podRepo PodRepository, appRepo CFAppRepository) *ProcessStats {
return &ProcessStats{
processRepo,
podRepo,
appRepo,
}
}
func (a *ProcessStats) FetchStats(ctx context.Context, authInfo authorization.Info, processGUID string) ([]repositories.PodStatsRecord, error) {
processRecord, err := a.processRepo.GetProcess(ctx, authInfo, processGUID)
if err != nil {
return nil, err
}
appRecord, err := a.appRepo.GetApp(ctx, authInfo, processRecord.AppGUID)
if err != nil {
return nil, err
}
if appRecord.State == repositories.StoppedState {
return []repositories.PodStatsRecord{
{
Type: processRecord.Type,
Index: 0,
State: "DOWN",
},
}, nil
}
message := repositories.ListPodStatsMessage{
Namespace: processRecord.SpaceGUID,
AppGUID: processRecord.AppGUID,
AppRevision: appRecord.Revision,
Instances: processRecord.DesiredInstances,
ProcessGUID: processRecord.GUID,
ProcessType: processRecord.Type,
}
return a.podRepo.ListPodStats(ctx, authInfo, message)
}