Skip to content

Commit 1098977

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 af7c286 commit 1098977

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,23 @@ module "castai-eks-cluster" {
234234
excluded_containers = ["container-1", "container-2"]
235235
}
236236
}
237+
238+
workload_custom_metrics_data_sources = {
239+
my-prometheus = {
240+
prometheus = {
241+
url = "http://prometheus-server.monitoring.svc.cluster.local:9090"
242+
timeout = "30s"
243+
presets = ["jvm"]
244+
245+
metrics = [
246+
{
247+
name = "http_requests_total"
248+
query = "sum(rate(http_requests_total[5m])) by (pod)"
249+
}
250+
]
251+
}
252+
}
253+
}
237254
}
238255
```
239256

@@ -916,6 +933,7 @@ terraform-docs markdown table . --output-file README.md
916933
| [castai_node_configuration.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/node_configuration) | resource |
917934
| [castai_node_configuration_default.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/node_configuration_default) | resource |
918935
| [castai_node_template.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/node_template) | resource |
936+
| [castai_workload_custom_metrics_data_source.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/workload_custom_metrics_data_source) | resource |
919937
| [castai_workload_scaling_policy.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/workload_scaling_policy) | resource |
920938
| [helm_release.castai_agent](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
921939
| [helm_release.castai_ai_optimizer_proxy](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
@@ -1008,6 +1026,7 @@ terraform-docs markdown table . --output-file README.md
10081026
| <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 |
10091027
| <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 |
10101028
| <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 |
1029+
| <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 |
10111030
| <a name="input_workload_scaling_policies"></a> [workload\_scaling\_policies](#input\_workload\_scaling\_policies) | Map of workload scaling policies to create | `any` | `{}` | no |
10121031

10131032
## Outputs

main.tf

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

383+
resource "castai_workload_custom_metrics_data_source" "this" {
384+
for_each = { for k, v in var.workload_custom_metrics_data_sources : k => v }
385+
386+
cluster_id = castai_eks_cluster.my_castai_cluster.id
387+
name = try(each.value.name, each.key)
388+
389+
prometheus {
390+
url = each.value.prometheus.url
391+
timeout = try(each.value.prometheus.timeout, null)
392+
presets = try(each.value.prometheus.presets, null)
393+
394+
dynamic "metric" {
395+
for_each = try(each.value.prometheus.metrics, [])
396+
content {
397+
name = metric.value.name
398+
query = metric.value.query
399+
}
400+
}
401+
}
402+
403+
depends_on = [helm_release.castai_workload_autoscaler]
404+
}
405+
383406
resource "helm_release" "castai_agent" {
384407
count = var.install_helm_apps ? 1 : 0
385408

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

0 commit comments

Comments
 (0)