Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds configs logging_add_custom_attributes, logging_drop_attribute_fb_input #1809

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,14 @@ type Config struct {
// Public: Yes
LoggingRetryLimit string `yaml:"logging_retry_limit" envconfig:"logging_retry_limit" public:"true"`

// LoggingAddCustomAtts adds custom_attributes to fluent-bit forwarder tags.
// Default: False
LoggingAddCustomAtts bool `yaml:"logging_add_custom_attributes" envconfig:"logging_add_custom_attributes" public:"false"`

// LoggingDropAttFbInput drops fb.input from fluent-bit forwarder tags.
// Default: False
LoggingDropAttFbInput bool `yaml:"logging_drop_attribute_fb_input" envconfig:"logging_drop_attribute_fb_input" public:"false"`

// FluentBitExePath is the location from where the agent can execute fluent-bit.
// Default (Linux): /opt/td-agent-bit/bin/td-agent-bit
// Default (Windows): C:\Program Files\New Relic\newrelic-infra\newrelic-integrations\logging\fluent-bit
Expand Down Expand Up @@ -1511,6 +1519,8 @@ type LogForward struct {
ProxyCfg LogForwardProxy
RetryLimit string
FluentBitVerbose bool
CommonAttributes CustomAttributeMap
DropAttFbInput bool
}

type LogForwardProxy struct {
Expand All @@ -1523,22 +1533,31 @@ type LogForwardProxy struct {

// NewLogForward creates a valid log forwarder config.
func NewLogForward(config *Config, troubleshoot Troubleshoot) LogForward {

// Add any config specified common attributes for logs
var commonAttributes CustomAttributeMap
if config.LoggingAddCustomAtts {
commonAttributes = config.CustomAttributes
}

return LogForward{
Troubleshoot: troubleshoot,
ConfigsDir: config.LoggingConfigsDir,
HomeDir: config.LoggingHomeDir,
License: config.License,
IsFedramp: config.Fedramp,
IsStaging: config.Staging,
RetryLimit: config.LoggingRetryLimit,
FluentBitVerbose: config.Log.Level == LogLevelTrace && config.Log.HasIncludeFilter(TracesFieldName, SupervisorTrace),
Troubleshoot: troubleshoot,
ConfigsDir: config.LoggingConfigsDir,
HomeDir: config.LoggingHomeDir,
License: config.License,
IsFedramp: config.Fedramp,
IsStaging: config.Staging,
ProxyCfg: LogForwardProxy{
IgnoreSystemProxy: config.IgnoreSystemProxy,
Proxy: config.Proxy,
CABundleFile: config.CABundleFile,
CABundleDir: config.CABundleDir,
ValidateCerts: config.ProxyValidateCerts,
},
RetryLimit: config.LoggingRetryLimit,
FluentBitVerbose: config.Log.Level == LogLevelTrace && config.Log.HasIncludeFilter(TracesFieldName, SupervisorTrace),
CommonAttributes: commonAttributes,
DropAttFbInput: config.LoggingDropAttFbInput,
}
}

Expand Down Expand Up @@ -1827,6 +1846,8 @@ func NewConfig() *Config {
DebugLogSec: defaultDebugLogSec,
TruncTextValues: defaultTruncTextValues,
LogFormat: defaultLogFormat,
LoggingAddCustomAtts: defaultLoggingAddCustomAtts,
LoggingDropAttFbInput: defaultLoggingDropAttFbInput,
LoggingRetryLimit: defaultLoggingRetryLimit,
HTTPServerHost: defaultHTTPServerHost,
HTTPServerPort: defaultHTTPServerPort,
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ var (
defaultLogFormat = LogFormatText
defaultLogLevel = LogLevelInfo
defaultLogForward = false
defaultLoggingAddCustomAtts = false
defaultLoggingDropAttFbInput = false
defaultLoggingRetryLimit = "5" // nolint:gochecknoglobals
defaultMaxInventorySize = 1000 * 1000 // Size limit from Vortex collector service (1MB)
defaultPayloadCompressionLevel = 6 // default compression level used in go, higher than this does not show tangible benefits
Expand Down
27 changes: 24 additions & 3 deletions pkg/integrations/v4/logs/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,17 @@ func NewFBConf(loggingCfgs LogsCfg, logFwdCfg *config.LogForward, entityGUID, ho
fb.Inputs = append(fb.Inputs, input)
}

fb.Filters = append(fb.Filters, filters...)
for _, filter := range filters {
_, ok := filter.Records["fb.input"]
if logFwdCfg.DropAttFbInput && ok {
// Delete fb.input if in filters
delete(filter.Records, "fb.input")
}
// If any records remain, add to filters
if len(filter.Records) > 0 {
fb.Filters = append(fb.Filters, filter)
}
}

if (external != FBCfgExternal{} && fb.ExternalCfg != FBCfgExternal{}) {
cfgLogger.Warn("External Fluent Bit configuration specified more than once. Only first one is considered, please remove any duplicates from the configuration.")
Expand All @@ -301,15 +311,26 @@ func NewFBConf(loggingCfgs LogsCfg, logFwdCfg *config.LogForward, entityGUID, ho
}

// This record_modifier FILTER adds common attributes for all the log records
fb.Filters = append(fb.Filters, FBCfgFilter{
commonFilter := FBCfgFilter{
Name: fbFilterTypeRecordModifier,
Match: "*",
Records: map[string]string{
rAttEntityGUID: entityGUID,
rAttPluginType: logRecordModifierSource,
rAttHostname: hostname,
},
})
}
// Add custom_attributes if provided
if logFwdCfg.CommonAttributes != nil {
for key, value := range logFwdCfg.CommonAttributes {
if !isReserved(key) {
commonFilter.Records[key] = fmt.Sprintf("%v", value)
} else {
cfgLogger.WithField("attribute", key).Warn("attribute name is a reserved keyword and will be ignored, please use a different name")
}
}
}
fb.Filters = append(fb.Filters, commonFilter)

// Newrelic OUTPUT plugin will send all the collected logs to Vortex
fb.Output = newNROutput(logFwdCfg)
Expand Down