Skip to content

Commit 51e1325

Browse files
authored
feat: added support for LogDNA metadata filtering (#226)
1 parent f0873fa commit 51e1325

File tree

7 files changed

+85
-7
lines changed

7 files changed

+85
-7
lines changed

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/)
99
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
1010

11-
This module supports deploying the following observability agents to the provided OCP cluster:
11+
This module deploys the following observability agents to a Red Hat OpenShift Container Platform cluster:
12+
13+
- Logging agent
14+
- Monitoring agent
1215

13-
* Logging (LogDNA) agent
14-
* Monitoring (SysDig) agent
1516

1617
## Usage
1718

@@ -70,6 +71,28 @@ module "observability_agents" {
7071
}
7172
```
7273

74+
## Configuration for Kubernetes metadata filtering in the logging agent
75+
76+
You can configure the logging agent to filter log lines according to the Kubernetes resources metadata by setting the exclusion and inclusion parameters.
77+
78+
For example, to set the agent to return all log lines coming from the `default` Kubernetes namespace and exclude anything with a label `app.kubernetes.io/name` with value `sample-app` or an annotation `annotation.user` with value `sample-user`, include these parameters:
79+
80+
```text
81+
custom_logdna_at_agent_line_exclusion = "label.app.kubernetes.io/name:sample-app\\, annotation.user:sample-user"
82+
custom_logdna_at_agent_line_inclusion = "namespace:default"
83+
```
84+
85+
The following is the corresponding DaemonSet configuration:
86+
87+
```text
88+
- name: LOGDNA_K8S_METADATA_LINE_INCLUSION
89+
value: "label.app.kubernetes.io/name:sample-app, annotation.user:sample-user"
90+
- name: LOGDNA_K8S_METADATA_LINE_EXCLUSION
91+
value: "namespace:default"
92+
```
93+
94+
For more information, see [Configuration for Kubernetes Metadata Filtering](https://github.com/logdna/logdna-agent-v2/blob/3.8/docs/KUBERNETES.md#configuration-for-kubernetes-metadata-filtering).
95+
7396
## Required IAM access policies
7497
You need the following permissions to run this module.
7598

@@ -125,6 +148,8 @@ No modules.
125148
| <a name="input_cluster_id"></a> [cluster\_id](#input\_cluster\_id) | Cluster id to add to agents to | `string` | n/a | yes |
126149
| <a name="input_cluster_resource_group_id"></a> [cluster\_resource\_group\_id](#input\_cluster\_resource\_group\_id) | Resource group of the cluster | `string` | n/a | yes |
127150
| <a name="input_logdna_add_cluster_name"></a> [logdna\_add\_cluster\_name](#input\_logdna\_add\_cluster\_name) | If true, configure the logdna agent to attach a tag containing the cluster name to all log messages. | `bool` | `true` | no |
151+
| <a name="input_logdna_agent_custom_line_exclusion"></a> [logdna\_agent\_custom\_line\_exclusion](#input\_logdna\_agent\_custom\_line\_exclusion) | LogDNA agent custom configuration for line exclusion setting LOGDNA\_K8S\_METADATA\_LINE\_EXCLUSION. | `string` | `null` | no |
152+
| <a name="input_logdna_agent_custom_line_inclusion"></a> [logdna\_agent\_custom\_line\_inclusion](#input\_logdna\_agent\_custom\_line\_inclusion) | LogDNA agent custom configuration for line inclusion setting LOGDNA\_K8S\_METADATA\_LINE\_INCLUSION. | `string` | `null` | no |
128153
| <a name="input_logdna_agent_tags"></a> [logdna\_agent\_tags](#input\_logdna\_agent\_tags) | array of tags to group the host logs pushed by the logdna agent | `list(string)` | `[]` | no |
129154
| <a name="input_logdna_agent_version"></a> [logdna\_agent\_version](#input\_logdna\_agent\_version) | Version of the agent to deploy. To lookup version run: `ibmcloud cr images --restrict ext/logdna-agent`. If null, the default value is used. | `string` | `"3.8.9-20231113.3d09f4dc47c1f590"` | no |
130155
| <a name="input_logdna_enabled"></a> [logdna\_enabled](#input\_logdna\_enabled) | Deploy IBM Cloud Logging agent | `bool` | `true` | no |

chart/logdna-agent/templates/daemonset.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ spec:
7777
fieldPath: spec.nodeName
7878
- name: NAMESPACE
7979
value: {{ .Release.Namespace }}
80+
{{- if .Values.agentMetadataLineInclusion }}
81+
- name: LOGDNA_K8S_METADATA_LINE_INCLUSION
82+
value: {{ .Values.agentMetadataLineInclusion | quote }}
83+
{{- end }}
84+
{{- if .Values.agentMetadataLineExclusion }}
85+
- name: LOGDNA_K8S_METADATA_LINE_EXCLUSION
86+
value: {{ .Values.agentMetadataLineExclusion | quote }}
87+
{{- end }}
8088
resources:
8189
requests:
8290
cpu: 20m

examples/basic/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# Deploy basic observability agents
22

3-
An end to end example using the module's default variable values.
3+
An end-to-end example that uses the module's default variable values.
4+
5+
The example sets up the logging agent for [Kubernetes metadata filtering](https://github.com/logdna/logdna-agent-v2/blob/3.8/docs/KUBERNETES.md#configuration-for-kubernetes-metadata-filtering).
6+
7+
The example configures the agent to include all log lines coming from the `default` Kubernetes namespace and excludes anything with a label `app.kubernetes.io/name` and value `sample-app` or an annotation `annotation.user` with the value `sample-user`.

examples/basic/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,9 @@ module "observability_agents" {
115115
# 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
116116
sysdig_metrics_filter = [{ type = "exclude", name = "metricA.*" }, { type = "include", name = "metricB.*" }]
117117
sysdig_agent_tags = var.resource_tags
118+
# LogDNA agent custom settings to setup Kubernetes metadata logs filtering by setting
119+
# LOGDNA_K8S_METADATA_LINE_INCLUSION and LOGDNA_K8S_METADATA_LINE_EXCLUSION in the agent daemonset definition
120+
# Ref https://github.com/logdna/logdna-agent-v2/blob/3.8/docs/KUBERNETES.md#configuration-for-kubernetes-metadata-filtering
121+
logdna_agent_custom_line_exclusion = "label.app.kubernetes.io/name:sample-app\\, annotation.user:sample-user"
122+
logdna_agent_custom_line_inclusion = "namespace:default"
118123
}

main.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ resource "helm_release" "logdna_agent" {
109109
value = join("\\,", local.logdna_agent_tags)
110110
}
111111

112+
dynamic "set" {
113+
for_each = var.logdna_agent_custom_line_inclusion != null ? [var.logdna_agent_custom_line_inclusion] : []
114+
content {
115+
name = "agentMetadataLineInclusion"
116+
type = "string"
117+
value = set.value
118+
}
119+
}
120+
121+
dynamic "set" {
122+
for_each = var.logdna_agent_custom_line_exclusion != null ? [var.logdna_agent_custom_line_exclusion] : []
123+
content {
124+
name = "agentMetadataLineExclusion"
125+
type = "string"
126+
value = set.value
127+
}
128+
}
129+
112130
provisioner "local-exec" {
113131
command = "${path.module}/scripts/confirm-rollout-status.sh logdna-agent ${local.logdna_agent_namespace}"
114132
interpreter = ["/bin/bash", "-c"]

tests/pr_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ var ignoreUpdates = []string{
1919
"module.observability_agents.helm_release.logdna_agent_activity_tracker[0]",
2020
}
2121

22+
var extTerraformVars = map[string]interface{}{}
23+
2224
var sharedInfoSvc *cloudinfo.CloudInfoService
2325

2426
// TestMain will be run before any parallel tests, used to set up a shared InfoService object to track region usage
@@ -29,7 +31,7 @@ func TestMain(m *testing.M) {
2931
os.Exit(m.Run())
3032
}
3133

32-
func setupOptions(t *testing.T, prefix string, terraformDir string) *testhelper.TestOptions {
34+
func setupOptions(t *testing.T, prefix string, terraformDir string, terraformVars map[string]interface{}) *testhelper.TestOptions {
3335
options := testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{
3436
Testing: t,
3537
TerraformDir: terraformDir,
@@ -40,6 +42,7 @@ func setupOptions(t *testing.T, prefix string, terraformDir string) *testhelper.
4042
},
4143
CloudInfoService: sharedInfoSvc,
4244
ExcludeActivityTrackerRegions: true,
45+
TerraformVars: terraformVars,
4346
})
4447

4548
return options
@@ -48,7 +51,7 @@ func setupOptions(t *testing.T, prefix string, terraformDir string) *testhelper.
4851
func TestRunBasicAgents(t *testing.T) {
4952
t.Parallel()
5053

51-
options := setupOptions(t, "basic-obs-agents", terraformDirOther)
54+
options := setupOptions(t, "basic-obs-agents", terraformDirOther, extTerraformVars)
5255

5356
output, err := options.RunTestConsistency()
5457
assert.Nil(t, err, "This should not have errored")
@@ -58,7 +61,7 @@ func TestRunBasicAgents(t *testing.T) {
5861
func TestRunUpgrade(t *testing.T) {
5962
t.Parallel()
6063

61-
options := setupOptions(t, "observ-agents-upg", terraformDirOther)
64+
options := setupOptions(t, "observ-agents-upg", terraformDirOther, extTerraformVars)
6265

6366
output, err := options.RunTestUpgrade()
6467
if !options.UpgradeTestSkipped {

variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ variable "logdna_add_cluster_name" {
5959
default = true
6060
}
6161

62+
# LogDNA agent custom settings to setup Kubernetes metadata logs filtering
63+
# Ref https://github.com/logdna/logdna-agent-v2/blob/3.8/docs/KUBERNETES.md#configuration-for-kubernetes-metadata-filtering
64+
65+
variable "logdna_agent_custom_line_inclusion" {
66+
description = "LogDNA agent custom configuration for line inclusion setting LOGDNA_K8S_METADATA_LINE_INCLUSION."
67+
type = string
68+
default = null
69+
}
70+
71+
variable "logdna_agent_custom_line_exclusion" {
72+
description = "LogDNA agent custom configuration for line exclusion setting LOGDNA_K8S_METADATA_LINE_EXCLUSION."
73+
type = string
74+
default = null
75+
}
76+
6277
variable "sysdig_enabled" {
6378
type = bool
6479
description = "Deploy IBM Cloud Monitoring agent"

0 commit comments

Comments
 (0)