-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expose silver surfer as a mvc via grpc code incorporated in this commit
- Loading branch information
1 parent
cb3cad6
commit 663f602
Showing
960 changed files
with
143,798 additions
and
41,413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//go:build wireinject | ||
// +build wireinject | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/devtron-labs/silver-surfer/app" | ||
"github.com/devtron-labs/silver-surfer/app/api" | ||
"github.com/devtron-labs/silver-surfer/app/logger" | ||
"github.com/google/wire" | ||
) | ||
|
||
func InitializeApp() (*app.App, error) { | ||
wire.Build( | ||
app.NewApp, | ||
logger.NewSugaredLogger, | ||
api.NewGrpcHandlerImpl, | ||
) | ||
return &app.App{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package app | ||
|
||
import ( | ||
"fmt" | ||
"github.com/caarlos0/env" | ||
"github.com/devtron-labs/silver-surfer/app/api" | ||
grpc2 "github.com/devtron-labs/silver-surfer/app/grpc" | ||
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/recovery" | ||
"go.uber.org/zap" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/keepalive" | ||
"google.golang.org/grpc/status" | ||
"log" | ||
"net" | ||
"os" | ||
"runtime/debug" | ||
"time" | ||
) | ||
|
||
type App struct { | ||
grpcServer *grpc.Server | ||
StartupConfig *StartupConfig | ||
logger *zap.SugaredLogger | ||
GrpcHandler *api.GrpcHandlerImpl | ||
} | ||
|
||
func NewApp( | ||
logger *zap.SugaredLogger, | ||
GrpcHandler *api.GrpcHandlerImpl, | ||
) *App { | ||
return &App{ | ||
logger: logger, | ||
GrpcHandler: GrpcHandler, | ||
} | ||
} | ||
|
||
type StartupConfig struct { | ||
GrpcPort int `env:"SERVER_GRPC_PORT" envDefault:"8111"` | ||
GrpcMaxRecvMsgSize int `env:"GRPC_MAX_RECEIVE_MSG_SIZE" envDefault:"20"` // In mb | ||
GrpcMaxSendMsgSize int `env:"GRPC_MAX_SEND_MSG_SIZE" envDefault:"4"` // In mb | ||
} | ||
|
||
func (app *App) Start() { | ||
// Parse config | ||
app.StartupConfig = &StartupConfig{} | ||
err := env.Parse(app.StartupConfig) | ||
if err != nil { | ||
app.logger.Errorw("failed to parse configuration") | ||
os.Exit(2) | ||
} | ||
|
||
// Start gRPC server | ||
err = app.initGrpcServer(app.StartupConfig.GrpcPort) | ||
if err != nil { | ||
app.logger.Errorw("error starting grpc server", "err", err) | ||
os.Exit(2) | ||
} | ||
} | ||
|
||
func (app *App) initGrpcServer(port int) error { | ||
app.logger.Infow("gRPC server starting", "port", app.StartupConfig.GrpcPort) | ||
|
||
//listen on the port | ||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) | ||
if err != nil { | ||
log.Fatalf("failed to start grpcServer %v", err) | ||
return err | ||
} | ||
|
||
grpcPanicRecoveryHandler := func(p any) (err error) { | ||
app.logger.Error(PanicLogIdentifier, "recovered from panic", "panic", p, "stack", string(debug.Stack())) | ||
return status.Errorf(codes.Internal, "%s", p) | ||
} | ||
recoveryOption := recovery.WithRecoveryHandler(grpcPanicRecoveryHandler) | ||
opts := []grpc.ServerOption{ | ||
grpc.MaxRecvMsgSize(app.StartupConfig.GrpcMaxRecvMsgSize * 1024 * 1024), // GRPC Request size | ||
grpc.MaxSendMsgSize(app.StartupConfig.GrpcMaxSendMsgSize * 1024 * 1024), // GRPC Response size | ||
grpc.KeepaliveParams(keepalive.ServerParameters{ | ||
MaxConnectionAge: 10 * time.Second, | ||
}), | ||
grpc.ChainStreamInterceptor( | ||
recovery.StreamServerInterceptor(recoveryOption)), // panic interceptor, should be at last | ||
grpc.ChainUnaryInterceptor( | ||
recovery.UnaryServerInterceptor(recoveryOption)), // panic interceptor, should be at last | ||
} | ||
// create a new gRPC grpcServer | ||
app.grpcServer = grpc.NewServer(opts...) | ||
|
||
// register Silver Surfer service | ||
grpc2.RegisterApplicationServiceServer(app.grpcServer, app.GrpcHandler) | ||
|
||
// start listening on address | ||
if err = app.grpcServer.Serve(lis); err != nil { | ||
log.Fatalf("failed to start: %v", err) | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (app *App) Stop() { | ||
|
||
app.logger.Infow("silver-surfer shutdown initiating") | ||
|
||
// Gracefully stop the gRPC server | ||
app.logger.Info("Stopping gRPC server...") | ||
app.grpcServer.GracefulStop() | ||
|
||
app.logger.Infow("housekeeping done. exiting now") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package app | ||
|
||
const ( | ||
PanicLogIdentifier = "DEVTRON_PANIC_RECOVER" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"github.com/devtron-labs/silver-surfer/app/grpc" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type GrpcHandlerImpl struct { | ||
grpc.UnimplementedApplicationServiceServer | ||
logger *zap.SugaredLogger | ||
} | ||
|
||
func NewGrpcHandlerImpl(logger *zap.SugaredLogger) *GrpcHandlerImpl { | ||
return &GrpcHandlerImpl{ | ||
logger: logger, | ||
} | ||
} | ||
|
||
func (impl *GrpcHandlerImpl) GetClusterUpgradeSummaryValidationResult(ctx context.Context, request *grpc.ClusterUpgradeRequest) (*grpc.ClusterUpgradeResponse, error) { | ||
|
||
} |
Oops, something went wrong.