Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1801 from hashicorp/feat/app-poll-handler
Browse files Browse the repository at this point in the history
feature: Queue status reports on continuous interval for applications
  • Loading branch information
briancain authored Jul 28, 2021
2 parents 96f9195 + 3ef4b05 commit a779e23
Show file tree
Hide file tree
Showing 21 changed files with 2,422 additions and 1,160 deletions.
4 changes: 4 additions & 0 deletions .changelog/1801.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:improvement
server: Continuously generate a status report for an application after the initial
deployment or release for projects backed by a git data source
```
50 changes: 38 additions & 12 deletions internal/cli/project_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ import (
type ProjectApplyCommand struct {
*baseCommand

flagDataSource string
flagGitURL string
flagGitRef string
flagGitAuthType string
flagGitUsername string
flagGitPassword string
flagGitKeyPath string
flagGitKeyPassword string
flagFromWaypointHcl string
flagWaypointHcl string
flagPoll bool
flagPollInterval string
flagDataSource string
flagGitURL string
flagGitRef string
flagGitAuthType string
flagGitUsername string
flagGitPassword string
flagGitKeyPath string
flagGitKeyPassword string
flagFromWaypointHcl string
flagWaypointHcl string
flagPoll bool
flagPollInterval string
flagAppStatusPoll bool
flagAppStatusPollInterval string
}

func (c *ProjectApplyCommand) Run(args []string) int {
Expand Down Expand Up @@ -171,6 +173,15 @@ func (c *ProjectApplyCommand) Run(args []string) int {
proj.DataSourcePoll.Interval = c.flagPollInterval
}

if c.flagAppStatusPoll {
if proj.StatusReportPoll == nil {
proj.StatusReportPoll = &pb.Project_AppStatusPoll{}
}

proj.StatusReportPoll.Enabled = c.flagAppStatusPoll
proj.StatusReportPoll.Interval = c.flagAppStatusPollInterval
}

// If the project existing datasource is Git, then we're overriding.
// If the existing datasource is not Git or not set, then we set it
// to Git and create new.
Expand Down Expand Up @@ -454,6 +465,21 @@ func (c *ProjectApplyCommand) Flags() *flag.Sets {
Default: "30s",
Usage: "Interval between polling if polling is enabled.",
})

f.BoolVar(&flag.BoolVar{
Name: "app-status-poll",
Target: &c.flagAppStatusPoll,
Default: false,
Usage: "Enable polling to continuously generate status reports for apps. " +
"This is only valid if a Git data source is supplied.",
})

f.StringVar(&flag.StringVar{
Name: "app-status-poll-interval",
Target: &c.flagAppStatusPollInterval,
Default: "5m",
Usage: "Interval between polling to generate status reports if polling is enabled.",
})
})
}

Expand Down
17 changes: 9 additions & 8 deletions internal/core/app_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ func (a *App) Release(ctx context.Context, target *pb.Deployment) (
"err", err)
}

unimplemeneted := false
unimplemented := false
c, err := a.createReleaser(ctx, &evalCtx)
if status.Code(err) == codes.Unimplemented {
c = nil
err = nil
unimplemeneted = true
unimplemented = true
}
if err != nil {
return nil, nil, err
Expand All @@ -80,7 +80,7 @@ func (a *App) Release(ctx context.Context, target *pb.Deployment) (

if releasepb != nil {
rpb := releasepb.(*pb.Release)
rpb.Unimplemented = unimplemeneted
rpb.Unimplemented = unimplemented
releasepb = rpb
}

Expand Down Expand Up @@ -166,11 +166,12 @@ type releaseOperation struct {

func (op *releaseOperation) Init(app *App) (proto.Message, error) {
release := &pb.Release{
Application: app.ref,
Workspace: app.workspace,
DeploymentId: op.Target.Id,
State: pb.Operation_CREATED,
Component: op.Target.Component,
Application: app.ref,
Workspace: app.workspace,
DeploymentId: op.Target.Id,
State: pb.Operation_CREATED,
Component: op.Target.Component,
Unimplemented: true,
}

if v := op.Component; v != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/runner/accept.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ func (r *Runner) prepareAndExecuteJob(
client pb.Waypoint_RunnerJobStreamClient,
job *pb.Job,
) (*pb.Job_Result, error) {
log.Trace("preparing to execute job operation", "type", hclog.Fmt("%T", job.Operation))

// Some operation types don't need to download data, execute those here.
switch job.Operation.(type) {
case *pb.Job_Poll:
Expand Down
2 changes: 1 addition & 1 deletion internal/runner/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (r *Runner) executeJob(
return r.executeQueueProjectOp(ctx, log, job, project)

case *pb.Job_StatusReport:
return r.executeStatusReportOp(ctx, job, project)
return r.executeStatusReportOp(ctx, log, job, project)

default:
return nil, status.Errorf(codes.Aborted, "unknown operation %T", job.Operation)
Expand Down
7 changes: 7 additions & 0 deletions internal/runner/operation_status_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"context"
"fmt"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/waypoint/internal/core"
pb "github.com/hashicorp/waypoint/internal/server/gen"
)

func (r *Runner) executeStatusReportOp(
ctx context.Context,
log hclog.Logger,
job *pb.Job,
project *core.Project,
) (*pb.Job_Result, error) {
Expand All @@ -25,12 +27,17 @@ func (r *Runner) executeStatusReportOp(
panic("operation not expected type")
}

log = log.With("app", job.Application.Application)

log.Trace("generating status report")
var statusReportResult *pb.StatusReport

switch t := op.StatusReport.Target.(type) {
case *pb.Job_StatusReportOp_Deployment:
log.Trace("starting a status report against a deployment")
statusReportResult, err = app.DeploymentStatusReport(ctx, t.Deployment)
case *pb.Job_StatusReportOp_Release:
log.Trace("starting a status report against a release")
statusReportResult, err = app.ReleaseStatusReport(ctx, t.Release)
default:
err = fmt.Errorf("unknown status report target: %T", op.StatusReport.Target)
Expand Down
4 changes: 2 additions & 2 deletions internal/runner/operation_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (r *Runner) executeUpOp(

// Status Report for Deployments
app.UI.Output("")
result, err = r.executeStatusReportOp(ctx, &pb.Job{
result, err = r.executeStatusReportOp(ctx, log, &pb.Job{
Application: job.Application,
Operation: &pb.Job_StatusReport{
StatusReport: &pb.Job_StatusReportOp{
Expand Down Expand Up @@ -105,7 +105,7 @@ func (r *Runner) executeUpOp(
releaseResult.Release.Release != nil {
// Status Report for Releases
app.UI.Output("")
result, err = r.executeStatusReportOp(ctx, &pb.Job{
result, err = r.executeStatusReportOp(ctx, log, &pb.Job{
Application: job.Application,
Operation: &pb.Job_StatusReport{
StatusReport: &pb.Job_StatusReportOp{
Expand Down
Loading

0 comments on commit a779e23

Please sign in to comment.