Compare commits

..

8 Commits

Author SHA1 Message Date
defelmnq
66aa7bf80a add validation rules to monitoring variables 2024-12-11 00:06:06 +01:00
defelmnq
1a101ecc10 improve versions set 2024-12-10 15:42:02 +01:00
defelmnq
9c049bd555 improve desription and default values 2024-12-10 15:39:53 +01:00
defelmnq
84bf63705f Work on monitoring module 2024-12-10 15:21:20 +01:00
defelmnq
e4af2a9887 Work on monitoring module 2024-12-10 15:17:20 +01:00
Muhammad Atif Ali
cbd06b1135 Improve incident management in Instatus check script (#346) 2024-12-05 14:24:45 +05:00
Muhammad Atif Ali
675c82367a feat(jetbrains-gateway): bump to 2024.3 (#355) 2024-11-29 15:51:24 +00:00
Mathias Fredriksson
bf697e1fa4 fix(update-versions.sh): handle markdown/tf block nesting when updating version (#356) 2024-11-29 20:22:43 +05:00
8 changed files with 292 additions and 136 deletions

View File

@@ -48,7 +48,7 @@ update_component_status() {
# Function to create an incident
create_incident() {
local incident_name="Testing Instatus"
local incident_name="Degraded Service"
local message="The following modules are experiencing issues:\n"
for i in "${!failures[@]}"; do
message+="$((i + 1)). ${failures[$i]}\n"
@@ -59,7 +59,7 @@ create_incident() {
component_status="MAJOROUTAGE"
fi
# see https://instatus.com/help/api/incidents
response=$(curl -s -X POST "https://api.instatus.com/v1/$INSTATUS_PAGE_ID/incidents" \
incident_id=$(curl -s -X POST "https://api.instatus.com/v1/$INSTATUS_PAGE_ID/incidents" \
-H "Authorization: Bearer $INSTATUS_API_KEY" \
-H "Content-Type: application/json" \
-d "{
@@ -74,10 +74,25 @@ create_incident() {
\"status\": \"PARTIALOUTAGE\"
}
]
}")
}" | jq -r '.id')
incident_id=$(echo "$response" | jq -r '.id')
echo "$incident_id"
echo "Created incident with ID: $incident_id"
}
# Function to check for existing unresolved incidents
check_existing_incident() {
# Fetch the latest incidents with status not equal to "RESOLVED"
local unresolved_incidents=$(curl -s -X GET "https://api.instatus.com/v1/$INSTATUS_PAGE_ID/incidents" \
-H "Authorization: Bearer $INSTATUS_API_KEY" \
-H "Content-Type: application/json" | jq -r '.incidents[] | select(.status != "RESOLVED") | .id')
if [[ -n "$unresolved_incidents" ]]; then
echo "Unresolved incidents found: $unresolved_incidents"
return 0 # Indicate that there are unresolved incidents
else
echo "No unresolved incidents found."
return 1 # Indicate that no unresolved incidents exist
fi
}
force_redeploy_registry () {
@@ -174,9 +189,10 @@ else
update_component_status "PARTIALOUTAGE"
fi
# Create a new incident
incident_id=$(create_incident)
echo "Created incident with ID: $incident_id"
# Check if there is an existing incident before creating a new one
if ! check_existing_incident; then
create_incident
fi
# If a module is down, force a reployment to try getting things back online
# ASAP

View File

@@ -14,12 +14,12 @@ This module adds a JetBrains Gateway Button to open any workspace with a single
```tf
module "jetbrains_gateway" {
source = "registry.coder.com/modules/jetbrains-gateway/coder"
version = "1.0.24"
version = "1.0.25"
agent_id = coder_agent.example.id
agent_name = "example"
folder = "/home/coder/example"
jetbrains_ides = ["CL", "GO", "IU", "PY", "WS"]
default = ["GO"]
default = "GO"
}
```
@@ -32,27 +32,52 @@ module "jetbrains_gateway" {
```tf
module "jetbrains_gateway" {
source = "registry.coder.com/modules/jetbrains-gateway/coder"
version = "1.0.24"
version = "1.0.25"
agent_id = coder_agent.example.id
agent_name = "example"
folder = "/home/coder/example"
jetbrains_ides = ["GO", "WS"]
default = ["GO"]
default = "GO"
}
```
### Use the fixed version
### Use the latest version of each IDE
```tf
module "jetbrains_gateway" {
source = "registry.coder.com/modules/jetbrains-gateway/coder"
version = "1.0.24"
version = "1.0.25"
agent_id = coder_agent.example.id
agent_name = "example"
folder = "/home/coder/example"
jetbrains_ides = ["GO", "WS"]
default = ["GO"]
latest = false # current version is 2024.3
jetbrains_ides = ["IU", "PY"]
default = "IU"
latest = true
}
```
### Use fixed versions set by `jetbrains_ide_versions`
```tf
module "jetbrains_gateway" {
source = "registry.coder.com/modules/jetbrains-gateway/coder"
version = "1.0.25"
agent_id = coder_agent.example.id
agent_name = "example"
folder = "/home/coder/example"
jetbrains_ides = ["IU", "PY"]
default = "IU"
latest = false
jetbrains_ide_versions = {
"IU" = {
build_number = "243.21565.193"
version = "2024.3"
}
"PY" = {
build_number = "243.21565.199"
version = "2024.3"
}
}
}
```
@@ -61,12 +86,12 @@ module "jetbrains_gateway" {
```tf
module "jetbrains_gateway" {
source = "registry.coder.com/modules/jetbrains-gateway/coder"
version = "1.0.24"
version = "1.0.25"
agent_id = coder_agent.example.id
agent_name = "example"
folder = "/home/coder/example"
jetbrains_ides = ["GO", "WS"]
default = ["GO"]
default = "GO"
latest = true
channel = "eap"
}
@@ -79,29 +104,14 @@ Due to the highest priority of the `ide_download_link` parameter in the `(jetbra
```tf
module "jetbrains_gateway" {
source = "registry.coder.com/modules/jetbrains-gateway/coder"
version = "1.0.24"
version = "1.0.25"
agent_id = coder_agent.example.id
agent_name = "example"
folder = "/home/coder/example"
jetbrains_ides = ["GO", "WS"]
releases_base_link = "https://releases.internal.site/"
download_base_link = "https://download.internal.site/"
default = ["GO"]
}
```
### Add multiple IDEs
**Note:** This removes the choice of IDE from the user.
```tf
module "jetbrains_gateway" {
source = "registry.coder.com/modules/jetbrains-gateway/coder"
version = "1.0.24"
agent_id = coder_agent.example.id
agent_name = "example"
folder = "/home/coder/example"
default = ["GO", "WS"]
default = "GO"
}
```

View File

@@ -16,13 +16,14 @@ describe("jetbrains-gateway", async () => {
it("should create a link with the default values", async () => {
const state = await runTerraformApply(import.meta.dir, {
// These are all required.
agent_id: "foo",
agent_name: "foo",
folder: "/home/coder",
});
expect(state.outputs.url.value).toEqual([
expect(state.outputs.url.value).toBe(
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&agent=foo&folder=/home/coder&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=IU&ide_build_number=243.21565.193&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2024.3.tar.gz",
]);
);
const coder_app = state.resources.find(
(res) => res.type === "coder_app" && res.name === "gateway",
@@ -33,31 +34,13 @@ describe("jetbrains-gateway", async () => {
expect(coder_app?.instances[0].attributes.order).toBeNull();
});
it("default to first IDE", async () => {
it("default to first ide", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "foo",
agent_name: "foo",
folder: "/home/foo",
jetbrains_ides: ["IU", "PY"],
jetbrains_ides: '["IU", "GO", "PY"]',
});
expect(state.outputs.identifier.value).toEqual(["IU"]);
expect(state.outputs.url.value).toEqual([
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&agent=foo&folder=/home/foo&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=IU&ide_build_number=243.21565.193&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2024.3.tar.gz",
]);
});
it("should create multiple IDEs", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "foo",
agent_name: "foo",
folder: "/home/foo",
default: ["GO", "IU", "PY"],
});
expect(state.outputs.identifier.value).toEqual(["GO", "IU", "PY"]);
expect(state.outputs.url.value).toEqual([
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&agent=foo&folder=/home/foo&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=GO&ide_build_number=243.21565.208&ide_download_link=https://download.jetbrains.com/go/goland-2024.3.tar.gz",
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&agent=foo&folder=/home/foo&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=IU&ide_build_number=243.21565.193&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2024.3.tar.gz",
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&agent=foo&folder=/home/foo&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=PY&ide_build_number=243.21565.199&ide_download_link=https://download.jetbrains.com/python/pycharm-professional-2024.3.tar.gz",
]);
expect(state.outputs.identifier.value).toBe("IU");
});
});

View File

@@ -39,23 +39,9 @@ variable "folder" {
}
variable "default" {
default = []
type = list(string)
description = "List of default IDEs to be added to the Workspace page."
# check if the list is unique
validation {
condition = length(var.default) == length(toset(var.default))
error_message = "The default must not contain duplicates."
}
# check if default are valid jetbrains_ides
validation {
condition = (
alltrue([
for code in var.default : contains(["IU", "PS", "WS", "PY", "CL", "GO", "RM", "RD"], code)
])
)
error_message = "The default must be a list of valid product codes. Valid product codes are ${join(",", ["IU", "PS", "WS", "PY", "CL", "GO", "RM", "RD"])}."
}
default = ""
type = string
description = "Default IDE"
}
variable "order" {
@@ -73,7 +59,7 @@ variable "coder_parameter_order" {
variable "latest" {
type = bool
description = "Whether to fetch the latest version of the IDE."
default = true
default = false
}
variable "channel" {
@@ -138,7 +124,7 @@ variable "jetbrains_ide_versions" {
variable "jetbrains_ides" {
type = list(string)
description = "The list of IDE product codes to be shown to the user. Does not apply when there are multiple defaults."
description = "The list of IDE product codes."
default = ["IU", "PS", "WS", "PY", "CL", "GO", "RM", "RD"]
validation {
condition = (
@@ -253,42 +239,23 @@ locals {
}
}
identifier = try([data.coder_parameter.jetbrains_ide[0].value], var.default)
list_json_data = var.latest ? [
for ide in local.identifier : jsondecode(data.http.jetbrains_ide_versions[ide].response_body)
] : []
list_key = var.latest ? [
for j in local.list_json_data : keys(j)[0]
] : []
download_links = length(local.list_key) > 0 ? [
for i, j in local.list_json_data : j[local.list_key[i]][0].downloads.linux.link
] : [
for ide in local.identifier : local.jetbrains_ides[ide].download_link
]
build_numbers = length(local.list_key) > 0 ? [
for i, j in local.list_json_data : j[local.list_key[i]][0].build
] : [
for ide in local.identifier : local.jetbrains_ides[ide].build_number
]
versions = length(local.list_key) > 0 ? [
for i, j in local.list_json_data : j[local.list_key[i]][0].version
] : [
for ide in local.identifier : local.jetbrains_ides[ide].version
]
display_names = [for key in keys(coder_app.gateway) : coder_app.gateway[key].display_name]
icons = [for key in keys(coder_app.gateway) : coder_app.gateway[key].icon]
urls = [for key in keys(coder_app.gateway) : coder_app.gateway[key].url]
icon = local.jetbrains_ides[data.coder_parameter.jetbrains_ide.value].icon
json_data = var.latest ? jsondecode(data.http.jetbrains_ide_versions[data.coder_parameter.jetbrains_ide.value].response_body) : {}
key = var.latest ? keys(local.json_data)[0] : ""
display_name = local.jetbrains_ides[data.coder_parameter.jetbrains_ide.value].name
identifier = data.coder_parameter.jetbrains_ide.value
download_link = var.latest ? local.json_data[local.key][0].downloads.linux.link : local.jetbrains_ides[data.coder_parameter.jetbrains_ide.value].download_link
build_number = var.latest ? local.json_data[local.key][0].build : local.jetbrains_ides[data.coder_parameter.jetbrains_ide.value].build_number
version = var.latest ? local.json_data[local.key][0].version : var.jetbrains_ide_versions[data.coder_parameter.jetbrains_ide.value].version
}
data "coder_parameter" "jetbrains_ide" {
# remove the coder_parameter if there are multiple default
count = length(var.default) > 1 ? 0 : 1
type = "string"
name = "jetbrains_ide"
display_name = "JetBrains IDE"
icon = "/icon/gateway.svg"
mutable = true
default = length(var.default) > 0 ? var.default[0] : var.jetbrains_ides[0]
default = var.default == "" ? var.jetbrains_ides[0] : var.default
order = var.coder_parameter_order
dynamic "option" {
@@ -305,11 +272,10 @@ data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}
resource "coder_app" "gateway" {
for_each = length(var.default) > 1 ? toset(var.default) : toset([data.coder_parameter.jetbrains_ide[0].value])
agent_id = var.agent_id
slug = "${var.slug}-${lower(each.value)}"
display_name = local.jetbrains_ides[each.value].name
icon = local.jetbrains_ides[each.value].icon
slug = var.slug
display_name = local.display_name
icon = local.icon
external = true
order = var.order
url = join("", [
@@ -326,45 +292,38 @@ resource "coder_app" "gateway" {
"&token=",
"$SESSION_TOKEN",
"&ide_product_code=",
each.value,
data.coder_parameter.jetbrains_ide.value,
"&ide_build_number=",
local.jetbrains_ides[each.value].build_number,
local.build_number,
"&ide_download_link=",
local.jetbrains_ides[each.value].download_link,
local.download_link,
])
}
output "identifier" {
value = local.identifier
description = "The product code of the JetBrains IDE."
}
output "display_name" {
value = [for key in keys(coder_app.gateway) : coder_app.gateway[key].display_name]
description = "The display name of the JetBrains IDE."
value = local.display_name
}
output "icon" {
value = [for key in keys(coder_app.gateway) : coder_app.gateway[key].icon]
description = "The icon of the JetBrains IDE."
value = local.icon
}
output "download_link" {
value = local.download_links
description = "The download link of the JetBrains IDE."
value = local.download_link
}
output "build_number" {
value = local.build_numbers
description = "The build number of the JetBrains IDE."
value = local.build_number
}
output "version" {
value = local.versions
description = "The version of the JetBrains IDE."
value = local.version
}
output "url" {
value = [for key in keys(coder_app.gateway) : coder_app.gateway[key].url]
description = "The URL to connect to the JetBrains IDE."
value = coder_app.gateway.url
}

72
monitoring/README.md Normal file
View File

@@ -0,0 +1,72 @@
---
display_name: Monitoring
description: Monitoring of workspace resources
maintainer_github: coder
verified: true
tags: [monitoring]
---
# Monitoring
This module adds monitoring of workspace resources.
```tf
module "monitoring" {
source = "registry.coder.com/modules/monitoring/coder"
version = "1.0.0"
agent_id = coder_agent.dev.id
}
```
## Examples
```tf
module "monitoring" {
source = "registry.coder.com/modules/monitoring/coder"
version = "1.0.0"
agent_id = coder_agent.dev.id
}
```
### Enable/Disable
You can customize the monitoring by setting the `enabled`, `memory_enabled`, and `disk_enabled` variables.
```tf
module "monitoring" {
source = "registry.coder.com/modules/monitoring/coder"
version = "1.0.0"
agent_id = coder_agent.dev.id
enabled = false
memory_enabled = true
disk_enabled = false
}
```
### Customize Thresholds
You can customize the thresholds by setting the `threshold`, `memory_threshold`, and `disk_threshold` variables.
```tf
module "monitoring" {
source = "registry.coder.com/modules/monitoring/coder"
version = "1.0.0"
agent_id = coder_agent.dev.id
threshold = 90
memory_threshold = 95
disk_threshold = 90
}
```
### Customize Disks
You can customize the disks by setting the `disks` variable.
```tf
module "monitoring" {
source = "registry.coder.com/modules/monitoring/coder"
version = "1.0.0"
agent_id = coder_agent.dev.id
disks = ["/"]
}
```

92
monitoring/main.tf Normal file
View File

@@ -0,0 +1,92 @@
terraform {
required_version = ">= 1.0.25"
required_providers {
coder = {
source = "coder/coder"
version = ">= 2.0.2"
}
}
}
variable "threshold" {
type = number
description = "The threshold for the monitoring, used for all resources unless overridden by *_threshold - expressed as a percentage."
default = 90
validation {
condition = var.threshold >= 0 && var.threshold <= 100
error_message = "The threshold must be between 0 and 100."
}
}
variable "memory_threshold" {
type = number
description = "The threshold for the memory monitoring - expressed as a percentage."
default = 90
validation {
condition = var.memory_threshold >= 0 && var.memory_threshold <= 100
error_message = "The memory_threshold must be between 0 and 100."
}
}
variable "disk_threshold" {
type = number
description = "The threshold for the disk monitoring - expressed as a percentage."
default = 90
validation {
condition = var.disk_threshold >= 0 && var.disk_threshold <= 100
error_message = "The disk_threshold must be between 0 and 100."
}
}
variable "disks" {
type = list(string)
description = "The disks to monitor. e.g. ['/', '/home']"
default = ["/"]
}
variable "enabled" {
type = bool
description = "Whether the monitoring is enabled."
default = true
validation {
condition = var.enabled == true || var.enabled == false
error_message = "The enabled must be true or false."
}
}
variable "memory_enabled" {
type = bool
description = "Whether the memory monitoring is enabled."
default = true
validation {
condition = var.memory_enabled == true || var.memory_enabled == false
error_message = "The memory_enabled must be true or false."
}
}
variable "disk_enabled" {
type = bool
description = "Whether the disk monitoring is enabled."
default = true
validation {
condition = var.disk_enabled == true || var.disk_enabled == false
error_message = "The disk_enabled must be true or false."
}
}
variable "agent_id" {
type = string
description = "The ID of the agent to monitor."
}
data "coder_monitoring" "monitoring" {
threshold = var.threshold
memory_threshold = var.memory_threshold
disk_threshold = var.disk_threshold
disks = var.disks
enabled = var.enabled
memory_enabled = var.memory_enabled
disk_enabled = var.disk_enabled
agent_id = var.agent_id
}

View File

@@ -200,8 +200,7 @@ export const runTerraformApply = async <TVars extends TerraformVariables>(
const combinedEnv = env === undefined ? {} : { ...env };
for (const [key, value] of Object.entries(vars)) {
// Convert arrays to JSON strings
combinedEnv[`TF_VAR_${key}`] = Array.isArray(value) ? JSON.stringify(value) : String(value);
combinedEnv[`TF_VAR_${key}`] = String(value);
}
const proc = spawn(

View File

@@ -21,14 +21,39 @@ for dir in "${changed_dirs[@]}"; do
if [[ -f "$dir/README.md" ]]; then
file="$dir/README.md"
tmpfile=$(mktemp /tmp/tempfile.XXXXXX)
awk -v tag="$LATEST_TAG" '{
if ($1 == "version" && $2 == "=") {
awk -v tag="$LATEST_TAG" '
BEGIN { in_code_block = 0; in_nested_block = 0 }
{
# Detect the start and end of Markdown code blocks.
if ($0 ~ /^```/) {
in_code_block = !in_code_block
# Reset nested block tracking when exiting a code block.
if (!in_code_block) {
in_nested_block = 0
}
}
# Handle nested blocks within a code block.
if (in_code_block) {
# Detect the start of a nested block (skipping "module" blocks).
if ($0 ~ /{/ && !($1 == "module" || $1 ~ /^[a-zA-Z0-9_]+$/)) {
in_nested_block++
}
# Detect the end of a nested block.
if ($0 ~ /}/ && in_nested_block > 0) {
in_nested_block--
}
# Update "version" only if not in a nested block.
if (!in_nested_block && $1 == "version" && $2 == "=") {
sub(/"[^"]*"/, "\"" tag "\"")
print
} else {
}
}
print
}
}' "$file" > "$tmpfile" && mv "$tmpfile" "$file"
' "$file" > "$tmpfile" && mv "$tmpfile" "$file"
# Check if the README.md file has changed
if ! git diff --quiet -- "$dir/README.md"; then