mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add health check monitoring to workspace apps (#4114)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/awalterschulze/gographviz"
|
||||
@@ -25,12 +27,20 @@ type agentAttributes struct {
|
||||
|
||||
// A mapping of attributes on the "coder_app" resource.
|
||||
type agentAppAttributes struct {
|
||||
AgentID string `mapstructure:"agent_id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Icon string `mapstructure:"icon"`
|
||||
URL string `mapstructure:"url"`
|
||||
Command string `mapstructure:"command"`
|
||||
RelativePath bool `mapstructure:"relative_path"`
|
||||
AgentID string `mapstructure:"agent_id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Icon string `mapstructure:"icon"`
|
||||
URL string `mapstructure:"url"`
|
||||
Command string `mapstructure:"command"`
|
||||
RelativePath bool `mapstructure:"relative_path"`
|
||||
Healthcheck []appHealthcheckAttributes `mapstructure:"healthcheck"`
|
||||
}
|
||||
|
||||
// A mapping of attributes on the "healthcheck" resource.
|
||||
type appHealthcheckAttributes struct {
|
||||
URL string `mapstructure:"url"`
|
||||
Interval int32 `mapstructure:"interval"`
|
||||
Threshold int32 `mapstructure:"threshold"`
|
||||
}
|
||||
|
||||
// A mapping of attributes on the "coder_metadata" resource.
|
||||
@@ -212,12 +222,22 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res
|
||||
var attrs agentAppAttributes
|
||||
err = mapstructure.Decode(resource.AttributeValues, &attrs)
|
||||
if err != nil {
|
||||
d, _ := json.MarshalIndent(resource.AttributeValues, "", " ")
|
||||
fmt.Print(string(d))
|
||||
return nil, xerrors.Errorf("decode app attributes: %w", err)
|
||||
}
|
||||
if attrs.Name == "" {
|
||||
// Default to the resource name if none is set!
|
||||
attrs.Name = resource.Name
|
||||
}
|
||||
var healthcheck *proto.Healthcheck
|
||||
if len(attrs.Healthcheck) != 0 {
|
||||
healthcheck = &proto.Healthcheck{
|
||||
Url: attrs.Healthcheck[0].URL,
|
||||
Interval: attrs.Healthcheck[0].Interval,
|
||||
Threshold: attrs.Healthcheck[0].Threshold,
|
||||
}
|
||||
}
|
||||
for _, agents := range resourceAgents {
|
||||
for _, agent := range agents {
|
||||
// Find agents with the matching ID and associate them!
|
||||
@@ -230,6 +250,7 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res
|
||||
Url: attrs.URL,
|
||||
Icon: attrs.Icon,
|
||||
RelativePath: attrs.RelativePath,
|
||||
Healthcheck: healthcheck,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +112,11 @@ func TestConvertResources(t *testing.T) {
|
||||
Name: "app1",
|
||||
}, {
|
||||
Name: "app2",
|
||||
Healthcheck: &proto.Healthcheck{
|
||||
Url: "http://localhost:13337/healthz",
|
||||
Interval: 5,
|
||||
Threshold: 6,
|
||||
},
|
||||
}},
|
||||
Auth: &proto.Agent_Token{},
|
||||
}},
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "0.4.11"
|
||||
version = "0.4.15"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -16,11 +16,11 @@
|
||||
"auth": "token",
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "f05ddf9e-106a-4669-bba8-5e2289bd891d",
|
||||
"id": "f5435556-71b4-4e9c-a961-474ef4c70836",
|
||||
"init_script": "",
|
||||
"os": "linux",
|
||||
"startup_script": null,
|
||||
"token": "ed4655b9-e917-44af-8706-a1215384a35f"
|
||||
"token": "cbe1cec2-8c52-4411-ab1b-c7e9aa4e93ea"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
}
|
||||
@@ -44,7 +44,7 @@
|
||||
"outputs": {
|
||||
"script": ""
|
||||
},
|
||||
"random": "7640853885488752810"
|
||||
"random": "2977741887145450154"
|
||||
},
|
||||
"sensitive_values": {
|
||||
"inputs": {},
|
||||
@@ -59,7 +59,7 @@
|
||||
"provider_name": "registry.terraform.io/hashicorp/null",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"id": "6481148597794195898",
|
||||
"id": "3098344175322958112",
|
||||
"triggers": null
|
||||
},
|
||||
"sensitive_values": {},
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "0.4.11"
|
||||
version = "0.4.15"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
Vendored
+4
-4
@@ -16,11 +16,11 @@
|
||||
"auth": "token",
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "fcd8018c-7e4a-4e92-855b-e02319ab051e",
|
||||
"id": "846b2cd1-1dcc-4b26-ad71-8508c8d71738",
|
||||
"init_script": "",
|
||||
"os": "linux",
|
||||
"startup_script": null,
|
||||
"token": "ad906408-0eb0-4844-83f7-0f5070427e1c"
|
||||
"token": "3a3e4e25-6be2-4b51-a369-957fdb243a4f"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
},
|
||||
@@ -32,7 +32,7 @@
|
||||
"provider_name": "registry.terraform.io/hashicorp/null",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"id": "2672857180605476162",
|
||||
"id": "8441562949971496089",
|
||||
"triggers": null
|
||||
},
|
||||
"sensitive_values": {},
|
||||
@@ -49,7 +49,7 @@
|
||||
"provider_name": "registry.terraform.io/hashicorp/null",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"id": "264584188140644760",
|
||||
"id": "4737933879128730392",
|
||||
"triggers": null
|
||||
},
|
||||
"sensitive_values": {},
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "0.4.11"
|
||||
version = "0.4.15"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
Vendored
+4
-4
@@ -16,11 +16,11 @@
|
||||
"auth": "token",
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "e3df7d56-17ce-4d8a-9d4e-30ea41cc8a93",
|
||||
"id": "2efd4acf-bb30-4713-98b5-21fef293c995",
|
||||
"init_script": "",
|
||||
"os": "linux",
|
||||
"startup_script": null,
|
||||
"token": "1717f79d-2c72-440e-a5c6-e4b8c3fef084"
|
||||
"token": "7db84d6e-c079-4b4a-99e0-e2414a70df84"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
},
|
||||
@@ -32,7 +32,7 @@
|
||||
"provider_name": "registry.terraform.io/hashicorp/null",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"id": "2957375211969224115",
|
||||
"id": "6618109150570768254",
|
||||
"triggers": null
|
||||
},
|
||||
"sensitive_values": {},
|
||||
@@ -48,7 +48,7 @@
|
||||
"provider_name": "registry.terraform.io/hashicorp/null",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"id": "6924176854496195292",
|
||||
"id": "4505836003282545145",
|
||||
"triggers": null
|
||||
},
|
||||
"sensitive_values": {},
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "0.4.11"
|
||||
version = "0.4.15"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -16,11 +16,11 @@
|
||||
"auth": "google-instance-identity",
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "9a37096a-7f01-42cd-93d8-9f4572c94489",
|
||||
"id": "e2d2e12e-1975-4bca-8a96-67d6b303b25b",
|
||||
"init_script": "",
|
||||
"os": "linux",
|
||||
"startup_script": null,
|
||||
"token": "7784ea1f-7fe5-463f-af8d-255c32d12992"
|
||||
"token": "87ba2736-3519-4368-b9ee-4132bd042fe3"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
},
|
||||
@@ -32,8 +32,8 @@
|
||||
"provider_name": "registry.terraform.io/coder/coder",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"agent_id": "9a37096a-7f01-42cd-93d8-9f4572c94489",
|
||||
"id": "8ed448e2-51d7-4cc7-9e26-a3a77f252b1d",
|
||||
"agent_id": "e2d2e12e-1975-4bca-8a96-67d6b303b25b",
|
||||
"id": "979121e7-2a41-432a-aa90-8b0d2d802b50",
|
||||
"instance_id": "example"
|
||||
},
|
||||
"sensitive_values": {},
|
||||
@@ -49,7 +49,7 @@
|
||||
"provider_name": "registry.terraform.io/hashicorp/null",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"id": "771742387122791362",
|
||||
"id": "3316746911978433294",
|
||||
"triggers": null
|
||||
},
|
||||
"sensitive_values": {},
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "0.4.11"
|
||||
version = "0.4.15"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -16,11 +16,11 @@
|
||||
"auth": "token",
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "0c3c20d8-8a1d-4fc9-bc73-ed45ddad9a9d",
|
||||
"id": "032d71aa-570d-4d0a-bce8-57b9d884b694",
|
||||
"init_script": "",
|
||||
"os": "linux",
|
||||
"startup_script": null,
|
||||
"token": "48b3f4c4-4bb9-477c-8d32-d1e14188e5f8"
|
||||
"token": "7a0df6bf-313d-4f73-ba2c-6532d72cb808"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
},
|
||||
@@ -36,11 +36,11 @@
|
||||
"auth": "token",
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "08e8ebc8-4660-47f0-acb5-6ca46747919d",
|
||||
"id": "019ae4b9-ae5c-4837-be16-dae99b911acf",
|
||||
"init_script": "",
|
||||
"os": "darwin",
|
||||
"startup_script": null,
|
||||
"token": "827a1f01-a2d7-4794-ab73-8fd8442010d5"
|
||||
"token": "9f4adbf4-9113-42f4-bb84-d1621262b1e2"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
},
|
||||
@@ -56,11 +56,11 @@
|
||||
"auth": "token",
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "50f52bd4-a52b-4c73-bf99-fe956913bca4",
|
||||
"id": "8f2c3b12-e112-405e-9fbf-fe540ed3fe21",
|
||||
"init_script": "",
|
||||
"os": "windows",
|
||||
"startup_script": null,
|
||||
"token": "159d6407-a913-4e05-8ba7-786d47a7e34b"
|
||||
"token": "1a6ddbc7-77a9-43c2-9e60-c84d3ecf512a"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
},
|
||||
@@ -72,7 +72,7 @@
|
||||
"provider_name": "registry.terraform.io/hashicorp/null",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"id": "2529387636030139440",
|
||||
"id": "6351611769218065391",
|
||||
"triggers": null
|
||||
},
|
||||
"sensitive_values": {},
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "0.4.11"
|
||||
version = "0.4.15"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,11 @@ resource "coder_app" "app1" {
|
||||
|
||||
resource "coder_app" "app2" {
|
||||
agent_id = coder_agent.dev1.id
|
||||
healthcheck {
|
||||
url = "http://localhost:13337/healthz"
|
||||
interval = 5
|
||||
threshold = 6
|
||||
}
|
||||
}
|
||||
|
||||
resource "null_resource" "dev" {
|
||||
|
||||
+54
-7
@@ -30,12 +30,15 @@
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"command": null,
|
||||
"healthcheck": [],
|
||||
"icon": null,
|
||||
"name": null,
|
||||
"relative_path": null,
|
||||
"url": null
|
||||
},
|
||||
"sensitive_values": {}
|
||||
"sensitive_values": {
|
||||
"healthcheck": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"address": "coder_app.app2",
|
||||
@@ -46,12 +49,23 @@
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"command": null,
|
||||
"healthcheck": [
|
||||
{
|
||||
"interval": 5,
|
||||
"threshold": 6,
|
||||
"url": "http://localhost:13337/healthz"
|
||||
}
|
||||
],
|
||||
"icon": null,
|
||||
"name": null,
|
||||
"relative_path": null,
|
||||
"url": null
|
||||
},
|
||||
"sensitive_values": {}
|
||||
"sensitive_values": {
|
||||
"healthcheck": [
|
||||
{}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"address": "null_resource.dev",
|
||||
@@ -94,7 +108,9 @@
|
||||
"token": true
|
||||
},
|
||||
"before_sensitive": false,
|
||||
"after_sensitive": {}
|
||||
"after_sensitive": {
|
||||
"token": true
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -110,6 +126,7 @@
|
||||
"before": null,
|
||||
"after": {
|
||||
"command": null,
|
||||
"healthcheck": [],
|
||||
"icon": null,
|
||||
"name": null,
|
||||
"relative_path": null,
|
||||
@@ -117,10 +134,13 @@
|
||||
},
|
||||
"after_unknown": {
|
||||
"agent_id": true,
|
||||
"healthcheck": [],
|
||||
"id": true
|
||||
},
|
||||
"before_sensitive": false,
|
||||
"after_sensitive": {}
|
||||
"after_sensitive": {
|
||||
"healthcheck": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -136,6 +156,13 @@
|
||||
"before": null,
|
||||
"after": {
|
||||
"command": null,
|
||||
"healthcheck": [
|
||||
{
|
||||
"interval": 5,
|
||||
"threshold": 6,
|
||||
"url": "http://localhost:13337/healthz"
|
||||
}
|
||||
],
|
||||
"icon": null,
|
||||
"name": null,
|
||||
"relative_path": null,
|
||||
@@ -143,10 +170,17 @@
|
||||
},
|
||||
"after_unknown": {
|
||||
"agent_id": true,
|
||||
"healthcheck": [
|
||||
{}
|
||||
],
|
||||
"id": true
|
||||
},
|
||||
"before_sensitive": false,
|
||||
"after_sensitive": {}
|
||||
"after_sensitive": {
|
||||
"healthcheck": [
|
||||
{}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -176,7 +210,7 @@
|
||||
"coder": {
|
||||
"name": "coder",
|
||||
"full_name": "registry.terraform.io/coder/coder",
|
||||
"version_constraint": "0.4.11"
|
||||
"version_constraint": "0.4.14"
|
||||
},
|
||||
"null": {
|
||||
"name": "null",
|
||||
@@ -229,7 +263,20 @@
|
||||
"coder_agent.dev1.id",
|
||||
"coder_agent.dev1"
|
||||
]
|
||||
}
|
||||
},
|
||||
"healthcheck": [
|
||||
{
|
||||
"interval": {
|
||||
"constant_value": 5
|
||||
},
|
||||
"threshold": {
|
||||
"constant_value": 6
|
||||
},
|
||||
"url": {
|
||||
"constant_value": "http://localhost:13337/healthz"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"schema_version": 0
|
||||
},
|
||||
|
||||
+23
-9
@@ -16,11 +16,11 @@
|
||||
"auth": "token",
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "3d4ee1d5-6413-4dc7-baec-2fa9dbd870ba",
|
||||
"id": "685dba1f-09de-40c0-8fc0-4d8ca00ef946",
|
||||
"init_script": "",
|
||||
"os": "linux",
|
||||
"startup_script": null,
|
||||
"token": "32e082d7-af02-42f1-a5bd-f6adc34220a1"
|
||||
"token": "2c73d680-ef4c-4bc1-80f0-f6916e4e5255"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
},
|
||||
@@ -32,15 +32,18 @@
|
||||
"provider_name": "registry.terraform.io/coder/coder",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"agent_id": "3d4ee1d5-6413-4dc7-baec-2fa9dbd870ba",
|
||||
"agent_id": "685dba1f-09de-40c0-8fc0-4d8ca00ef946",
|
||||
"command": null,
|
||||
"healthcheck": [],
|
||||
"icon": null,
|
||||
"id": "90e045f9-19f1-4d8a-8021-be61c44ee54f",
|
||||
"id": "46f8d3cd-bcf7-4792-8d54-66e01e63018a",
|
||||
"name": null,
|
||||
"relative_path": null,
|
||||
"url": null
|
||||
},
|
||||
"sensitive_values": {},
|
||||
"sensitive_values": {
|
||||
"healthcheck": []
|
||||
},
|
||||
"depends_on": [
|
||||
"coder_agent.dev1"
|
||||
]
|
||||
@@ -53,15 +56,26 @@
|
||||
"provider_name": "registry.terraform.io/coder/coder",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"agent_id": "3d4ee1d5-6413-4dc7-baec-2fa9dbd870ba",
|
||||
"agent_id": "685dba1f-09de-40c0-8fc0-4d8ca00ef946",
|
||||
"command": null,
|
||||
"healthcheck": [
|
||||
{
|
||||
"interval": 5,
|
||||
"threshold": 6,
|
||||
"url": "http://localhost:13337/healthz"
|
||||
}
|
||||
],
|
||||
"icon": null,
|
||||
"id": "873026f8-3050-4b0b-bebf-41e13e5949bb",
|
||||
"id": "e4556c74-2f67-4266-b1e8-7ee61d754583",
|
||||
"name": null,
|
||||
"relative_path": null,
|
||||
"url": null
|
||||
},
|
||||
"sensitive_values": {},
|
||||
"sensitive_values": {
|
||||
"healthcheck": [
|
||||
{}
|
||||
]
|
||||
},
|
||||
"depends_on": [
|
||||
"coder_agent.dev1"
|
||||
]
|
||||
@@ -74,7 +88,7 @@
|
||||
"provider_name": "registry.terraform.io/hashicorp/null",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"id": "4447693752005094678",
|
||||
"id": "2997000197756647168",
|
||||
"triggers": null
|
||||
},
|
||||
"sensitive_values": {},
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "0.4.11"
|
||||
version = "0.4.15"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -16,11 +16,11 @@
|
||||
"auth": "token",
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "09aac2a4-9d8e-43ef-83cb-34657db199f4",
|
||||
"id": "50a0466c-d983-422f-8bed-9dd0bf705a9a",
|
||||
"init_script": "",
|
||||
"os": "linux",
|
||||
"startup_script": null,
|
||||
"token": "a0f6b8af-8edc-447f-b6d2-67a60ecd2a77"
|
||||
"token": "aa714059-3579-49d1-a0e2-3519dbe43688"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
},
|
||||
@@ -34,7 +34,7 @@
|
||||
"values": {
|
||||
"hide": true,
|
||||
"icon": "/icon/server.svg",
|
||||
"id": "a7f9cf03-de78-4d17-bcbb-21dc34c2d86a",
|
||||
"id": "64a47d31-28d0-4a50-8e09-a3e705278305",
|
||||
"item": [
|
||||
{
|
||||
"is_null": false,
|
||||
@@ -61,7 +61,7 @@
|
||||
"value": "squirrel"
|
||||
}
|
||||
],
|
||||
"resource_id": "6209384655473556868"
|
||||
"resource_id": "4887255791781048166"
|
||||
},
|
||||
"sensitive_values": {
|
||||
"item": [
|
||||
@@ -83,7 +83,7 @@
|
||||
"provider_name": "registry.terraform.io/hashicorp/null",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"id": "6209384655473556868",
|
||||
"id": "4887255791781048166",
|
||||
"triggers": null
|
||||
},
|
||||
"sensitive_values": {}
|
||||
|
||||
Reference in New Issue
Block a user