-
Notifications
You must be signed in to change notification settings - Fork 16
Check the agent's status #232
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ed37ab0
Simplify workspace status check
code-asher 3b06d9f
Simplify agent model list
code-asher 9b787c7
Add lifecycle_state and login_before_ready to agent response
code-asher 9ab8769
Check agent status
code-asher 5f31f55
Remove unused expressions
code-asher 176d868
Add tooltips to describe the status
code-asher d5abf2b
Simplify some borders
code-asher 596934c
Fix start/shutdown timeout status
code-asher a70a32b
Extract ready logic to WorkspaceAndAgentStatus
code-asher 55e4a61
Change agent timeout description
code-asher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
src/main/kotlin/com/coder/gateway/models/WorkspaceAgentStatus.kt
This file was deleted.
Oops, something went wrong.
106 changes: 106 additions & 0 deletions
106
src/main/kotlin/com/coder/gateway/models/WorkspaceAndAgentStatus.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package com.coder.gateway.models | ||
|
||
import com.coder.gateway.sdk.v2.models.Workspace | ||
import com.coder.gateway.sdk.v2.models.WorkspaceAgent | ||
import com.coder.gateway.sdk.v2.models.WorkspaceAgentLifecycleState | ||
import com.coder.gateway.sdk.v2.models.WorkspaceAgentStatus | ||
import com.coder.gateway.sdk.v2.models.WorkspaceStatus | ||
import com.intellij.ui.JBColor | ||
|
||
/** | ||
* WorkspaceAndAgentStatus represents the combined status of a single agent and | ||
* its workspace (or just the workspace if there are no agents). | ||
*/ | ||
enum class WorkspaceAndAgentStatus(val label: String, val description: String) { | ||
// Workspace states. | ||
QUEUED("◍ Queued", "The workspace is queueing to start."), | ||
STARTING("⦿ Starting", "The workspace is starting."), | ||
FAILED("ⓧ Failed", "The workspace has failed to start."), | ||
DELETING("⦸ Deleting", "The workspace is being deleted."), | ||
DELETED("⦸ Deleted", "The workspace has been deleted."), | ||
STOPPING("◍ Stopping", "The workspace is stopping."), | ||
STOPPED("◍ Stopped", "The workspace has stopped."), | ||
CANCELING("◍ Canceling action", "The workspace is being canceled."), | ||
CANCELED("◍ Canceled action", "The workspace has been canceled."), | ||
RUNNING("⦿ Running", "The workspace is running, waiting for agents."), | ||
|
||
// Agent states. | ||
CONNECTING("⦿ Connecting", "The agent is connecting."), | ||
DISCONNECTED("⦸ Disconnected", "The agent has disconnected."), | ||
TIMEOUT("ⓧ Timeout", "The agent is taking longer than expected to connect."), | ||
AGENT_STARTING("⦿ Starting", "The startup script is running."), | ||
AGENT_STARTING_READY("⦿ Starting", "The startup script is still running but the agent is ready to accept connections."), | ||
CREATED("⦿ Created", "The agent has been created."), | ||
START_ERROR("◍ Started with error", "The agent is ready but the startup script errored."), | ||
START_TIMEOUT("◍ Starting", "The startup script is taking longer than expected."), | ||
START_TIMEOUT_READY("◍ Starting", "The startup script is taking longer than expected but the agent is ready to accept connections."), | ||
SHUTTING_DOWN("◍ Shutting down", "The agent is shutting down."), | ||
SHUTDOWN_ERROR("⦸ Shutdown with error", "The agent shut down but the shutdown script errored."), | ||
SHUTDOWN_TIMEOUT("⦸ Shutting down", "The shutdown script is taking longer than expected."), | ||
OFF("⦸ Off", "The agent has shut down."), | ||
READY("⦿ Ready", "The agent is ready to accept connections."); | ||
|
||
fun statusColor(): JBColor = when (this) { | ||
READY, AGENT_STARTING_READY, START_TIMEOUT_READY -> JBColor.GREEN | ||
START_ERROR, START_TIMEOUT, SHUTDOWN_TIMEOUT -> JBColor.YELLOW | ||
FAILED, DISCONNECTED, TIMEOUT, SHUTDOWN_ERROR -> JBColor.RED | ||
else -> if (JBColor.isBright()) JBColor.LIGHT_GRAY else JBColor.DARK_GRAY | ||
} | ||
|
||
/** | ||
* Return true if the agent is in a connectable state. | ||
*/ | ||
fun ready(): Boolean { | ||
return listOf(READY, START_ERROR, AGENT_STARTING_READY, START_TIMEOUT_READY) | ||
.contains(this) | ||
} | ||
|
||
// We want to check that the workspace is `running`, the agent is | ||
// `connected`, and the agent lifecycle state is `ready` to ensure the best | ||
// possible scenario for attempting a connection. | ||
// | ||
// We can also choose to allow `start_error` for the agent lifecycle state; | ||
// this means the startup script did not successfully complete but the agent | ||
// will still accept SSH connections. | ||
// | ||
// Lastly we can also allow connections when the agent lifecycle state is | ||
// `starting` or `start_timeout` if `login_before_ready` is true on the | ||
// workspace response since this bypasses the need to wait for the script. | ||
// | ||
// Note that latest_build.status is derived from latest_build.job.status and | ||
// latest_build.job.transition so there is no need to check those. | ||
companion object { | ||
fun from(workspace: Workspace, agent: WorkspaceAgent? = null) = when (workspace.latestBuild.status) { | ||
WorkspaceStatus.PENDING -> QUEUED | ||
WorkspaceStatus.STARTING -> STARTING | ||
WorkspaceStatus.RUNNING -> when (agent?.status) { | ||
WorkspaceAgentStatus.CONNECTED -> when (agent.lifecycleState) { | ||
WorkspaceAgentLifecycleState.CREATED -> CREATED | ||
WorkspaceAgentLifecycleState.STARTING -> if (agent.loginBeforeReady == true) AGENT_STARTING_READY else AGENT_STARTING | ||
WorkspaceAgentLifecycleState.START_TIMEOUT -> if (agent.loginBeforeReady == true) START_TIMEOUT_READY else START_TIMEOUT | ||
WorkspaceAgentLifecycleState.START_ERROR -> START_ERROR | ||
WorkspaceAgentLifecycleState.READY -> READY | ||
WorkspaceAgentLifecycleState.SHUTTING_DOWN -> SHUTTING_DOWN | ||
WorkspaceAgentLifecycleState.SHUTDOWN_TIMEOUT -> SHUTDOWN_TIMEOUT | ||
WorkspaceAgentLifecycleState.SHUTDOWN_ERROR -> SHUTDOWN_ERROR | ||
WorkspaceAgentLifecycleState.OFF -> OFF | ||
} | ||
|
||
WorkspaceAgentStatus.DISCONNECTED -> DISCONNECTED | ||
WorkspaceAgentStatus.TIMEOUT -> TIMEOUT | ||
WorkspaceAgentStatus.CONNECTING -> CONNECTING | ||
else -> RUNNING | ||
} | ||
|
||
WorkspaceStatus.STOPPING -> STOPPING | ||
WorkspaceStatus.STOPPED -> STOPPED | ||
WorkspaceStatus.FAILED -> FAILED | ||
WorkspaceStatus.CANCELING -> CANCELING | ||
WorkspaceStatus.CANCELED -> CANCELED | ||
WorkspaceStatus.DELETING -> DELETING | ||
WorkspaceStatus.DELETED -> DELETED | ||
} | ||
|
||
fun from(str: String) = WorkspaceAndAgentStatus.values().first { it.label.contains(str, true) } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something feels a bit off to me about this, like maybe we should just have the workspace status and agent status and check both whenever we need to rather than have this computed state but my thoughts about it are a bit fuzzy and we already had it architectured like this so I left it for now.