This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
base.go
169 lines (150 loc) · 6.96 KB
/
base.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package adminservice
import (
"context"
"fmt"
"runtime/debug"
"github.com/lyft/flyteadmin/pkg/manager/impl/resources"
"github.com/golang/protobuf/proto"
"github.com/lyft/flyteadmin/pkg/async/notifications"
"github.com/lyft/flyteadmin/pkg/async/schedule"
"github.com/lyft/flyteadmin/pkg/data"
executionCluster "github.com/lyft/flyteadmin/pkg/executioncluster/impl"
manager "github.com/lyft/flyteadmin/pkg/manager/impl"
"github.com/lyft/flyteadmin/pkg/manager/interfaces"
"github.com/lyft/flyteadmin/pkg/repositories"
repositoryConfig "github.com/lyft/flyteadmin/pkg/repositories/config"
"github.com/lyft/flyteadmin/pkg/runtime"
workflowengine "github.com/lyft/flyteadmin/pkg/workflowengine/impl"
"github.com/lyft/flytestdlib/logger"
"github.com/lyft/flytestdlib/profutils"
"github.com/lyft/flytestdlib/promutils"
"github.com/lyft/flytestdlib/storage"
)
type AdminService struct {
TaskManager interfaces.TaskInterface
WorkflowManager interfaces.WorkflowInterface
LaunchPlanManager interfaces.LaunchPlanInterface
ExecutionManager interfaces.ExecutionInterface
NodeExecutionManager interfaces.NodeExecutionInterface
TaskExecutionManager interfaces.TaskExecutionInterface
ProjectManager interfaces.ProjectInterface
ResourceManager interfaces.ResourceInterface
NamedEntityManager interfaces.NamedEntityInterface
Metrics AdminMetrics
}
// Intercepts all admin requests to handle panics during execution.
func (m *AdminService) interceptPanic(ctx context.Context, request proto.Message) {
err := recover()
if err == nil {
return
}
m.Metrics.PanicCounter.Inc()
logger.Fatalf(ctx, "panic-ed for request: [%+v] with err: %v", request, err)
}
const defaultRetries = 3
func NewAdminServer(kubeConfig, master string) *AdminService {
configuration := runtime.NewConfigurationProvider()
applicationConfiguration := configuration.ApplicationConfiguration().GetTopLevelConfig()
adminScope := promutils.NewScope(applicationConfiguration.MetricsScope).NewSubScope("admin")
defer func() {
if err := recover(); err != nil {
adminScope.MustNewCounter("initialization_panic",
"panics encountered initializing the admin service").Inc()
logger.Fatalf(context.Background(), fmt.Sprintf("caught panic: %v [%+v]", err, string(debug.Stack())))
}
}()
dbConfigValues := configuration.ApplicationConfiguration().GetDbConfig()
dbConfig := repositoryConfig.DbConfig{
Host: dbConfigValues.Host,
Port: dbConfigValues.Port,
DbName: dbConfigValues.DbName,
User: dbConfigValues.User,
Password: dbConfigValues.Password,
ExtraOptions: dbConfigValues.ExtraOptions,
}
db := repositories.GetRepository(
repositories.POSTGRES, dbConfig, adminScope.NewSubScope("database"))
storeConfig := storage.GetConfig()
execCluster := executionCluster.GetExecutionCluster(
adminScope.NewSubScope("executor").NewSubScope("cluster"),
kubeConfig,
master,
configuration,
db)
workflowExecutor := workflowengine.NewFlytePropeller(
applicationConfiguration.RoleNameKey,
execCluster,
adminScope.NewSubScope("executor").NewSubScope("flytepropeller"),
configuration.NamespaceMappingConfiguration())
logger.Info(context.Background(), "Successfully created a workflow executor engine")
dataStorageClient, err := storage.NewDataStore(storeConfig, adminScope.NewSubScope("storage"))
if err != nil {
logger.Error(context.Background(), "Failed to initialize storage config")
panic(err)
}
publisher := notifications.NewNotificationsPublisher(*configuration.ApplicationConfiguration().GetNotificationsConfig(), adminScope)
processor := notifications.NewNotificationsProcessor(*configuration.ApplicationConfiguration().GetNotificationsConfig(), adminScope)
go func() {
err = processor.StartProcessing()
if err != nil {
logger.Errorf(context.Background(), "error with starting processor err: [%v] ", err)
} else {
logger.Info(context.Background(), "Successfully started processing notifications.")
}
}()
// Configure workflow scheduler async processes.
schedulerConfig := configuration.ApplicationConfiguration().GetSchedulerConfig()
workflowScheduler := schedule.NewWorkflowScheduler(schedule.WorkflowSchedulerConfig{
Retries: defaultRetries,
EventSchedulerConfig: schedulerConfig.EventSchedulerConfig,
WorkflowExecutorConfig: schedulerConfig.WorkflowExecutorConfig,
Scope: adminScope,
})
eventScheduler := workflowScheduler.GetEventScheduler()
launchPlanManager := manager.NewLaunchPlanManager(
db, configuration, eventScheduler, adminScope.NewSubScope("launch_plan_manager"))
// Configure admin-specific remote data handler (separate from storage)
remoteDataConfig := configuration.ApplicationConfiguration().GetRemoteDataConfig()
urlData := data.GetRemoteDataHandler(data.RemoteDataHandlerConfig{
CloudProvider: remoteDataConfig.Scheme,
SignedURLDurationMinutes: remoteDataConfig.SignedURL.DurationMinutes,
Region: remoteDataConfig.Region,
Retries: defaultRetries,
RemoteDataStoreClient: dataStorageClient,
}).GetRemoteURLInterface()
executionManager := manager.NewExecutionManager(
db, configuration, dataStorageClient, workflowExecutor, adminScope.NewSubScope("execution_manager"),
adminScope.NewSubScope("user_execution_metrics"), publisher, urlData)
scheduledWorkflowExecutor := workflowScheduler.GetWorkflowExecutor(executionManager, launchPlanManager)
logger.Info(context.Background(), "Successfully initialized a new scheduled workflow executor")
go func() {
scheduledWorkflowExecutor.Run()
logger.Info(context.Background(), "Successfully started running the scheduled workflow executor")
}()
// Serve profiling endpoints.
go func() {
err := profutils.StartProfilingServerWithDefaultHandlers(
context.Background(), applicationConfiguration.ProfilerPort, nil)
if err != nil {
logger.Panicf(context.Background(), "Failed to Start profiling and Metrics server. Error, %v", err)
}
}()
logger.Info(context.Background(), "Initializing a new AdminService")
return &AdminService{
TaskManager: manager.NewTaskManager(db, configuration, workflowengine.NewCompiler(),
adminScope.NewSubScope("task_manager")),
WorkflowManager: manager.NewWorkflowManager(
db, configuration, workflowengine.NewCompiler(), dataStorageClient, applicationConfiguration.MetadataStoragePrefix,
adminScope.NewSubScope("workflow_manager")),
LaunchPlanManager: launchPlanManager,
ExecutionManager: executionManager,
NamedEntityManager: manager.NewNamedEntityManager(db, configuration, adminScope.NewSubScope("named_entity_manager")),
NodeExecutionManager: manager.NewNodeExecutionManager(
db, adminScope.NewSubScope("node_execution_manager"), urlData),
TaskExecutionManager: manager.NewTaskExecutionManager(
db, adminScope.NewSubScope("task_execution_manager"), urlData),
ProjectManager: manager.NewProjectManager(db, configuration),
ResourceManager: resources.NewResourceManager(db),
Metrics: InitMetrics(adminScope),
}
}