@@ -16,8 +16,6 @@ import (
1616 cel "github.com/envoyproxy/go-control-plane/envoy/extensions/access_loggers/filters/cel/v3"
1717 grpcaccesslog "github.com/envoyproxy/go-control-plane/envoy/extensions/access_loggers/grpc/v3"
1818 otelaccesslog "github.com/envoyproxy/go-control-plane/envoy/extensions/access_loggers/open_telemetry/v3"
19- celformatter "github.com/envoyproxy/go-control-plane/envoy/extensions/formatter/cel/v3"
20- metadataformatter "github.com/envoyproxy/go-control-plane/envoy/extensions/formatter/metadata/v3"
2119 reqwithoutqueryformatter "github.com/envoyproxy/go-control-plane/envoy/extensions/formatter/req_without_query/v3"
2220 "github.com/envoyproxy/go-control-plane/pkg/wellknown"
2321 otlpcommonv1 "go.opentelemetry.io/proto/otlp/common/v1"
@@ -35,8 +33,6 @@ const (
3533 otelAccessLog = "envoy.access_loggers.open_telemetry"
3634
3735 reqWithoutQueryCommandOperator = "%REQ_WITHOUT_QUERY"
38- metadataCommandOperator = "%METADATA"
39- celCommandOperator = "%CEL"
4036
4137 tcpGRPCAccessLog = "envoy.access_loggers.tcp_grpc"
4238 celFilter = "envoy.access_loggers.extension_filters.cel"
@@ -76,45 +72,17 @@ var listenerAccessLogFilter = &accesslog.AccessLogFilter{
7672 },
7773}
7874
79- var (
80- // reqWithoutQueryFormatter configures additional formatters needed for some of the format strings like "REQ_WITHOUT_QUERY"
81- reqWithoutQueryFormatter * cfgcore.TypedExtensionConfig
82-
83- // metadataFormatter configures additional formatters needed for some of the format strings like "METADATA"
84- // for more information, see https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/formatter/metadata/v3/metadata.proto
85- metadataFormatter * cfgcore.TypedExtensionConfig
86-
87- // celFormatter configures additional formatters needed for some of the format strings like "CEL"
88- // for more information, see https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/formatter/cel/v3/cel.proto
89- celFormatter * cfgcore.TypedExtensionConfig
90- )
75+ // reqWithoutQueryFormatter configures additional formatters needed for some of the format strings like "REQ_WITHOUT_QUERY"
76+ var reqWithoutQueryFormatter * cfgcore.TypedExtensionConfig
9177
9278func init () {
93- any , err := proto .ToAnyWithValidation (& reqwithoutqueryformatter.ReqWithoutQuery {})
79+ anyCfg , err := proto .ToAnyWithValidation (& reqwithoutqueryformatter.ReqWithoutQuery {})
9480 if err != nil {
9581 panic (err )
9682 }
9783 reqWithoutQueryFormatter = & cfgcore.TypedExtensionConfig {
9884 Name : "envoy.formatter.req_without_query" ,
99- TypedConfig : any ,
100- }
101-
102- any , err = proto .ToAnyWithValidation (& metadataformatter.Metadata {})
103- if err != nil {
104- panic (err )
105- }
106- metadataFormatter = & cfgcore.TypedExtensionConfig {
107- Name : "envoy.formatter.metadata" ,
108- TypedConfig : any ,
109- }
110-
111- any , err = proto .ToAnyWithValidation (& celformatter.Cel {})
112- if err != nil {
113- panic (err )
114- }
115- celFormatter = & cfgcore.TypedExtensionConfig {
116- Name : "envoy.formatter.cel" ,
117- TypedConfig : any ,
85+ TypedConfig : anyCfg ,
11886 }
11987}
12088
@@ -388,7 +356,7 @@ func celAccessLogFilter(expr string) (*accesslog.AccessLogFilter, error) {
388356 fl := & cel.ExpressionFilter {
389357 Expression : expr ,
390358 }
391- any , err := proto .ToAnyWithValidation (fl )
359+ anyCfg , err := proto .ToAnyWithValidation (fl )
392360 if err != nil {
393361 return nil , err
394362 }
@@ -397,7 +365,7 @@ func celAccessLogFilter(expr string) (*accesslog.AccessLogFilter, error) {
397365 FilterSpecifier : & accesslog.AccessLogFilter_ExtensionFilter {
398366 ExtensionFilter : & accesslog.ExtensionFilter {
399367 Name : celFilter ,
400- ConfigType : & accesslog.ExtensionFilter_TypedConfig {TypedConfig : any },
368+ ConfigType : & accesslog.ExtensionFilter_TypedConfig {TypedConfig : anyCfg },
401369 },
402370 },
403371 }, nil
@@ -441,36 +409,20 @@ func accessLogTextFormatters(text string) []*cfgcore.TypedExtensionConfig {
441409 formatters = append (formatters , reqWithoutQueryFormatter )
442410 }
443411
444- if strings .Contains (text , metadataCommandOperator ) {
445- formatters = append (formatters , metadataFormatter )
446- }
447-
448- if strings .Contains (text , celCommandOperator ) {
449- formatters = append (formatters , celFormatter )
450- }
451-
452412 return formatters
453413}
454414
455415func accessLogJSONFormatters (json map [string ]string ) []* cfgcore.TypedExtensionConfig {
456- reqWithoutQuery , metadata , cel := false , false , false
416+ reqWithoutQuery := false
457417
458418 for _ , value := range json {
459- if reqWithoutQuery && metadata && cel {
419+ if reqWithoutQuery {
460420 break
461421 }
462422
463423 if strings .Contains (value , reqWithoutQueryCommandOperator ) {
464424 reqWithoutQuery = true
465425 }
466-
467- if strings .Contains (value , metadataCommandOperator ) {
468- metadata = true
469- }
470-
471- if strings .Contains (value , celCommandOperator ) {
472- cel = true
473- }
474426 }
475427
476428 formatters := make ([]* cfgcore.TypedExtensionConfig , 0 , 3 )
@@ -479,64 +431,28 @@ func accessLogJSONFormatters(json map[string]string) []*cfgcore.TypedExtensionCo
479431 formatters = append (formatters , reqWithoutQueryFormatter )
480432 }
481433
482- if metadata {
483- formatters = append (formatters , metadataFormatter )
484- }
485-
486- if cel {
487- formatters = append (formatters , celFormatter )
488- }
489-
490434 return formatters
491435}
492436
493437func accessLogOpenTelemetryFormatters (body string , attributes map [string ]string ) []* cfgcore.TypedExtensionConfig {
494- reqWithoutQuery , metadata , cel := false , false , false
438+ var reqWithoutQuery bool
495439
496440 if strings .Contains (body , reqWithoutQueryCommandOperator ) {
497441 reqWithoutQuery = true
498442 }
499443
500- if strings .Contains (body , metadataCommandOperator ) {
501- metadata = true
502- }
503-
504- if strings .Contains (body , celCommandOperator ) {
505- cel = true
506- }
507-
508444 for _ , value := range attributes {
509- if reqWithoutQuery && metadata && cel {
510- break
511- }
512-
513- if ! reqWithoutQuery && strings .Contains (value , reqWithoutQueryCommandOperator ) {
445+ if strings .Contains (value , reqWithoutQueryCommandOperator ) {
514446 reqWithoutQuery = true
515- }
516-
517- if ! metadata && strings .Contains (value , metadataCommandOperator ) {
518- metadata = true
519- }
520-
521- if ! cel && strings .Contains (value , celCommandOperator ) {
522- cel = true
447+ break
523448 }
524449 }
525450
526451 formatters := make ([]* cfgcore.TypedExtensionConfig , 0 , 3 )
527-
528452 if reqWithoutQuery {
529453 formatters = append (formatters , reqWithoutQueryFormatter )
530454 }
531455
532- if metadata {
533- formatters = append (formatters , metadataFormatter )
534- }
535-
536- if cel {
537- formatters = append (formatters , celFormatter )
538- }
539-
540456 return formatters
541457}
542458
0 commit comments