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

Commit

Permalink
Logging the runner type during operations
Browse files Browse the repository at this point in the history
  • Loading branch information
izaaklauer committed Dec 3, 2021
1 parent 1f34608 commit 304e14b
Show file tree
Hide file tree
Showing 12 changed files with 3,279 additions and 2,879 deletions.
2 changes: 1 addition & 1 deletion builtin/docker/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (b *TaskLauncher) StartTask(
"spawn docker container for task",
"oci-url", tli.OciUrl,
"arguments", tli.Arguments,
"environment", env,
//"environment", env, // NOTE(izaak): env vars are likely to contain secrets, so we shouldn't log them.
)

var memory int64
Expand Down
7 changes: 1 addition & 6 deletions internal/cli/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,7 @@ func remoteOpPreferred(ctx context.Context, client pb.WaypointClient, project *p
}
hasRemoteRunner := false
for _, runner := range runnersResp.Runners {
if !runner.Odr {
// NOTE(izaak): There is currently no way to distinguish between a remote runner and a CLI runner.
// So if some other waypoint client is performing an operation at this moment, we will interpret
// that as a remote runner, and this will return a false positive.

// Also note that this is designed to run before se start our own CLI runner.
if _, ok := runner.Type.(*pb.Runner_Remote); ok {
hasRemoteRunner = true
break
}
Expand Down
12 changes: 11 additions & 1 deletion internal/cli/runner_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ type RunnerAgentCommand struct {
// is made available to the plugins so they can alter their behavior for
// this unique context.
flagODR bool

// If this is an ODR runner, this should be the ODR profile that it was created
// from.
flagOdrProfileId string
}

// This is how long a runner in ODR mode will wait for its job assignment before
Expand Down Expand Up @@ -133,7 +137,7 @@ func (c *RunnerAgentCommand) Run(args []string) int {

if c.flagODR {
options = append(options,
runnerpkg.WithODR(),
runnerpkg.WithODR(c.flagOdrProfileId),
runnerpkg.ByIdOnly(),
runnerpkg.WithAcceptTimeout(defaultRunnerODRAcceptTimeout),
)
Expand Down Expand Up @@ -273,6 +277,12 @@ func (c *RunnerAgentCommand) Flags() *flag.Sets {
Target: &c.flagODR,
Usage: "Indicates to the runner it's operating as an on-demand runner.",
})

f.StringVar(&flag.StringVar{
Name: "odr-profile-id",
Target: &c.flagOdrProfileId,
Hidden: true,
})
})
}

Expand Down
36 changes: 36 additions & 0 deletions internal/client/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ func (c *Project) queueAndStreamJob(
}()
}

var assignedRunner *pb.Ref_RunnerId

for {
resp, err := stream.Recv()
if err != nil {
Expand Down Expand Up @@ -325,6 +327,40 @@ func (c *Project) queueAndStreamJob(
stateEventTimer = nil
}

// Check if this job has been assigned a runner for the first time
if event.State != nil &&
event.State.Job != nil &&
event.State.Job.AssignedRunner != nil &&
assignedRunner == nil {

assignedRunner = event.State.Job.AssignedRunner

runner, err := c.client.GetRunner(ctx, &pb.GetRunnerRequest{RunnerId: assignedRunner.Id})
if err != nil {
c.UI.Output("Failed to inspect the runner (id %q) assigned for this operation: %s", assignedRunner.Id, err, terminal.WithErrorStyle())
}
switch runnerType := runner.Type.(type) {
case *pb.Runner_Local:
c.UI.Output("Performing operation locally", terminal.WithInfoStyle())
case *pb.Runner_Remote:
c.UI.Output("Performing this operation on a remote runner with id %q", runner.Id, terminal.WithInfoStyle())
case *pb.Runner_Odr:
log.Debug("Executing operation on an on-demand runner from profile with ID %q", runnerType.Odr.ProfileId)
profile, err := c.client.GetOnDemandRunnerConfig(
ctx, &pb.GetOnDemandRunnerConfigRequest{
Config: &pb.Ref_OnDemandRunnerConfig{
Id: runnerType.Odr.ProfileId,
},
})
if err != nil {
c.UI.Output("Performing operation on an on-demand runner from profile with ID %q", runnerType.Odr.ProfileId, terminal.WithInfoStyle())
c.UI.Output("Failed inspecting runner profile with id %q: %s", runnerType.Odr.GetProfileId(), err, terminal.WithErrorStyle())
} else {
c.UI.Output("Performing operation on %q with runner profile %q", profile.Config.PluginType, profile.Config.Name, terminal.WithInfoStyle())
}
}
}

// For certain states, we do a quality of life UI message if
// the wait time ends up being long.
switch event.State.Current {
Expand Down
6 changes: 6 additions & 0 deletions internal/runner/operation_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ func (r *Runner) executeStartTaskOp(
tli.Arguments = sti.Arguments
}

if tli.EnvironmentVariables == nil {
tli.EnvironmentVariables = make(map[string]string)
}
// TODO(izaak): document this somewhere
tli.EnvironmentVariables["WAYPOINT_TASK_JOB_ID"] = job.Id

fn := c.(component.TaskLauncher).StartTaskFunc()

val, err := pi.Invoke(ctx, log, fn, tli)
Expand Down
25 changes: 21 additions & 4 deletions internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,22 @@ func New(opts ...Option) (*Runner, error) {
runner.runner = &pb.Runner{
Id: runner.id,
ByIdOnly: cfg.byIdOnly,
Odr: cfg.odr,
}

if cfg.odr {
runner.runner.Type = &pb.Runner_Odr{
Odr: &pb.Runner_TypeODR{
ProfileId: cfg.odrProfileId,
},
}
} else if runner.local {
runner.runner.Type = &pb.Runner_Local{
Local: &pb.Runner_TypeLocal{},
}
} else {
runner.runner.Type = &pb.Runner_Remote{
Remote: &pb.Runner_TypeRemote{},
}
}

// Setup our runner components list
Expand Down Expand Up @@ -267,8 +282,9 @@ func (r *Runner) setState(state *bool, v bool) {
}

type config struct {
byIdOnly bool
odr bool
byIdOnly bool
odr bool
odrProfileId string
}

type Option func(*Runner, *config) error
Expand Down Expand Up @@ -323,9 +339,10 @@ func ByIdOnly() Option {

// WithODR configures this runner to be an on-demand runner. This
// will flag this to the server on registration.
func WithODR() Option {
func WithODR(profileId string) Option {
return func(r *Runner, cfg *config) error {
cfg.odr = true
cfg.odrProfileId = profileId
return nil
}
}
Expand Down
15 changes: 15 additions & 0 deletions internal/server/gen/mocks/is_runner__type.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 304e14b

Please sign in to comment.