Skip to content

feat: add agent log streaming and follow provisioner format #8170

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

Merged
merged 11 commits into from
Jun 28, 2023
Prev Previous commit
Next Next commit
improve messages
  • Loading branch information
mafredri committed Jun 26, 2023
commit d42bf8c0579c5897fc07629f6866758a2f7ce382
7 changes: 4 additions & 3 deletions cli/cliui/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
// startup logs.
showStartupLogs = true

stage := "Waiting for initial connection from the workspace agent"
stage := "Waiting for the workspace agent to connect"
sw.Start(stage)
for agent.Status == codersdk.WorkspaceAgentConnecting {
if agent, err = fetch(); err != nil {
Expand All @@ -96,7 +96,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {

if agent.Status == codersdk.WorkspaceAgentTimeout {
now := time.Now()
sw.Log(now, codersdk.LogLevelInfo, "The workspace agent is having trouble connecting, we will keep trying to reach it")
sw.Log(now, codersdk.LogLevelInfo, "The workspace agent is having trouble connecting, wait for it to connect or restart your workspace.")
sw.Log(now, codersdk.LogLevelInfo, troubleshootingMessage(agent, "https://coder.com/docs/v2/latest/templates#agent-connection-issues"))
for agent.Status == codersdk.WorkspaceAgentTimeout {
if agent, err = fetch(); err != nil {
Expand Down Expand Up @@ -218,8 +218,9 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
case codersdk.WorkspaceAgentDisconnected:
showInitialConnection = false

stage := "The workspace agent lost connection, waiting for it to reconnect"
stage := "The workspace agent lost connection"
sw.Start(stage)
sw.Log(time.Now(), codersdk.LogLevelWarn, "Wait for it to reconnect or restart your workspace.")
sw.Log(time.Now(), codersdk.LogLevelWarn, troubleshootingMessage(agent, "https://coder.com/docs/v2/latest/templates#agent-connection-issues"))
for agent.Status == codersdk.WorkspaceAgentDisconnected {
if agent, err = fetch(); err != nil {
Expand Down
33 changes: 17 additions & 16 deletions cli/cliui/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func TestAgent(t *testing.T) {
},
},
want: []string{
"⧗ Waiting for initial connection from the workspace agent",
"✔ Waiting for initial connection from the workspace agent",
"⧗ Waiting for the workspace agent to connect",
"✔ Waiting for the workspace agent to connect",
"⧗ Running workspace agent startup script (non-blocking)",
"Notice: The startup script is still running and your workspace may be incomplete.",
"For more information and troubleshooting, see",
Expand Down Expand Up @@ -86,10 +86,10 @@ func TestAgent(t *testing.T) {
},
},
want: []string{
"⧗ Waiting for initial connection from the workspace agent",
"The workspace agent is having trouble connecting, we will keep trying to reach it",
"⧗ Waiting for the workspace agent to connect",
"The workspace agent is having trouble connecting, wait for it to connect or restart your workspace.",
"For more information and troubleshooting, see",
"✔ Waiting for initial connection from the workspace agent",
"✔ Waiting for the workspace agent to connect",
"⧗ Running workspace agent startup script (non-blocking)",
"✔ Running workspace agent startup script (non-blocking)",
},
Expand Down Expand Up @@ -121,9 +121,10 @@ func TestAgent(t *testing.T) {
},
},
want: []string{
"⧗ The workspace agent lost connection, waiting for it to reconnect",
"⧗ The workspace agent lost connection",
"Wait for it to reconnect or restart your workspace.",
"For more information and troubleshooting, see",
"✔ The workspace agent lost connection, waiting for it to reconnect",
"✔ The workspace agent lost connection",
},
},
{
Expand Down Expand Up @@ -160,8 +161,8 @@ func TestAgent(t *testing.T) {
},
},
want: []string{
"⧗ Waiting for initial connection from the workspace agent",
"✔ Waiting for initial connection from the workspace agent",
"⧗ Waiting for the workspace agent to connect",
"✔ Waiting for the workspace agent to connect",
"⧗ Running workspace agent startup script",
"Hello world",
"Bye now",
Expand Down Expand Up @@ -192,8 +193,8 @@ func TestAgent(t *testing.T) {
},
},
want: []string{
"⧗ Waiting for initial connection from the workspace agent",
"✔ Waiting for initial connection from the workspace agent",
"⧗ Waiting for the workspace agent to connect",
"✔ Waiting for the workspace agent to connect",
"⧗ Running workspace agent startup script",
"Hello world",
"Warning: The startup script exited with an error and your workspace may be incomplete.",
Expand Down Expand Up @@ -244,8 +245,8 @@ func TestAgent(t *testing.T) {
},
},
want: []string{
"⧗ Waiting for initial connection from the workspace agent",
"✔ Waiting for initial connection from the workspace agent",
"⧗ Waiting for the workspace agent to connect",
"✔ Waiting for the workspace agent to connect",
"⧗ Running workspace agent startup script",
"Hello world",
"✔ Running workspace agent startup script",
Expand All @@ -268,7 +269,7 @@ func TestAgent(t *testing.T) {
},
},
want: []string{
"⧗ Waiting for initial connection from the workspace agent",
"⧗ Waiting for the workspace agent to connect",
},
wantErr: true,
},
Expand All @@ -289,8 +290,8 @@ func TestAgent(t *testing.T) {
},
},
want: []string{
"⧗ Waiting for initial connection from the workspace agent",
"The workspace agent is having trouble connecting, we will keep trying to reach it",
"⧗ Waiting for the workspace agent to connect",
"The workspace agent is having trouble connecting, wait for it to connect or restart your workspace.",
"https://troubleshoot",
},
wantErr: true,
Expand Down