@@ -36,40 +36,90 @@ import (
36
36
"google.golang.org/protobuf/types/known/wrapperspb"
37
37
)
38
38
39
- // getAccessLogConfigs provides file access log configurations for envoy
40
- func getFileAccessLogConfigs () * config_access_logv3.AccessLog {
41
- var logFormat * file_accesslogv3.FileAccessLog_LogFormat
42
- logpath := defaultAccessLogPath //default access log path
43
-
44
- logConf := config .ReadLogConfigs ()
45
-
46
- if ! logConf .AccessLogs .Enable {
47
- logger .LoggerOasparser .Info ("Accesslog Configurations are disabled." )
48
- return nil
49
- }
50
-
51
- formatters := []* corev3.TypedExtensionConfig {
39
+ // getAccessLogConfigs provides default formatters
40
+ func getDefaultFormatters () []* corev3.TypedExtensionConfig {
41
+ return []* corev3.TypedExtensionConfig {
52
42
{
53
43
Name : "envoy.formatter.req_without_query" ,
54
44
TypedConfig : & anypb.Any {
55
45
TypeUrl : "type.googleapis.com/envoy.extensions.formatter.req_without_query.v3.ReqWithoutQuery" ,
56
46
},
57
47
},
58
48
}
59
- // Set the default log format
60
- logFormat = & file_accesslogv3.FileAccessLog_LogFormat {
49
+ }
50
+
51
+ // getDefaultTextLogFormat provides default text log format
52
+ func getDefaultTextLogFormat (loggingFormat string ) * file_accesslogv3.FileAccessLog_LogFormat {
53
+ formatters := getDefaultFormatters ()
54
+
55
+ return & file_accesslogv3.FileAccessLog_LogFormat {
61
56
LogFormat : & corev3.SubstitutionFormatString {
62
57
Format : & corev3.SubstitutionFormatString_TextFormatSource {
63
58
TextFormatSource : & corev3.DataSource {
64
59
Specifier : & corev3.DataSource_InlineString {
65
- InlineString : logConf .AccessLogs .ReservedLogFormat +
66
- strings .TrimLeft (logConf .AccessLogs .SecondaryLogFormat , "'" ) + "\n " ,
60
+ InlineString : loggingFormat ,
67
61
},
68
62
},
69
63
},
70
64
Formatters : formatters ,
71
65
},
72
66
}
67
+ }
68
+
69
+ // getAccessLogConfigs provides file access log configurations for envoy
70
+ func getInsightsAccessLogConfigs () * config_access_logv3.AccessLog {
71
+ var logFormat * file_accesslogv3.FileAccessLog_LogFormat
72
+ logpath := defaultAccessLogPath //default access log path
73
+
74
+ logConf := config .ReadLogConfigs ()
75
+
76
+ if ! logConf .InsightsLogs .Enable {
77
+ return nil
78
+ }
79
+
80
+ // Set the default log format
81
+ loggingFormat := logConf .InsightsLogs .LoggingFormat + "\n "
82
+ logFormat = getDefaultTextLogFormat (loggingFormat )
83
+
84
+ logpath = logConf .InsightsLogs .LogFile
85
+ accessLogConf := & file_accesslogv3.FileAccessLog {
86
+ Path : logpath ,
87
+ AccessLogFormat : logFormat ,
88
+ }
89
+
90
+ accessLogTypedConf , err := anypb .New (accessLogConf )
91
+ if err != nil {
92
+ logger .LoggerOasparser .Error ("Error marshaling access log configs. " , err )
93
+ return nil
94
+ }
95
+
96
+ accessLog := config_access_logv3.AccessLog {
97
+ Name : fileAccessLogName ,
98
+ Filter : nil ,
99
+ ConfigType : & config_access_logv3.AccessLog_TypedConfig {
100
+ TypedConfig : accessLogTypedConf ,
101
+ },
102
+ }
103
+
104
+ return & accessLog
105
+ }
106
+
107
+ // getAccessLogConfigs provides file access log configurations for envoy
108
+ func getFileAccessLogConfigs () * config_access_logv3.AccessLog {
109
+ var logFormat * file_accesslogv3.FileAccessLog_LogFormat
110
+ logpath := defaultAccessLogPath //default access log path
111
+
112
+ logConf := config .ReadLogConfigs ()
113
+
114
+ if ! logConf .AccessLogs .Enable {
115
+ logger .LoggerOasparser .Info ("Accesslog Configurations are disabled." )
116
+ return nil
117
+ }
118
+
119
+ // Set the default log format
120
+ loggingFormat := logConf .AccessLogs .ReservedLogFormat +
121
+ strings .TrimLeft (logConf .AccessLogs .SecondaryLogFormat , "'" ) + "\n "
122
+ logFormat = getDefaultTextLogFormat (loggingFormat )
73
123
74
124
// Configure the log format based on the log type
75
125
switch logConf .AccessLogs .LogType {
@@ -95,7 +145,7 @@ func getFileAccessLogConfigs() *config_access_logv3.AccessLog {
95
145
Fields : logFields ,
96
146
},
97
147
},
98
- Formatters : formatters ,
148
+ Formatters : getDefaultFormatters () ,
99
149
},
100
150
}
101
151
logger .LoggerOasparser .Debug ("Access log type is set to json." )
@@ -197,12 +247,16 @@ func getAccessLogs() []*config_access_logv3.AccessLog {
197
247
var accessLoggers []* config_access_logv3.AccessLog
198
248
fileAccessLog := getFileAccessLogConfigs ()
199
249
grpcAccessLog := getGRPCAccessLogConfigs (conf )
250
+ insightsAccessLog := getInsightsAccessLogConfigs ()
200
251
if fileAccessLog != nil {
201
252
accessLoggers = append (accessLoggers , fileAccessLog )
202
253
}
203
254
if grpcAccessLog != nil {
204
255
accessLoggers = append (accessLoggers , getGRPCAccessLogConfigs (conf ))
205
256
}
257
+ if insightsAccessLog != nil {
258
+ accessLoggers = append (accessLoggers , insightsAccessLog )
259
+ }
206
260
return accessLoggers
207
261
}
208
262
0 commit comments