diff --git a/internal/controller/telemetry/otel_col_conf_test_fixtures/complex.yaml b/internal/controller/telemetry/otel_col_conf_test_fixtures/complex.yaml index cbb8d63..c7e6c8e 100644 --- a/internal/controller/telemetry/otel_col_conf_test_fixtures/complex.yaml +++ b/internal/controller/telemetry/otel_col_conf_test_fixtures/complex.yaml @@ -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: @@ -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: @@ -184,6 +184,7 @@ processors: key: tenant value: example-tenant-b deltatocumulative: {} + k8sattributes: auth_type: serviceAccount extract: diff --git a/internal/controller/telemetry/otel_conf_gen.go b/internal/controller/telemetry/otel_conf_gen.go index 2a6d30c..48cc75a 100644 --- a/internal/controller/telemetry/otel_conf_gen.go +++ b/internal/controller/telemetry/otel_conf_gen.go @@ -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{ @@ -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, @@ -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() diff --git a/internal/controller/telemetry/otel_conf_gen_test.go b/internal/controller/telemetry/otel_conf_gen_test.go index 232e0f6..54651e5 100644 --- a/internal/controller/telemetry/otel_conf_gen_test.go +++ b/internal/controller/telemetry/otel_conf_gen_test.go @@ -108,6 +108,11 @@ func TestOtelColConfComplex(t *testing.T) { }, }, }, + Status: v1alpha1.TenantStatus{ + LogSourceNamespaces: []string{ + "example-tenant-a", + }, + }, }, { ObjectMeta: metav1.ObjectMeta{ @@ -129,6 +134,11 @@ func TestOtelColConfComplex(t *testing.T) { }, }, }, + Status: v1alpha1.TenantStatus{ + LogSourceNamespaces: []string{ + "example-tenant-b", + }, + }, }, { ObjectMeta: metav1.ObjectMeta{