in agent/taskresource/firelens/firelensconfig_unix.go [119:202]
func (firelens *FirelensResource) generateConfig() (generator.FluentConfig, error) {
config := generator.New()
// Specify log stream input, which is a unix socket that will be used for communication between the Firelens
// container and other containers.
var inputName, inputPathOption, matchAnyWildcard string
if firelens.firelensConfigType == FirelensConfigTypeFluentd {
inputName = socketInputNameFluentd
inputPathOption = socketInputPathOptionFluentd
matchAnyWildcard = matchAnyWildcardFluentd
} else {
inputName = inputNameForward
inputPathOption = socketInputPathOptionFluentbit
matchAnyWildcard = matchAnyWildcardFluentbit
}
config.AddInput(inputName, "", map[string]string{
inputPathOption: socketPath,
})
// Specify log stream input of tcp socket kind that can be used for communication between the Firelens
// container and other containers if the network is bridge or awsvpc mode. Also add health check sections to support
// doing container health check on firlens container for these two modes.
if firelens.networkMode == bridgeNetworkMode || firelens.networkMode == awsvpcNetworkMode {
var inputMap map[string]string
var inputBindValue string
if firelens.networkMode == bridgeNetworkMode {
inputBindValue = inputBridgeBindValue
} else if firelens.networkMode == awsvpcNetworkMode {
inputBindValue = inputAWSVPCBindValue
}
if firelens.firelensConfigType == FirelensConfigTypeFluentd {
inputMap = map[string]string{
inputPortOptionFluentd: inputPortValue,
inputBindOptionFluentd: inputBindValue,
}
inputName = inputNameForward
} else {
inputName = inputNameForward
inputMap = map[string]string{
inputPortOptionFluentbit: inputPortValue,
inputListenOptionFluentbit: inputBindValue,
}
}
config.AddInput(inputName, "", inputMap)
firelens.addHealthcheckSections(config)
}
if firelens.ecsMetadataEnabled {
// Add ecs metadata fields to the log stream.
config.AddFieldToRecord("ecs_cluster", firelens.cluster, matchAnyWildcard).
AddFieldToRecord("ecs_task_arn", firelens.taskARN, matchAnyWildcard).
AddFieldToRecord("ecs_task_definition", firelens.taskDefinition, matchAnyWildcard)
if firelens.ec2InstanceID != "" {
config.AddFieldToRecord("ec2_instance_id", firelens.ec2InstanceID, matchAnyWildcard)
}
}
// Specify log stream output. Each container that uses the firelens container to stream logs
// may have its own output section with options, constructed from container's log options.
for containerName, logOptions := range firelens.containerToLogOptions {
tag := fmt.Sprintf(fluentTagOutputFormat, containerName, matchAnyWildcard) // Each output section is distinguished by a tag specific to a container.
newConfig, err := addOutputSection(tag, firelens.firelensConfigType, logOptions, config)
if err != nil {
return nil, fmt.Errorf("unable to apply log options of container %s to firelens config: %v", containerName, err)
}
config = newConfig
}
// Include external config file if specified.
if firelens.externalConfigType == ExternalConfigTypeFile {
config.AddExternalConfig(firelens.externalConfigValue, generator.AfterFilters)
} else if firelens.externalConfigType == ExternalConfigTypeS3 {
var s3ConfPath string
if firelens.firelensConfigType == FirelensConfigTypeFluentd {
s3ConfPath = S3ConfigPathFluentd
} else {
s3ConfPath = S3ConfigPathFluentbit
}
config.AddExternalConfig(s3ConfPath, generator.AfterFilters)
}
seelog.Infof("Included external firelens config file at: %s", firelens.externalConfigValue)
return config, nil
}