Skip to content

Commit

Permalink
configure request without query access log formatter (istio#35795)
Browse files Browse the repository at this point in the history
* configure request without query access log formatter

Signed-off-by: Rama Chavali <rama.rao@salesforce.com>

* gen check

Signed-off-by: Rama Chavali <rama.rao@salesforce.com>

* add only if format exists

Signed-off-by: Rama Chavali <rama.rao@salesforce.com>

* change to value

Signed-off-by: Rama Chavali <rama.rao@salesforce.com>
  • Loading branch information
ramaraochavali authored Nov 8, 2021
1 parent 71563ca commit 1c418ae
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions pilot/pkg/networking/core/v1alpha3/accesslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package v1alpha3

import (
"strings"
"sync"

accesslog "github.com/envoyproxy/go-control-plane/envoy/config/accesslog/v3"
Expand All @@ -24,6 +25,7 @@ import (
grpcaccesslog "github.com/envoyproxy/go-control-plane/envoy/extensions/access_loggers/grpc/v3"
hcm "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
tcp "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/tcp_proxy/v3"
formatters "github.com/envoyproxy/go-control-plane/envoy/extensions/formatter/req_without_query/v3"
"github.com/envoyproxy/go-control-plane/pkg/wellknown"
structpb "google.golang.org/protobuf/types/known/structpb"

Expand Down Expand Up @@ -59,6 +61,8 @@ const (
// EnvoyAccessLogCluster is the cluster name that has details for server implementing Envoy ALS.
// This cluster is created in bootstrap.
EnvoyAccessLogCluster = "envoy_accesslog_service"

requestWithoutQuery = "%REQ_WITHOUT_QUERY%"
)

var (
Expand Down Expand Up @@ -102,6 +106,15 @@ var (

// accessLogBuilder is used to set accessLog to filters
accessLogBuilder = newAccessLogBuilder()

// accessLogFormatters configures additional formatters needed for some of the format strings like "REQ_WITHOUT_QUERY"
accessLogFormatters = []*core.TypedExtensionConfig{
{

Name: "envoy.formatter.req_without_query",
TypedConfig: util.MessageToAny(&formatters.ReqWithoutQuery{}),
},
}
)

type AccessLogBuilder struct {
Expand Down Expand Up @@ -203,13 +216,14 @@ func buildFileAccessLogHelper(path string, mesh *meshconfig.MeshConfig) *accessl
fl := &fileaccesslog.FileAccessLog{
Path: path,
}

needsFormatter := false
switch mesh.AccessLogEncoding {
case meshconfig.MeshConfig_TEXT:
formatString := EnvoyTextLogFormat
if mesh.AccessLogFormat != "" {
formatString = mesh.AccessLogFormat
}
needsFormatter = strings.Contains(formatString, requestWithoutQuery)
fl.AccessLogFormat = &fileaccesslog.FileAccessLog_LogFormat{
LogFormat: &core.SubstitutionFormatString{
Format: &core.SubstitutionFormatString_TextFormatSource{
Expand All @@ -231,6 +245,12 @@ func buildFileAccessLogHelper(path string, mesh *meshconfig.MeshConfig) *accessl
jsonLogStruct = &parsedJSONLogStruct
}
}
for _, value := range jsonLogStruct.Fields {
if value.GetStringValue() == requestWithoutQuery {
needsFormatter = true
break
}
}
fl.AccessLogFormat = &fileaccesslog.FileAccessLog_LogFormat{
LogFormat: &core.SubstitutionFormatString{
Format: &core.SubstitutionFormatString_JsonFormat{
Expand All @@ -241,7 +261,9 @@ func buildFileAccessLogHelper(path string, mesh *meshconfig.MeshConfig) *accessl
default:
log.Warnf("unsupported access log format %v", mesh.AccessLogEncoding)
}

if needsFormatter {
fl.GetLogFormat().Formatters = accessLogFormatters
}
al := &accesslog.AccessLog{
Name: wellknown.FileAccessLog,
ConfigType: &accesslog.AccessLog_TypedConfig{TypedConfig: util.MessageToAny(fl)},
Expand Down

0 comments on commit 1c418ae

Please sign in to comment.