Skip to content

Commit fb04b92

Browse files
authored
feat: added container filtering for cloud monitoring agents using new variable cloud_monitoring_container_filter (#419)
1 parent e94a156 commit fb04b92

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ You need the following permissions to run this module.
125125
| <a name="input_cloud_monitoring_agent_namespace"></a> [cloud\_monitoring\_agent\_namespace](#input\_cloud\_monitoring\_agent\_namespace) | Namespace where to deploy the Cloud Monitoring agent. Default value is 'ibm-observe' | `string` | `"ibm-observe"` | no |
126126
| <a name="input_cloud_monitoring_agent_tags"></a> [cloud\_monitoring\_agent\_tags](#input\_cloud\_monitoring\_agent\_tags) | List of tags to associate to all matrics that the agent collects. NOTE: Use the 'cloud\_monitoring\_add\_cluster\_name' variable to add the cluster name as a tag. | `list(string)` | `[]` | no |
127127
| <a name="input_cloud_monitoring_agent_tolerations"></a> [cloud\_monitoring\_agent\_tolerations](#input\_cloud\_monitoring\_agent\_tolerations) | List of tolerations to apply to Cloud Monitoring 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 |
128+
| <a name="input_cloud_monitoring_container_filter"></a> [cloud\_monitoring\_container\_filter](#input\_cloud\_monitoring\_container\_filter) | To filter custom containers, specify the Cloud Monitoring containers to include or to exclude. See https://cloud.ibm.com/docs/monitoring?topic=monitoring-change_kube_agent#change_kube_agent_filter_data. | <pre>list(object({<br/> type = string<br/> parameter = string<br/> name = string<br/> }))</pre> | `[]` | no |
128129
| <a name="input_cloud_monitoring_enabled"></a> [cloud\_monitoring\_enabled](#input\_cloud\_monitoring\_enabled) | Deploy IBM Cloud Monitoring agent | `bool` | `true` | no |
129130
| <a name="input_cloud_monitoring_endpoint_type"></a> [cloud\_monitoring\_endpoint\_type](#input\_cloud\_monitoring\_endpoint\_type) | Specify the IBM Cloud Monitoring instance endpoint type (public or private) to use. Used to construct the ingestion endpoint. | `string` | `"private"` | no |
130131
| <a name="input_cloud_monitoring_instance_region"></a> [cloud\_monitoring\_instance\_region](#input\_cloud\_monitoring\_instance\_region) | The IBM Cloud Monitoring instance region. Used to construct the ingestion endpoint. | `string` | `null` | no |

chart/sysdig-agent/templates/configmap.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,15 @@ data:
4141
- {{ $v.type }}: {{ $v.name }}
4242
{{ end }}
4343
{{- end -}}
44+
45+
{{ if .Values.container_filter -}}
46+
# Enable the feature
47+
use_container_filter: true
48+
49+
# Include or exclude conditions
50+
container_filter:
51+
{{ range $c := .Values.container_filter -}}
52+
- {{ $c.type }}:
53+
{{ $c.parameter }}: {{ $c.name }}
54+
{{ end }}
55+
{{- end -}}

chart/sysdig-agent/values.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,13 @@ metrics_filter: []
2222
psp:
2323
# true here enables creation of Pod Security Policy to allow the agent run with the required permissions
2424
create: true
25+
26+
container_filter: []
27+
# example:
28+
# container_filter:
29+
# - include:
30+
# container.image: appdomain/my-app-image
31+
# - include:
32+
# container.name: my-java-app
33+
# - exclude:
34+
# kubernetes.namespace.name: kube-system

examples/obs-agent-ocp/main.tf

+4-3
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ module "observability_agents" {
197197
# Monitoring agent
198198
cloud_monitoring_access_key = module.observability_instances.cloud_monitoring_access_key
199199
# example of how to include / exclude metrics - more info https://cloud.ibm.com/docs/monitoring?topic=monitoring-change_kube_agent#change_kube_agent_log_metrics
200-
cloud_monitoring_metrics_filter = [{ type = "exclude", name = "metricA.*" }, { type = "include", name = "metricB.*" }]
201-
cloud_monitoring_agent_tags = var.resource_tags
202-
cloud_monitoring_instance_region = module.observability_instances.region
200+
cloud_monitoring_metrics_filter = [{ type = "exclude", name = "metricA.*" }, { type = "include", name = "metricB.*" }]
201+
cloud_monitoring_container_filter = [{ type = "exclude", parameter = "kubernetes.namespace.name", name = "kube-system" }]
202+
cloud_monitoring_agent_tags = var.resource_tags
203+
cloud_monitoring_instance_region = module.observability_instances.region
203204
}

main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ resource "helm_release" "cloud_monitoring_agent" {
106106
metrics_filter = var.cloud_monitoring_metrics_filter
107107
}), yamlencode({
108108
tolerations = var.cloud_monitoring_agent_tolerations
109+
}), yamlencode({
110+
container_filter = var.cloud_monitoring_container_filter
109111
})]
110112

111113
provisioner "local-exec" {

variables.tf

+14
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ variable "cloud_monitoring_metrics_filter" {
8282
}
8383
}
8484

85+
variable "cloud_monitoring_container_filter" {
86+
type = list(object({
87+
type = string
88+
parameter = string
89+
name = string
90+
}))
91+
description = "To filter custom containers, specify the Cloud Monitoring containers to include or to exclude. See https://cloud.ibm.com/docs/monitoring?topic=monitoring-change_kube_agent#change_kube_agent_filter_data."
92+
default = []
93+
validation {
94+
condition = length(var.cloud_monitoring_container_filter) == 0 || can(regex("^(include|exclude)$", var.cloud_monitoring_container_filter[0].type))
95+
error_message = "Invalid input for `cloud_monitoring_container_filter`. Valid options for 'type' are: `include` and `exclude`. If empty, no containers are included or excluded."
96+
}
97+
}
98+
8599
variable "cloud_monitoring_agent_tags" {
86100
type = list(string)
87101
description = "List of tags to associate to all matrics that the agent collects. NOTE: Use the 'cloud_monitoring_add_cluster_name' variable to add the cluster name as a tag."

0 commit comments

Comments
 (0)