@@ -414,3 +414,109 @@ func TestClusterOutputList_Load_As_Yaml(t *testing.T) {
414414 i ++
415415 }
416416}
417+
418+ func TestLokiOutputWithStructuredMetadata_Load (t * testing.T ) {
419+ g := NewGomegaWithT (t )
420+ sl := plugins .NewSecretLoader (nil , "testnamespace" )
421+
422+ lokiOutput := ClusterOutput {
423+ TypeMeta : metav1.TypeMeta {
424+ APIVersion : "fluentbit.fluent.io/v1alpha2" ,
425+ Kind : "ClusterOutput" ,
426+ },
427+ ObjectMeta : metav1.ObjectMeta {
428+ Name : "loki_output_with_metadata" ,
429+ },
430+ Spec : OutputSpec {
431+ Match : "kube.*" ,
432+ Loki : & output.Loki {
433+ Host : "loki-gateway" ,
434+ Port : ptrInt32 (int32 (3100 )),
435+ Labels : []string {
436+ "job=fluentbit" ,
437+ "environment=production" ,
438+ },
439+ StructuredMetadata : map [string ]string {
440+ "pod" : "${record['kubernetes']['pod_name']}" ,
441+ "container" : "${record['kubernetes']['container_name']}" ,
442+ "trace_id" : "${record['trace_id']}" ,
443+ },
444+ StructuredMetadataKeys : []string {
445+ "level" ,
446+ "caller" ,
447+ },
448+ },
449+ },
450+ }
451+
452+ outputs := ClusterOutputList {
453+ Items : []ClusterOutput {lokiOutput },
454+ }
455+
456+ expected := `[Output]
457+ Name loki
458+ Match kube.*
459+ host loki-gateway
460+ port 3100
461+ labels environment=production,job=fluentbit
462+ structured_metadata container=${record['kubernetes']['container_name']},pod=${record['kubernetes']['pod_name']},trace_id=${record['trace_id']}
463+ structured_metadata_keys level,caller
464+ `
465+
466+ result , err := outputs .Load (sl )
467+ g .Expect (err ).NotTo (HaveOccurred ())
468+ g .Expect (result ).To (Equal (expected ))
469+ }
470+
471+ func TestLokiOutputWithStructuredMetadata_LoadAsYaml (t * testing.T ) {
472+ g := NewGomegaWithT (t )
473+ sl := plugins .NewSecretLoader (nil , "testnamespace" )
474+
475+ lokiOutput := ClusterOutput {
476+ TypeMeta : metav1.TypeMeta {
477+ APIVersion : "fluentbit.fluent.io/v1alpha2" ,
478+ Kind : "ClusterOutput" ,
479+ },
480+ ObjectMeta : metav1.ObjectMeta {
481+ Name : "loki_output_with_metadata" ,
482+ },
483+ Spec : OutputSpec {
484+ Match : "kube.*" ,
485+ Loki : & output.Loki {
486+ Host : "loki-gateway" ,
487+ Port : ptrInt32 (int32 (3100 )),
488+ Labels : []string {
489+ "job=fluentbit" ,
490+ "environment=production" ,
491+ },
492+ StructuredMetadata : map [string ]string {
493+ "pod" : "${record['kubernetes']['pod_name']}" ,
494+ "container" : "${record['kubernetes']['container_name']}" ,
495+ "trace_id" : "${record['trace_id']}" ,
496+ },
497+ StructuredMetadataKeys : []string {
498+ "level" ,
499+ "caller" ,
500+ },
501+ },
502+ },
503+ }
504+
505+ outputs := ClusterOutputList {
506+ Items : []ClusterOutput {lokiOutput },
507+ }
508+
509+ expected := `outputs:
510+ - name: loki
511+ match: "kube.*"
512+ host: loki-gateway
513+ port: 3100
514+ labels: environment=production,job=fluentbit
515+ structured_metadata: container=${record['kubernetes']['container_name']},pod=${record['kubernetes']['pod_name']},trace_id=${record['trace_id']}
516+ structured_metadata_keys: level,caller
517+ `
518+
519+ result , err := outputs .LoadAsYaml (sl , 0 )
520+ g .Expect (err ).NotTo (HaveOccurred ())
521+ g .Expect (result ).To (Equal (expected ))
522+ }
0 commit comments