feat: Add connection_timeout and troubleshooting_url to agent (#4937)

* feat: Add connection_timeout and troubleshooting_url to agent

This commit adds the connection timeout and troubleshooting url fields
to coder agents.

If an initial connection cannot be established within connection timeout
seconds, then the agent status will be marked as `"timeout"`.

The troubleshooting URL will be present, if configured in the Terraform
template, it can be presented to the user when the agent state is either
`"timeout"` or `"disconnected"`.

Fixes #4678
This commit is contained in:
Mathias Fredriksson
2022-11-09 17:27:05 +02:00
committed by GitHub
parent ed7de90a55
commit 90c34b74de
44 changed files with 857 additions and 423 deletions

View File

@ -2,6 +2,7 @@ package testutil
import (
"context"
"fmt"
"testing"
"time"
@ -20,22 +21,31 @@ import (
//
// condition is not run in a goroutine; use the provided
// context argument for cancellation if required.
func Eventually(ctx context.Context, t testing.TB, condition func(context.Context) bool, tick time.Duration) bool {
func Eventually(ctx context.Context, t testing.TB, condition func(ctx context.Context) (done bool), tick time.Duration, msgAndArgs ...interface{}) (done bool) {
t.Helper()
if _, ok := ctx.Deadline(); !ok {
panic("developer error: must set deadline or timeout on ctx")
}
msg := "Eventually timed out"
if len(msgAndArgs) > 0 {
if m, ok := msgAndArgs[0].(string); ok {
msg = fmt.Sprintf(m, msgAndArgs[1:]...)
} else {
panic("developer error: first argument of msgAndArgs must be a string")
}
}
ticker := time.NewTicker(tick)
defer ticker.Stop()
for tick := ticker.C; ; {
select {
case <-ctx.Done():
assert.NoError(t, ctx.Err(), "Eventually timed out")
assert.NoError(t, ctx.Err(), msg)
return false
case <-tick:
if !assert.NoError(t, ctx.Err(), "Eventually timed out") {
if !assert.NoError(t, ctx.Err(), msg) {
return false
}
if condition(ctx) {