Skip to content

Commit

Permalink
feat(conf gen): only watch namespaces selected by tenant's logSourcen…
Browse files Browse the repository at this point in the history
…amespaceselector field

Signed-off-by: Szilard Parrag <szilard.parrag@axoflow.com>
  • Loading branch information
OverOrion committed May 2, 2024
1 parent f49c175 commit 953a31a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ receivers:
exclude:
- /var/log/pods/*/otc-container/*.log
include:
- /var/log/pods/*/*/*.log
- /var/log/pods/example-tenant-a_*/*/*.log
include_file_name: false
include_file_path: true
operators:
Expand Down Expand Up @@ -62,7 +62,7 @@ receivers:
exclude:
- /var/log/pods/*/otc-container/*.log
include:
- /var/log/pods/*/*/*.log
- /var/log/pods/example-tenant-b_*/*/*.log
include_file_name: false
include_file_path: true
operators:
Expand Down Expand Up @@ -184,6 +184,7 @@ processors:
key: tenant
value: example-tenant-b
deltatocumulative: {}

k8sattributes:
auth_type: serviceAccount
extract:
Expand Down
21 changes: 16 additions & 5 deletions internal/controller/telemetry/otel_conf_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ func (cfgInput *OtelColConfigInput) generateDefaultKubernetesProcessor() map[str
return k8sProcessor
}

func (cfgInput *OtelColConfigInput) generateDefaultKubernetesReceiver() map[string]any {
func (cfgInput *OtelColConfigInput) generateDefaultKubernetesReceiver(namespaces []string) map[string]any {

// TODO: fix parser-crio
operators := []map[string]any{
Expand Down Expand Up @@ -801,8 +801,14 @@ func (cfgInput *OtelColConfigInput) generateDefaultKubernetesReceiver() map[stri
},
}

includeList := make([]string, 0, len(namespaces))
for _, ns := range namespaces {
include := fmt.Sprintf("/var/log/pods/%s_*/*/*.log", ns)
includeList = append(includeList, include)
}

k8sReceiver := map[string]any{
"include": []string{"/var/log/pods/*/*/*.log"},
"include": includeList,
"exclude": []string{"/var/log/pods/*/otc-container/*.log"},
"start_at": "end",
"include_file_path": true,
Expand All @@ -828,9 +834,14 @@ func (cfgInput *OtelColConfigInput) ToIntermediateRepresentation(ctx context.Con
result.Processors = cfgInput.generateProcessors()

result.Receivers = make(map[string]any)
for tenant := range cfgInput.TenantSubscriptionMap {
k8sReceiverName := fmt.Sprintf("filelog/%s", tenant)
result.Receivers[k8sReceiverName] = cfgInput.generateDefaultKubernetesReceiver()
for tenantName := range cfgInput.TenantSubscriptionMap {
if tenantIdx := slices.IndexFunc(cfgInput.Tenants, func(t v1alpha1.Tenant) bool {
return tenantName == t.Name
}); tenantIdx != -1 {
k8sReceiverName := fmt.Sprintf("filelog/%s", tenantName)
namespaces := cfgInput.Tenants[tenantIdx].Status.LogSourceNamespaces
result.Receivers[k8sReceiverName] = cfgInput.generateDefaultKubernetesReceiver(namespaces)
}
}

result.Connectors = cfgInput.generateConnectors()
Expand Down
10 changes: 10 additions & 0 deletions internal/controller/telemetry/otel_conf_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func TestOtelColConfComplex(t *testing.T) {
},
},
},
Status: v1alpha1.TenantStatus{
LogSourceNamespaces: []string{
"example-tenant-a",
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -129,6 +134,11 @@ func TestOtelColConfComplex(t *testing.T) {
},
},
},
Status: v1alpha1.TenantStatus{
LogSourceNamespaces: []string{
"example-tenant-b",
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 953a31a

Please sign in to comment.