Skip to content

Commit 4a67b46

Browse files
authored
Merge pull request #3596 from ruks/choreo
Support Insights access logs and configs
2 parents 2208e9e + 366be3e commit 4a67b46

File tree

18 files changed

+1780
-62
lines changed

18 files changed

+1780
-62
lines changed

adapter/internal/discovery/xds/server.go

+10
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,16 @@ func UpdateAPI(vHost string, apiProject mgw.ProjectAPI, deployedEnvironments []*
358358
mgwSwagger.APIProvider = apiProject.APIYaml.Data.Provider
359359
mgwSwagger.EnvironmentID = deployedEnvironments[0].ID
360360
mgwSwagger.EnvironmentName = deployedEnvironments[0].Name
361+
362+
choreoComponentInfo := mgw.ChoreoComponentInfo{
363+
OrganizationID: apiYaml.ChoreoComponentInfo.OrganizationID,
364+
ProjectID: apiYaml.ChoreoComponentInfo.ProjectID,
365+
ComponentID: apiYaml.ChoreoComponentInfo.ComponentID,
366+
VersionID: apiYaml.ChoreoComponentInfo.VersionID,
367+
}
368+
369+
mgwSwagger.ChoreoComponentInfo = &choreoComponentInfo
370+
361371
organizationID := apiProject.OrganizationID
362372
apiHashValue := generateHashValue(apiYaml.Name, apiYaml.Version)
363373

adapter/internal/oasparser/config_generator.go

+9
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ func GetEnforcerAPI(mgwSwagger model.MgwSwagger, lifeCycleState string, vhost st
196196
}
197197
}
198198

199+
choreoComponentInfo := &api.ChoreoComponentInfo{}
200+
if mgwSwagger.ChoreoComponentInfo != nil {
201+
choreoComponentInfo.ComponentID = mgwSwagger.ChoreoComponentInfo.ComponentID
202+
choreoComponentInfo.VersionID = mgwSwagger.ChoreoComponentInfo.VersionID
203+
choreoComponentInfo.OrganizationID = mgwSwagger.ChoreoComponentInfo.OrganizationID
204+
choreoComponentInfo.ProjectID = mgwSwagger.ChoreoComponentInfo.ProjectID
205+
}
206+
199207
return &api.Api{
200208
Id: mgwSwagger.GetID(),
201209
Title: mgwSwagger.GetTitle(),
@@ -221,6 +229,7 @@ func GetEnforcerAPI(mgwSwagger model.MgwSwagger, lifeCycleState string, vhost st
221229
DeploymentType: mgwSwagger.DeploymentType,
222230
EnvironmentId: mgwSwagger.EnvironmentID,
223231
EnvironmentName: mgwSwagger.EnvironmentName,
232+
ChoreoComponentInfo: choreoComponentInfo,
224233
}
225234
}
226235

adapter/internal/oasparser/envoyconf/access_loggers.go

+72-18
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,90 @@ import (
3636
"google.golang.org/protobuf/types/known/wrapperspb"
3737
)
3838

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{
5242
{
5343
Name: "envoy.formatter.req_without_query",
5444
TypedConfig: &anypb.Any{
5545
TypeUrl: "type.googleapis.com/envoy.extensions.formatter.req_without_query.v3.ReqWithoutQuery",
5646
},
5747
},
5848
}
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{
6156
LogFormat: &corev3.SubstitutionFormatString{
6257
Format: &corev3.SubstitutionFormatString_TextFormatSource{
6358
TextFormatSource: &corev3.DataSource{
6459
Specifier: &corev3.DataSource_InlineString{
65-
InlineString: logConf.AccessLogs.ReservedLogFormat +
66-
strings.TrimLeft(logConf.AccessLogs.SecondaryLogFormat, "'") + "\n",
60+
InlineString: loggingFormat,
6761
},
6862
},
6963
},
7064
Formatters: formatters,
7165
},
7266
}
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)
73123

74124
// Configure the log format based on the log type
75125
switch logConf.AccessLogs.LogType {
@@ -95,7 +145,7 @@ func getFileAccessLogConfigs() *config_access_logv3.AccessLog {
95145
Fields: logFields,
96146
},
97147
},
98-
Formatters: formatters,
148+
Formatters: getDefaultFormatters(),
99149
},
100150
}
101151
logger.LoggerOasparser.Debug("Access log type is set to json.")
@@ -197,12 +247,16 @@ func getAccessLogs() []*config_access_logv3.AccessLog {
197247
var accessLoggers []*config_access_logv3.AccessLog
198248
fileAccessLog := getFileAccessLogConfigs()
199249
grpcAccessLog := getGRPCAccessLogConfigs(conf)
250+
insightsAccessLog := getInsightsAccessLogConfigs()
200251
if fileAccessLog != nil {
201252
accessLoggers = append(accessLoggers, fileAccessLog)
202253
}
203254
if grpcAccessLog != nil {
204255
accessLoggers = append(accessLoggers, getGRPCAccessLogConfigs(conf))
205256
}
257+
if insightsAccessLog != nil {
258+
accessLoggers = append(accessLoggers, insightsAccessLog)
259+
}
206260
return accessLoggers
207261
}
208262

adapter/internal/oasparser/model/mgw_swagger.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,18 @@ type MgwSwagger struct {
6969
// APIProvider is required for analytics purposes as /apis call is avoided temporarily.
7070
APIProvider string
7171
// DeploymentType could be either "PRODUCTION" or "SANDBOX"
72-
DeploymentType string
73-
EnvironmentID string
74-
EnvironmentName string
72+
DeploymentType string
73+
EnvironmentID string
74+
EnvironmentName string
75+
ChoreoComponentInfo *ChoreoComponentInfo
76+
}
77+
78+
// ChoreoComponentInfo represents the information of the Choreo component
79+
type ChoreoComponentInfo struct {
80+
OrganizationID string
81+
ProjectID string
82+
ComponentID string
83+
VersionID string
7584
}
7685

7786
// EndpointCluster represent an upstream cluster

adapter/internal/oasparser/model/types.go

+8
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ type apiData struct {
148148
BackendJWTConfiguration backendJWTConfiguration `json:"backendJWTConfiguration,omitempty"`
149149
EndpointConfig endpointConfigStruct `json:"endpointConfig,omitempty"`
150150
Operations []OperationYaml `json:"Operations,omitempty"`
151+
ChoreoComponentInfo choreoComponentInfo `json:"choreoComponentInfo,omitempty"`
152+
}
153+
154+
type choreoComponentInfo struct {
155+
OrganizationID string `json:"organizationId,omitempty"`
156+
ProjectID string `json:"projectId,omitempty"`
157+
ComponentID string `json:"componentId,omitempty"`
158+
VersionID string `json:"versionId,omitempty"`
151159
}
152160

153161
type backendJWTConfiguration struct {

adapter/pkg/config/log_types.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ type accessLog struct {
3535
JSONFormat map[string]string
3636
}
3737

38+
type insightsLog struct {
39+
Enable bool
40+
LogFile string
41+
LoggingFormat string
42+
OmitEmptyValues bool
43+
}
44+
3845
// AccessLogExcludes represents the configurations related to excludes from access logs.
3946
type AccessLogExcludes struct {
4047
SystemHost AccessLogExcludesSystemHost
@@ -60,8 +67,9 @@ type LogConfig struct {
6067
Compress bool
6168
}
6269

63-
Pkg []pkg
64-
AccessLogs *accessLog
70+
Pkg []pkg
71+
AccessLogs *accessLog
72+
InsightsLogs *insightsLog
6573
}
6674

6775
func getDefaultLogConfig() *LogConfig {
@@ -115,6 +123,12 @@ func getDefaultLogConfig() *LogConfig {
115123
"extAuthDtls": "%DYNAMIC_METADATA(envoy.filters.http.ext_authz:extAuthDetails)%",
116124
},
117125
},
126+
InsightsLogs: &insightsLog{
127+
Enable: false,
128+
LogFile: "/dev/stdout",
129+
LoggingFormat: "-",
130+
OmitEmptyValues: true,
131+
},
118132
}
119133
adapterLogConfig.Rotation.MaxSize = 10
120134
adapterLogConfig.Rotation.MaxAge = 2

adapter/pkg/discovery/api/wso2/discovery/api/api.pb.go

+34-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)