-
Notifications
You must be signed in to change notification settings - Fork 132
/
application.go
69 lines (52 loc) · 1.96 KB
/
application.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package lookout
import (
"sync"
"github.com/doug-martin/goqu/v9"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
log "github.com/sirupsen/logrus"
"github.com/armadaproject/armada/internal/common/auth/authorization"
"github.com/armadaproject/armada/internal/common/grpc"
"github.com/armadaproject/armada/internal/common/health"
"github.com/armadaproject/armada/internal/common/util"
"github.com/armadaproject/armada/internal/lookout/configuration"
"github.com/armadaproject/armada/internal/lookout/metrics"
"github.com/armadaproject/armada/internal/lookout/postgres"
"github.com/armadaproject/armada/internal/lookout/repository"
"github.com/armadaproject/armada/internal/lookout/server"
"github.com/armadaproject/armada/pkg/api/lookout"
)
type LogRusLogger struct{}
func (l LogRusLogger) Printf(format string, v ...interface{}) {
log.Debugf(format, v...)
}
func StartUp(config configuration.LookoutConfiguration, healthChecks *health.MultiChecker) (func(), *sync.WaitGroup) {
wg := &sync.WaitGroup{}
wg.Add(1)
grpcServer := grpc.CreateGrpcServer(
config.Grpc.KeepaliveParams,
config.Grpc.KeepaliveEnforcementPolicy,
[]authorization.AuthService{&authorization.AnonymousAuthService{}},
)
db, err := postgres.Open(config.Postgres)
if err != nil {
panic(err)
}
goquDb := goqu.New("postgres", db)
goquDb.Logger(&LogRusLogger{})
jobRepository := repository.NewSQLJobRepository(goquDb, &util.DefaultClock{})
healthChecks.Add(repository.NewSqlHealth(db))
dbMetricsProvider := metrics.NewLookoutSqlDbMetricsProvider(db, config.Postgres)
metrics.ExposeLookoutMetrics(dbMetricsProvider)
lookoutServer := server.NewLookoutServer(jobRepository)
lookout.RegisterLookoutServer(grpcServer, lookoutServer)
grpc_prometheus.Register(grpcServer)
grpc.Listen(config.GrpcPort, grpcServer, wg)
stop := func() {
err = db.Close()
if err != nil {
log.Errorf("failed to close db connection: %v", err)
}
grpcServer.GracefulStop()
}
return stop, wg
}