Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce plugin logpersister package #5342

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"fmt"

"github.com/pipe-cd/pipecd/pkg/app/pipedv1/cmd/piped/service"
"github.com/pipe-cd/pipecd/pkg/app/server/service/pipedservice"
"github.com/pipe-cd/pipecd/pkg/config"
"github.com/pipe-cd/pipecd/pkg/crypto"
"github.com/pipe-cd/pipecd/pkg/model"
Expand All @@ -30,19 +31,27 @@
type PluginAPI struct {
service.PluginServiceServer

cfg *config.PipedSpec
cfg *config.PipedSpec
apiClient apiClient

Logger *zap.Logger
}

type apiClient interface {
ReportStageLogs(ctx context.Context, req *pipedservice.ReportStageLogsRequest, opts ...grpc.CallOption) (*pipedservice.ReportStageLogsResponse, error)
ReportStageLogsFromLastCheckpoint(ctx context.Context, in *pipedservice.ReportStageLogsFromLastCheckpointRequest, opts ...grpc.CallOption) (*pipedservice.ReportStageLogsFromLastCheckpointResponse, error)
}

// Register registers all handling of this service into the specified gRPC server.
func (a *PluginAPI) Register(server *grpc.Server) {
service.RegisterPluginServiceServer(server, a)
}

func NewPluginAPI(cfg *config.PipedSpec, logger *zap.Logger) *PluginAPI {
func NewPluginAPI(cfg *config.PipedSpec, apiClient apiClient, logger *zap.Logger) *PluginAPI {

Check warning on line 50 in pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go#L50

Added line #L50 was not covered by tests
return &PluginAPI{
cfg: cfg,
Logger: logger.Named("plugin-api"),
cfg: cfg,
apiClient: apiClient,
Logger: logger.Named("plugin-api"),

Check warning on line 54 in pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go#L52-L54

Added lines #L52 - L54 were not covered by tests
}
}

Expand Down Expand Up @@ -71,6 +80,43 @@
}, nil
}

func (a *PluginAPI) ReportStageLogs(ctx context.Context, req *service.ReportStageLogsRequest) (*service.ReportStageLogsResponse, error) {
_, err := a.apiClient.ReportStageLogs(ctx, &pipedservice.ReportStageLogsRequest{
DeploymentId: req.DeploymentId,
StageId: req.StageId,
RetriedCount: req.RetriedCount,
Blocks: req.Blocks,
})
if err != nil {
a.Logger.Error("failed to report stage logs",
zap.String("deploymentID", req.DeploymentId),
zap.String("stageID", req.StageId),
zap.Error(err))
return nil, err
}

Check warning on line 96 in pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go#L83-L96

Added lines #L83 - L96 were not covered by tests

return &service.ReportStageLogsResponse{}, nil

Check warning on line 98 in pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go#L98

Added line #L98 was not covered by tests
}

func (a *PluginAPI) ReportStageLogsFromLastCheckpoint(ctx context.Context, req *service.ReportStageLogsFromLastCheckpointRequest) (*service.ReportStageLogsFromLastCheckpointResponse, error) {
_, err := a.apiClient.ReportStageLogsFromLastCheckpoint(ctx, &pipedservice.ReportStageLogsFromLastCheckpointRequest{
DeploymentId: req.DeploymentId,
StageId: req.StageId,
RetriedCount: req.RetriedCount,
Blocks: req.Blocks,
Completed: req.Completed,
})
if err != nil {
a.Logger.Error("failed to report stage logs from last checkpoint",
zap.String("deploymentID", req.DeploymentId),
zap.String("stageID", req.StageId),
zap.Error(err))
return nil, err
}

Check warning on line 115 in pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go#L101-L115

Added lines #L101 - L115 were not covered by tests

return &service.ReportStageLogsFromLastCheckpointResponse{}, nil

Check warning on line 117 in pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go#L117

Added line #L117 was not covered by tests
}

func initializeSecretDecrypter(sm *config.SecretManagement) (crypto.Decrypter, error) {
if sm == nil {
return nil, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/pipedv1/cmd/piped/piped.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
// Start running plugin service server.
{
var (
service = grpcapi.NewPluginAPI(cfg, input.Logger)
service = grpcapi.NewPluginAPI(cfg, apiClient, input.Logger)

Check warning on line 307 in pkg/app/pipedv1/cmd/piped/piped.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/piped.go#L307

Added line #L307 was not covered by tests
opts = []rpc.Option{
rpc.WithPort(p.pluginServicePort),
rpc.WithGracePeriod(p.gracePeriod),
Expand Down
Loading
Loading