Skip to content

Commit

Permalink
Merge pull request #3602 from ruks/choreo_filter1
Browse files Browse the repository at this point in the history
Filter insights access logs if org id it not present
  • Loading branch information
ruks authored Oct 15, 2024
2 parents de31034 + d06c645 commit c7f4486
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
44 changes: 39 additions & 5 deletions adapter/internal/oasparser/envoyconf/access_loggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func getDefaultFormatters() []*corev3.TypedExtensionConfig {
}

// getDefaultTextLogFormat provides default text log format
func getDefaultTextLogFormat(loggingFormat string) *file_accesslogv3.FileAccessLog_LogFormat {
func getDefaultTextLogFormat(loggingFormat string, omitEmptyValues bool) *file_accesslogv3.FileAccessLog_LogFormat {
formatters := getDefaultFormatters()

return &file_accesslogv3.FileAccessLog_LogFormat{
Expand All @@ -61,7 +61,8 @@ func getDefaultTextLogFormat(loggingFormat string) *file_accesslogv3.FileAccessL
},
},
},
Formatters: formatters,
Formatters: formatters,
OmitEmptyValues: omitEmptyValues,
},
}
}
Expand All @@ -79,7 +80,7 @@ func getInsightsAccessLogConfigs() *config_access_logv3.AccessLog {

// Set the default log format
loggingFormat := logConf.InsightsLogs.LoggingFormat + "\n"
logFormat = getDefaultTextLogFormat(loggingFormat)
logFormat = getDefaultTextLogFormat(loggingFormat, logConf.InsightsLogs.OmitEmptyValues)

logpath = logConf.InsightsLogs.LogFile
accessLogConf := &file_accesslogv3.FileAccessLog{
Expand All @@ -93,9 +94,42 @@ func getInsightsAccessLogConfigs() *config_access_logv3.AccessLog {
return nil
}

orgIDFilter := &config_access_logv3.AccessLogFilter{
FilterSpecifier: &config_access_logv3.AccessLogFilter_MetadataFilter{
MetadataFilter: &config_access_logv3.MetadataFilter{
Matcher: &matcherv3.MetadataMatcher{
Filter: extAuthzFilterName,
Path: []*matcherv3.MetadataMatcher_PathSegment{
{
Segment: &matcherv3.MetadataMatcher_PathSegment_Key{
Key: xWso2ApiOrganizationID,
},
},
},
Value: &matcherv3.ValueMatcher{
MatchPattern: &matcherv3.ValueMatcher_StringMatch{
StringMatch: &matcherv3.StringMatcher{
MatchPattern: &matcherv3.StringMatcher_SafeRegex{
SafeRegex: &matcherv3.RegexMatcher{
EngineType: &matcherv3.RegexMatcher_GoogleRe2{
GoogleRe2: &matcherv3.RegexMatcher_GoogleRE2{},
},
Regex: "^.{2,}$",
},
},
},
},
},
Invert: false,
},
MatchIfKeyNotFound: &wrapperspb.BoolValue{Value: false},
},
},
}

accessLog := config_access_logv3.AccessLog{
Name: fileAccessLogName,
Filter: nil,
Filter: orgIDFilter,
ConfigType: &config_access_logv3.AccessLog_TypedConfig{
TypedConfig: accessLogTypedConf,
},
Expand All @@ -119,7 +153,7 @@ func getFileAccessLogConfigs() *config_access_logv3.AccessLog {
// Set the default log format
loggingFormat := logConf.AccessLogs.ReservedLogFormat +
strings.TrimLeft(logConf.AccessLogs.SecondaryLogFormat, "'") + "\n"
logFormat = getDefaultTextLogFormat(loggingFormat)
logFormat = getDefaultTextLogFormat(loggingFormat, false)

// Configure the log format based on the log type
switch logConf.AccessLogs.LogType {
Expand Down
1 change: 1 addition & 0 deletions adapter/internal/oasparser/envoyconf/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const (
xWso2requestInterceptor string = "x-wso2-request-interceptor"
// xWso2responseInterceptor used to provide response interceptor details for api and resource level
xWso2responseInterceptor string = "x-wso2-response-interceptor"
xWso2ApiOrganizationID string = "x-wso2-api-organization-id"
)

// interceptor levels
Expand Down

0 comments on commit c7f4486

Please sign in to comment.