Skip to content

Commit 8a2e72b

Browse files
feat: add castai_workload_custom_metrics_data_source resource
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2de4dac commit 8a2e72b

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,23 @@ module "castai-eks-cluster" {
227227
excluded_containers = ["container-1", "container-2"]
228228
}
229229
}
230+
231+
workload_custom_metrics_data_sources = {
232+
my-prometheus = {
233+
prometheus = {
234+
url = "http://prometheus-server.monitoring.svc.cluster.local:9090"
235+
timeout = "30s"
236+
presets = ["jvm"]
237+
238+
metrics = [
239+
{
240+
name = "http_requests_total"
241+
query = "sum(rate(http_requests_total[5m])) by (pod)"
242+
}
243+
]
244+
}
245+
}
246+
}
230247
}
231248
```
232249

@@ -881,7 +898,7 @@ terraform-docs markdown table . --output-file README.md
881898
|------|---------|
882899
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
883900
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.23.0 |
884-
| <a name="requirement_castai"></a> [castai](#requirement\_castai) | >= 8.24.0 |
901+
| <a name="requirement_castai"></a> [castai](#requirement\_castai) | >= 8.26.0 |
885902
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 3.0.0 |
886903
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 3.0 |
887904

@@ -909,6 +926,7 @@ terraform-docs markdown table . --output-file README.md
909926
| [castai_node_configuration.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/node_configuration) | resource |
910927
| [castai_node_configuration_default.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/node_configuration_default) | resource |
911928
| [castai_node_template.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/node_template) | resource |
929+
| [castai_workload_custom_metrics_data_source.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/workload_custom_metrics_data_source) | resource |
912930
| [castai_workload_scaling_policy.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/workload_scaling_policy) | resource |
913931
| [helm_release.castai_agent](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
914932
| [helm_release.castai_ai_optimizer_proxy](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
@@ -1001,6 +1019,7 @@ terraform-docs markdown table . --output-file README.md
10011019
| <a name="input_workload_autoscaler_exporter_version"></a> [workload\_autoscaler\_exporter\_version](#input\_workload\_autoscaler\_exporter\_version) | Version of castai-workload-autoscaler-exporter helm chart. Default latest | `string` | `null` | no |
10021020
| <a name="input_workload_autoscaler_values"></a> [workload\_autoscaler\_values](#input\_workload\_autoscaler\_values) | List of YAML formatted string with cluster-workload-autoscaler values | `list(string)` | `[]` | no |
10031021
| <a name="input_workload_autoscaler_version"></a> [workload\_autoscaler\_version](#input\_workload\_autoscaler\_version) | Version of castai-workload-autoscaler helm chart. Default latest | `string` | `null` | no |
1022+
| <a name="input_workload_custom_metrics_data_sources"></a> [workload\_custom\_metrics\_data\_sources](#input\_workload\_custom\_metrics\_data\_sources) | Map of workload custom metrics data sources to create | `any` | `{}` | no |
10041023
| <a name="input_workload_scaling_policies"></a> [workload\_scaling\_policies](#input\_workload\_scaling\_policies) | Map of workload scaling policies to create | `any` | `{}` | no |
10051024

10061025
## Outputs

main.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,29 @@ resource "castai_workload_scaling_policy" "this" {
367367
depends_on = [helm_release.castai_workload_autoscaler]
368368
}
369369

370+
resource "castai_workload_custom_metrics_data_source" "this" {
371+
for_each = { for k, v in var.workload_custom_metrics_data_sources : k => v }
372+
373+
cluster_id = castai_eks_cluster.my_castai_cluster.id
374+
name = try(each.value.name, each.key)
375+
376+
prometheus {
377+
url = each.value.prometheus.url
378+
timeout = try(each.value.prometheus.timeout, null)
379+
presets = try(each.value.prometheus.presets, null)
380+
381+
dynamic "metric" {
382+
for_each = try(each.value.prometheus.metrics, [])
383+
content {
384+
name = metric.value.name
385+
query = metric.value.query
386+
}
387+
}
388+
}
389+
390+
depends_on = [helm_release.castai_workload_autoscaler]
391+
}
392+
370393
resource "helm_release" "castai_agent" {
371394
name = "castai-agent"
372395
repository = "https://castai.github.io/helm-charts"

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ variable "workload_scaling_policies" {
126126
default = {}
127127
}
128128

129+
variable "workload_custom_metrics_data_sources" {
130+
type = any
131+
description = "Map of workload custom metrics data sources to create"
132+
default = {}
133+
}
134+
129135
variable "install_security_agent" {
130136
type = bool
131137
default = false

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ terraform {
88
}
99
castai = {
1010
source = "castai/castai"
11-
version = ">= 8.24.0"
11+
version = ">= 8.26.0"
1212
}
1313
helm = {
1414
source = "hashicorp/helm"

0 commit comments

Comments
 (0)