Skip to content

Commit 215d598

Browse files
authored
feat: added support for prometheus metrics scraping (#167)
1 parent 31fb38c commit 215d598

File tree

7 files changed

+96
-5
lines changed

7 files changed

+96
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ No modules.
135135
| <a name="input_deployment_tag"></a> [deployment\_tag](#input\_deployment\_tag) | Sets a global tag that will be included in the components. It represents the mechanism from where the components have been installed (terraform, local...). | `string` | `"terraform"` | no |
136136
| <a name="input_enable_host_scanner"></a> [enable\_host\_scanner](#input\_enable\_host\_scanner) | Enable host scanning to detect vulnerabilities and identify the resolution priority based on available fixed versions and severity. Requires a Security and Compliance Center Workload Protection instance to view results. | `bool` | `true` | no |
137137
| <a name="input_enable_kspm_analyzer"></a> [enable\_kspm\_analyzer](#input\_enable\_kspm\_analyzer) | Enable Kubernetes Security Posture Management (KSPM) analyzer. Requires a Security and Compliance Center Workload Protection instance to view results. | `bool` | `true` | no |
138-
| <a name="input_enable_universal_ebpf"></a> [enable\_universal\_ebpf](#input\_enable\_universal\_ebpf) | Deploy monitoring agent with universal extended Berkeley Packet Filter (eBPF) enabled. It requires kernel version 5.8+. Learn more: https://github.com/terraform-ibm-modules/terraform-ibm-monitoring-agent/blob/main/solutions/fully-configurable/DA-docs.md#when-to-enable-enable_universal_ebpf | `bool` | `true` | no |
138+
| <a name="input_enable_universal_ebpf"></a> [enable\_universal\_ebpf](#input\_enable\_universal\_ebpf) | Deploy monitoring agent with universal extended Berkeley Packet Filter (eBPF) enabled. It requires kernel version 5.8+. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-monitoring-agent/blob/main/solutions/fully-configurable/DA-docs.md#when-to-enable-enable_universal_ebpf) | `bool` | `true` | no |
139139
| <a name="input_existing_access_key_secret_name"></a> [existing\_access\_key\_secret\_name](#input\_existing\_access\_key\_secret\_name) | An alternative to using `access_key`. Specify the name of an existing Kubernetes secret containing the access key in the same namespace that is defined in the `namespace` input. Either `access_key` or `existing_access_key_secret_name` is required. | `string` | `null` | no |
140140
| <a name="input_image_registry_base_url"></a> [image\_registry\_base\_url](#input\_image\_registry\_base\_url) | The image registry base URL to pull all images from. For example `icr.io` or `quay.io`. | `string` | `"icr.io"` | no |
141141
| <a name="input_image_registry_namespace"></a> [image\_registry\_namespace](#input\_image\_registry\_namespace) | The namespace within the image registry to pull all images from. | `string` | `"ext/sysdig"` | no |
@@ -146,6 +146,7 @@ No modules.
146146
| <a name="input_metrics_filter"></a> [metrics\_filter](#input\_metrics\_filter) | To filter custom metrics you can specify which metrics to include and exclude. For more info, see https://cloud.ibm.com/docs/monitoring?topic=monitoring-change_kube_agent#change_kube_agent_inc_exc_metrics | <pre>list(object({<br/> include = optional(string)<br/> exclude = optional(string)<br/> }))</pre> | `[]` | no |
147147
| <a name="input_name"></a> [name](#input\_name) | The name to give the agent helm release. | `string` | `"sysdig-agent"` | no |
148148
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Namespace to deploy the agent to. | `string` | `"ibm-observe"` | no |
149+
| <a name="input_prometheus_config"></a> [prometheus\_config](#input\_prometheus\_config) | Prometheus configuration for the agent. If you want to enable Prometheus configuration provide the prometheus.yaml file content in `hcl` format. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-monitoring-agent/blob/main/solutions/fully-configurable/DA-types.md#prometheus_config). | `map(any)` | `{}` | no |
149150
| <a name="input_tolerations"></a> [tolerations](#input\_tolerations) | List of tolerations to apply to the agent. | <pre>list(object({<br/> key = optional(string)<br/> operator = optional(string)<br/> value = optional(string)<br/> effect = optional(string)<br/> tolerationSeconds = optional(number)<br/> }))</pre> | <pre>[<br/> {<br/> "operator": "Exists"<br/> },<br/> {<br/> "effect": "NoSchedule",<br/> "key": "node-role.kubernetes.io/master",<br/> "operator": "Exists"<br/> }<br/>]</pre> | no |
150151
| <a name="input_use_private_endpoint"></a> [use\_private\_endpoint](#input\_use\_private\_endpoint) | Whether send data over a private endpoint or not. To use a private endpoint, you must enable virtual routing and forwarding (VRF) for your account. See https://cloud.ibm.com/docs/account?topic=account-vrf-service-endpoint. | `bool` | `true` | no |
151152
| <a name="input_use_scc_wp_endpoint"></a> [use\_scc\_wp\_endpoint](#input\_use\_scc\_wp\_endpoint) | By default an IBM Cloud Monitoring endpoint is used and is constructed from the `instance_region` and `use_private_endpoint` inputs. To use an IBM Cloud Security and Compliance Center Workload Protection endpoint instead, set this to true. | `bool` | `false` | no |

examples/obs-agent-iks/main.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,36 @@ module "monitoring_agents" {
145145
is_vpc_cluster = var.is_vpc_cluster
146146
access_key = module.cloud_monitoring.access_key
147147
instance_region = var.region
148+
prometheus_config = {
149+
scrape_configs = [
150+
{
151+
job_name = "testing-prometheus-scrape"
152+
tls_config = {
153+
insecure_skip_verify = true
154+
}
155+
kubernetes_sd_configs = [
156+
{
157+
role = "pod"
158+
}
159+
]
160+
relabel_configs = [
161+
{
162+
action = "keep"
163+
source_labels = ["__meta_kubernetes_pod_host_ip"]
164+
regex = "__HOSTIPS__"
165+
},
166+
{
167+
action = "drop"
168+
source_labels = ["__meta_kubernetes_pod_annotation_promcat_sysdig_com_omit"]
169+
regex = "true"
170+
},
171+
{
172+
source_labels = ["__meta_kubernetes_pod_phase"]
173+
action = "keep"
174+
regex = "Running"
175+
}
176+
]
177+
}
178+
]
179+
}
148180
}

main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ resource "helm_release" "cloud_monitoring_agent" {
253253
"path": "/tmp"
254254
"name": "tmp-vol"
255255
%{endif~}
256+
"prometheus":
257+
"file": ${length(var.prometheus_config) > 0}
258+
"yaml":
259+
%{for line in split("\n", yamlencode(var.prometheus_config))~}
260+
${line}
261+
%{endfor~}
256262
EOT
257263
]
258264

solutions/fully-configurable/DA-types.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,50 @@ type = list(object({
4747

4848
**Tip:**
4949
Use `metrics_filter` to optimize your monitoring setup by collecting only the metrics that matter most to your use case. This can help reduce costs and improve performance.
50+
51+
## `prometheus_config`
52+
53+
The `prometheus_config` variable allows you to enable sysdig agent to scrape metrics from processes that expose Prometheus metric endpoints on its own host and send findings to the Sysdig collector for storing and further processing.
54+
55+
### Type
56+
57+
```hcl
58+
map(any)
59+
```
60+
61+
### Example Usage
62+
63+
```hcl
64+
{
65+
scrape_configs = [
66+
{
67+
job_name = "testing-prometheus-scrape"
68+
tls_config = {
69+
insecure_skip_verify = true
70+
}
71+
kubernetes_sd_configs = [
72+
{
73+
role = "pod"
74+
}
75+
]
76+
relabel_configs = [
77+
{
78+
action = "keep"
79+
source_labels = ["__meta_kubernetes_pod_host_ip"]
80+
regex = "__HOSTIPS__"
81+
},
82+
{
83+
action = "drop"
84+
source_labels = ["__meta_kubernetes_pod_annotation_promcat_sysdig_com_omit"]
85+
regex = "true"
86+
},
87+
{
88+
source_labels = ["__meta_kubernetes_pod_phase"]
89+
action = "keep"
90+
regex = "Running"
91+
}
92+
]
93+
}
94+
]
95+
}
96+
```

solutions/fully-configurable/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ variable "agent_limits_memory" {
235235

236236
variable "enable_universal_ebpf" {
237237
type = bool
238-
description = "Deploy monitoring agent with universal extended Berkeley Packet Filter (eBPF) enabled. It requires kernel version 5.8+. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-monitoring-agent/blob/main/solutions/fully-configurable/DA-docs.md#when-to-enable-enable_universal_ebpf)"
238+
description = "Deploy monitoring agent with universal extended Berkeley Packet Filter (eBPF) enabled. It requires kernel version 5.8+. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-monitoring-agent/blob/main/solutions/fully-configurable/DA-docs.md#when-to-enable-enable_universal_ebpf)."
239239
default = true
240240
}
241241

tests/pr_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ func TestFullyConfigurableSolution(t *testing.T) {
112112
WaitJobCompleteMinutes: 60,
113113
Region: region,
114114
})
115-
116115
options.TerraformVars = []testschematic.TestSchematicTerraformVar{
117116
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
118117
{Name: "instance_region", Value: region, DataType: "string"},
@@ -239,7 +238,6 @@ func TestRunAgentVpcKubernetes(t *testing.T) {
239238
},
240239
CloudInfoService: sharedInfoSvc,
241240
})
242-
243241
output, err := options.RunTestConsistency()
244242
assert.Nil(t, err, "This should not have errored")
245243
assert.NotNil(t, output, "Expected some output")

variables.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ variable "agent_limits_memory" {
236236

237237
variable "enable_universal_ebpf" {
238238
type = bool
239-
description = "Deploy monitoring agent with universal extended Berkeley Packet Filter (eBPF) enabled. It requires kernel version 5.8+. Learn more: https://github.com/terraform-ibm-modules/terraform-ibm-monitoring-agent/blob/main/solutions/fully-configurable/DA-docs.md#when-to-enable-enable_universal_ebpf"
239+
description = "Deploy monitoring agent with universal extended Berkeley Packet Filter (eBPF) enabled. It requires kernel version 5.8+. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-monitoring-agent/blob/main/solutions/fully-configurable/DA-docs.md#when-to-enable-enable_universal_ebpf)"
240240
default = true
241241
}
242242

@@ -290,6 +290,13 @@ variable "container_filter" {
290290
}
291291
}
292292

293+
variable "prometheus_config" {
294+
description = "Prometheus configuration for the agent. If you want to enable Prometheus configuration provide the prometheus.yaml file content in `hcl` format. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-monitoring-agent/blob/main/solutions/fully-configurable/DA-types.md#prometheus_config)."
295+
type = map(any)
296+
default = {}
297+
nullable = false
298+
}
299+
293300
##############################################################################
294301
# SCC-WP related variables
295302
##############################################################################

0 commit comments

Comments
 (0)