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 62
/
base.go
190 lines (166 loc) · 8.12 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package adminservice
import (
"context"
"fmt"
"runtime/debug"
eventWriter "github.com/flyteorg/flyteadmin/pkg/async/events/implementations"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/service"
"github.com/flyteorg/flyteadmin/pkg/manager/impl/resources"
"github.com/flyteorg/flyteadmin/pkg/async/notifications"
"github.com/flyteorg/flyteadmin/pkg/async/schedule"
"github.com/flyteorg/flyteadmin/pkg/data"
executionCluster "github.com/flyteorg/flyteadmin/pkg/executioncluster/impl"
manager "github.com/flyteorg/flyteadmin/pkg/manager/impl"
"github.com/flyteorg/flyteadmin/pkg/manager/interfaces"
"github.com/flyteorg/flyteadmin/pkg/repositories"
repositoryConfig "github.com/flyteorg/flyteadmin/pkg/repositories/config"
"github.com/flyteorg/flyteadmin/pkg/runtime"
workflowengine "github.com/flyteorg/flyteadmin/pkg/workflowengine/impl"
"github.com/flyteorg/flytestdlib/logger"
"github.com/flyteorg/flytestdlib/profutils"
"github.com/flyteorg/flytestdlib/promutils"
"github.com/flyteorg/flytestdlib/storage"
"github.com/golang/protobuf/proto"
)
type AdminService struct {
service.UnimplementedAdminServiceServer
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
VersionManager interfaces.VersionInterface
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 with Stack: %v", request, err, string(debug.Stack()))
}
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{
BaseConfig: repositoryConfig.BaseConfig{
IsDebug: dbConfigValues.Debug,
},
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(), applicationConfiguration.EventVersion)
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)
eventPublisher := notifications.NewEventsPublisher(*configuration.ApplicationConfiguration().GetExternalEventsConfig(), adminScope)
go func() {
logger.Info(context.Background(), "Started processing notifications.")
processor.StartProcessing()
}()
// Configure workflow scheduler async processes.
schedulerConfig := configuration.ApplicationConfiguration().GetSchedulerConfig()
workflowScheduler := schedule.NewWorkflowScheduler(db, schedule.WorkflowSchedulerConfig{
Retries: defaultRetries,
SchedulerConfig: *schedulerConfig,
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,
SigningPrincipal: remoteDataConfig.SignedURL.SigningPrincipal,
Region: remoteDataConfig.Region,
Retries: defaultRetries,
RemoteDataStoreClient: dataStorageClient,
}).GetRemoteURLInterface()
workflowManager := manager.NewWorkflowManager(
db, configuration, workflowengine.NewCompiler(), dataStorageClient, applicationConfiguration.MetadataStoragePrefix,
adminScope.NewSubScope("workflow_manager"))
namedEntityManager := manager.NewNamedEntityManager(db, configuration, adminScope.NewSubScope("named_entity_manager"))
executionEventWriter := eventWriter.NewWorkflowExecutionEventWriter(db, applicationConfiguration.AsyncEventsBufferSize)
go func() {
executionEventWriter.Run()
}()
executionManager := manager.NewExecutionManager(db, configuration, dataStorageClient, workflowExecutor,
adminScope.NewSubScope("execution_manager"), adminScope.NewSubScope("user_execution_metrics"),
publisher, urlData, workflowManager, namedEntityManager, eventPublisher, executionEventWriter)
versionManager := manager.NewVersionManager()
scheduledWorkflowExecutor := workflowScheduler.GetWorkflowExecutor(executionManager, launchPlanManager)
logger.Info(context.Background(), "Successfully initialized a new scheduled workflow executor")
go func() {
logger.Info(context.Background(), "Starting the scheduled workflow executor")
scheduledWorkflowExecutor.Run()
}()
// 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)
}
}()
nodeExecutionEventWriter := eventWriter.NewNodeExecutionEventWriter(db, applicationConfiguration.AsyncEventsBufferSize)
go func() {
nodeExecutionEventWriter.Run()
}()
logger.Info(context.Background(), "Initializing a new AdminService")
return &AdminService{
TaskManager: manager.NewTaskManager(db, configuration, workflowengine.NewCompiler(),
adminScope.NewSubScope("task_manager")),
WorkflowManager: workflowManager,
LaunchPlanManager: launchPlanManager,
ExecutionManager: executionManager,
NamedEntityManager: namedEntityManager,
VersionManager: versionManager,
NodeExecutionManager: manager.NewNodeExecutionManager(db, configuration, applicationConfiguration.MetadataStoragePrefix, dataStorageClient,
adminScope.NewSubScope("node_execution_manager"), urlData, eventPublisher, nodeExecutionEventWriter),
TaskExecutionManager: manager.NewTaskExecutionManager(db, configuration, dataStorageClient,
adminScope.NewSubScope("task_execution_manager"), urlData, eventPublisher),
ProjectManager: manager.NewProjectManager(db, configuration),
ResourceManager: resources.NewResourceManager(db, configuration.ApplicationConfiguration()),
Metrics: InitMetrics(adminScope),
}
}