Skip to content

Commit 25a66c4

Browse files
feat: add castai_workload_custom_metrics_data_source resource
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 07883f9 commit 25a66c4

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
@@ -199,6 +199,23 @@ module "castai-aks-cluster" {
199199
excluded_containers = ["container-1", "container-2"]
200200
}
201201
}
202+
203+
workload_custom_metrics_data_sources = {
204+
my-prometheus = {
205+
prometheus = {
206+
url = "http://prometheus-server.monitoring.svc.cluster.local:9090"
207+
timeout = "30s"
208+
presets = ["jvm"]
209+
210+
metrics = [
211+
{
212+
name = "http_requests_total"
213+
query = "sum(rate(http_requests_total[5m])) by (pod)"
214+
}
215+
]
216+
}
217+
}
218+
}
202219
}
203220
```
204221

@@ -487,6 +504,7 @@ Usage examples are located in [terraform provider repo](https://github.com/casta
487504
| [castai_node_configuration.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/node_configuration) | resource |
488505
| [castai_node_configuration_default.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/node_configuration_default) | resource |
489506
| [castai_node_template.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/node_template) | resource |
507+
| [castai_workload_custom_metrics_data_source.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/workload_custom_metrics_data_source) | resource |
490508
| [castai_workload_scaling_policy.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/workload_scaling_policy) | resource |
491509
| [helm_release.castai_agent](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
492510
| [helm_release.castai_ai_optimizer_proxy](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
@@ -578,6 +596,7 @@ Usage examples are located in [terraform provider repo](https://github.com/casta
578596
| <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 |
579597
| <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 |
580598
| <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 |
599+
| <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 |
581600
| <a name="input_workload_scaling_policies"></a> [workload\_scaling\_policies](#input\_workload\_scaling\_policies) | Map of workload scaling policies to create | `any` | `{}` | no |
582601

583602
## Outputs

main.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,29 @@ resource "castai_workload_scaling_policy" "this" {
402402
}
403403
}
404404

405+
resource "castai_workload_custom_metrics_data_source" "this" {
406+
for_each = { for k, v in var.workload_custom_metrics_data_sources : k => v }
407+
408+
cluster_id = castai_aks_cluster.castai_cluster.id
409+
name = try(each.value.name, each.key)
410+
411+
prometheus {
412+
url = each.value.prometheus.url
413+
timeout = try(each.value.prometheus.timeout, null)
414+
presets = try(each.value.prometheus.presets, null)
415+
416+
dynamic "metric" {
417+
for_each = try(each.value.prometheus.metrics, [])
418+
content {
419+
name = metric.value.name
420+
query = metric.value.query
421+
}
422+
}
423+
}
424+
425+
depends_on = [helm_release.castai_workload_autoscaler]
426+
}
427+
405428
resource "helm_release" "castai_agent" {
406429
name = "castai-agent"
407430
repository = "https://castai.github.io/helm-charts"

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ variable "workload_scaling_policies" {
137137
default = {}
138138
}
139139

140+
variable "workload_custom_metrics_data_sources" {
141+
type = any
142+
description = "Map of workload custom metrics data sources to create"
143+
default = {}
144+
}
145+
140146
variable "install_security_agent" {
141147
type = bool
142148
default = false

0 commit comments

Comments
 (0)