From 8ed377af424d895d7c127fd771dde998f9fc610a Mon Sep 17 00:00:00 2001 From: Dan Rammer Date: Wed, 23 Aug 2023 17:42:21 -0500 Subject: [PATCH] refactoring profile handler into entrypoints (#113) * moved profutils profiling server start to entrypoint so it is not included in single binary Signed-off-by: Daniel Rammer * fixed imports Signed-off-by: Daniel Rammer --------- Signed-off-by: Daniel Rammer --- datacatalog/cmd/entrypoints/serve.go | 18 +++++++++++++++--- datacatalog/cmd/entrypoints/serve_dummy.go | 10 ++++++++++ .../pkg/rpc/datacatalogservice/service.go | 18 ------------------ 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/datacatalog/cmd/entrypoints/serve.go b/datacatalog/cmd/entrypoints/serve.go index 2e0449729c..1300dbe980 100644 --- a/datacatalog/cmd/entrypoints/serve.go +++ b/datacatalog/cmd/entrypoints/serve.go @@ -3,12 +3,14 @@ package entrypoints import ( "context" - "github.com/flyteorg/flytestdlib/contextutils" - "github.com/flyteorg/flytestdlib/promutils/labeled" - "github.com/flyteorg/datacatalog/pkg/config" "github.com/flyteorg/datacatalog/pkg/rpc/datacatalogservice" + "github.com/flyteorg/datacatalog/pkg/runtime" + "github.com/flyteorg/flytestdlib/contextutils" "github.com/flyteorg/flytestdlib/logger" + "github.com/flyteorg/flytestdlib/profutils" + "github.com/flyteorg/flytestdlib/promutils/labeled" + "github.com/spf13/cobra" ) @@ -27,6 +29,16 @@ var serveCmd = &cobra.Command{ } }() + // Serve profiling endpoint. + dataCatalogConfig := runtime.NewConfigurationProvider().ApplicationConfiguration().GetDataCatalogConfig() + go func() { + err := profutils.StartProfilingServerWithDefaultHandlers( + context.Background(), dataCatalogConfig.ProfilerPort, nil) + if err != nil { + logger.Panicf(context.Background(), "Failed to Start profiling and Metrics server. Error, %v", err) + } + }() + // Set Keys labeled.SetMetricKeys(contextutils.AppNameKey, contextutils.ProjectKey, contextutils.DomainKey) diff --git a/datacatalog/cmd/entrypoints/serve_dummy.go b/datacatalog/cmd/entrypoints/serve_dummy.go index a58ce0f696..4192540d48 100644 --- a/datacatalog/cmd/entrypoints/serve_dummy.go +++ b/datacatalog/cmd/entrypoints/serve_dummy.go @@ -5,6 +5,7 @@ import ( "github.com/flyteorg/datacatalog/pkg/config" "github.com/flyteorg/datacatalog/pkg/rpc/datacatalogservice" + "github.com/flyteorg/flytestdlib/logger" "github.com/spf13/cobra" ) @@ -14,6 +15,15 @@ var serveDummyCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() cfg := config.GetConfig() + + // serve a http healthcheck endpoint + go func() { + err := datacatalogservice.ServeHTTPHealthCheck(ctx, cfg) + if err != nil { + logger.Errorf(ctx, "Unable to serve http", cfg.GetGrpcHostAddress(), err) + } + }() + return datacatalogservice.Serve(ctx, cfg) }, } diff --git a/datacatalog/pkg/rpc/datacatalogservice/service.go b/datacatalog/pkg/rpc/datacatalogservice/service.go index 0591b7da0b..a7ca391e2e 100644 --- a/datacatalog/pkg/rpc/datacatalogservice/service.go +++ b/datacatalog/pkg/rpc/datacatalogservice/service.go @@ -21,7 +21,6 @@ import ( catalog "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/datacatalog" "github.com/flyteorg/flytestdlib/contextutils" "github.com/flyteorg/flytestdlib/logger" - "github.com/flyteorg/flytestdlib/profutils" "github.com/flyteorg/flytestdlib/promutils" "github.com/flyteorg/flytestdlib/storage" ) @@ -106,15 +105,6 @@ func NewDataCatalogService() *DataCatalogService { repos := repositories.GetRepository(ctx, repositories.POSTGRES, *dbConfigValues, catalogScope) logger.Infof(ctx, "Created DB connection.") - // Serve profiling endpoint. - go func() { - err := profutils.StartProfilingServerWithDefaultHandlers( - context.Background(), dataCatalogConfig.ProfilerPort, nil) - if err != nil { - logger.Panicf(context.Background(), "Failed to Start profiling and Metrics server. Error, %v", err) - } - }() - return &DataCatalogService{ DatasetManager: impl.NewDatasetManager(repos, dataStorageClient, catalogScope.NewSubScope("dataset")), ArtifactManager: impl.NewArtifactManager(repos, dataStorageClient, storagePrefix, catalogScope.NewSubScope("artifact")), @@ -173,14 +163,6 @@ func ServeHTTPHealthCheck(ctx context.Context, cfg *config.Config) error { // Create and start the gRPC server and http healthcheck endpoint func Serve(ctx context.Context, cfg *config.Config) error { - // serve a http healthcheck endpoint - go func() { - err := ServeHTTPHealthCheck(ctx, cfg) - if err != nil { - logger.Errorf(ctx, "Unable to serve http", cfg.GetGrpcHostAddress(), err) - } - }() - grpcServer := newGRPCDummyServer(ctx, cfg) grpcListener, err := net.Listen("tcp", cfg.GetGrpcHostAddress())