-
Notifications
You must be signed in to change notification settings - Fork 132
/
binoculars.go
51 lines (41 loc) · 1.39 KB
/
binoculars.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
package server
import (
"context"
"strconv"
"github.com/gogo/protobuf/types"
"github.com/armadaproject/armada/internal/binoculars/service"
"github.com/armadaproject/armada/internal/common"
"github.com/armadaproject/armada/internal/common/auth/authorization"
"github.com/armadaproject/armada/pkg/api/binoculars"
)
type BinocularsServer struct {
logService service.LogService
cordonService service.CordonService
}
func NewBinocularsServer(logService service.LogService, cordonService service.CordonService) *BinocularsServer {
return &BinocularsServer{
logService: logService,
cordonService: cordonService,
}
}
func (b *BinocularsServer) Logs(ctx context.Context, request *binoculars.LogRequest) (*binoculars.LogResponse, error) {
principal := authorization.GetPrincipal(ctx)
logLines, err := b.logService.GetLogs(ctx, &service.LogParams{
Principal: principal,
Namespace: request.PodNamespace,
PodName: common.PodNamePrefix + request.JobId + "-" + strconv.Itoa(int(request.PodNumber)),
SinceTime: request.SinceTime,
LogOptions: request.LogOptions,
})
if err != nil {
return nil, err
}
return &binoculars.LogResponse{Log: logLines}, nil
}
func (b *BinocularsServer) Cordon(ctx context.Context, request *binoculars.CordonRequest) (*types.Empty, error) {
err := b.cordonService.CordonNode(ctx, request)
if err != nil {
return nil, err
}
return &types.Empty{}, nil
}