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

Sarah/fluentbit windows log #688

Merged
merged 15 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

@td_agent_bit_conf_path = "/etc/opt/microsoft/docker-cimprov/td-agent-bit.conf"

@os_type = ENV["OS_TYPE"]
if !@os_type.nil? && !@os_type.empty? && @os_type.strip.casecmp("windows") == 0
@td_agent_bit_conf_path = "/etc/fluent-bit/fluent-bit.conf"
end

@default_service_interval = "15"
@default_mem_buf_limit = "10"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,37 @@ def populateSettingValuesFromConfigMap(parsedConfig)
puts "Exception while opening file for writing config environment variables"
puts "****************End Config Processing********************"
end

def get_command_windows(env_variable_name, env_variable_value)
return "[System.Environment]::SetEnvironmentVariable(\"#{env_variable_name}\", \"#{env_variable_value}\", \"Process\")" + "\n" + "[System.Environment]::SetEnvironmentVariable(\"#{env_variable_name}\", \"#{env_variable_value}\", \"Machine\")" + "\n"
end

if !@os_type.nil? && !@os_type.empty? && @os_type.strip.casecmp("windows") == 0
# Write the settings to file, so that they can be set as environment variables
file = File.open("setagentenv.ps1", "w")

if !file.nil?
if @fbitFlushIntervalSecs > 0
commands = get_command_windows('FBIT_SERVICE_FLUSH_INTERVAL', @fbitFlushIntervalSecs)
file.write(commands)
end
if @fbitTailBufferChunkSizeMBs > 0
commands = get_command_windows('FBIT_TAIL_BUFFER_CHUNK_SIZE', @fbitTailBufferChunkSizeMBs)
file.write(commands)
end
if @fbitTailBufferMaxSizeMBs > 0
commands = get_command_windows('FBIT_TAIL_BUFFER_MAX_SIZE', @fbitTailBufferMaxSizeMBs)
file.write(commands)
end
if @fbitTailMemBufLimitMBs > 0
commands = get_command_windows('FBIT_TAIL_MEM_BUF_LIMIT', @fbitTailMemBufLimitMBs)
file.write(commands)
end
# Close file after writing all environment variables
file.close
puts "****************End Config Processing********************"
else
puts "Exception while opening file for writing config environment variables for WINDOWS LOG"
puts "****************End Config Processing********************"
end
end
2 changes: 2 additions & 0 deletions build/common/installer/scripts/tomlparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
@adxDatabaseName = "containerinsights" # default for all configurations
if !@os_type.nil? && !@os_type.empty? && @os_type.strip.casecmp("windows") == 0
@containerLogsRoute = "v1" # default is v1 for windows until windows agent integrates windows ama
# This path format is necessary for fluent-bit in windows
@logTailPath = "C:\\var\\log\\containers\\*.log"
end
# Use parser to parse the configmap toml file to a ruby structure
def parseConfigMap
Expand Down
4 changes: 2 additions & 2 deletions build/linux/installer/datafiles/base_container.data
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ MAINTAINER: 'Microsoft Corporation'
/etc/opt/microsoft/docker-cimprov/td-agent-bit.conf; build/linux/installer/conf/td-agent-bit.conf; 644; root; root
/etc/opt/microsoft/docker-cimprov/td-agent-bit-prom-side-car.conf; build/linux/installer/conf/td-agent-bit-prom-side-car.conf; 644; root; root
/etc/opt/microsoft/docker-cimprov/td-agent-bit-rs.conf; build/linux/installer/conf/td-agent-bit-rs.conf; 644; root; root
/etc/opt/microsoft/docker-cimprov/azm-containers-parser.conf; build/linux/installer/conf/azm-containers-parser.conf; 644; root; root
/etc/opt/microsoft/docker-cimprov/azm-containers-parser.conf; build/common/installer/conf/azm-containers-parser.conf; 644; root; root
/etc/opt/microsoft/docker-cimprov/out_oms.conf; build/linux/installer/conf/out_oms.conf; 644; root; root
/etc/opt/microsoft/docker-cimprov/test.json; build/linux/installer/conf/test.json; 644; root; root
/etc/opt/microsoft/docker-cimprov/telegraf.conf; build/linux/installer/conf/telegraf.conf; 644; root; root
Expand All @@ -48,7 +48,7 @@ MAINTAINER: 'Microsoft Corporation'
/opt/tomlparser-metric-collection-config.rb; build/linux/installer/scripts/tomlparser-metric-collection-config.rb; 755; root; root


/opt/tomlparser-agent-config.rb; build/linux/installer/scripts/tomlparser-agent-config.rb; 755; root; root
/opt/tomlparser-agent-config.rb; build/common/installer/scripts/tomlparser-agent-config.rb; 755; root; root
/opt/tomlparser.rb; build/common/installer/scripts/tomlparser.rb; 755; root; root
/opt/td-agent-bit-conf-customizer.rb; build/common/installer/scripts/td-agent-bit-conf-customizer.rb; 755; root; root
/opt/ConfigParseErrorLogger.rb; build/common/installer/scripts/ConfigParseErrorLogger.rb; 755; root; root
Expand Down
70 changes: 53 additions & 17 deletions build/windows/installer/conf/fluent-bit.conf
Original file line number Diff line number Diff line change
@@ -1,25 +1,61 @@
[SERVICE]
Flush 15
Daemon Off
Log_Level info
Log_File /etc/fluent-bit/fluent-bit.log
Flush 15
sarahpeiffer marked this conversation as resolved.
Show resolved Hide resolved
Daemon Off
storage.path /etc/fluent-bit/flbstore/
storage.sync normal
storage.checksum off
storage.backlog.mem_limit 10M
Log_Level debug
Parsers_File /etc/fluent-bit/azm-containers-parser.conf
Log_File /etc/fluent-bit/fluent-bit.log

[INPUT]
Name forward
Listen 127.0.0.1
Port 25230
Mem_Buf_Limit 10m
Chunk_Size 32
Buffer_Size 64
Name tail
Tag oms.container.log.la.*
Path ${AZMON_LOG_TAIL_PATH}
Read_from_Head true
DB /etc/fluent-bit/omsagent-fblogs.db
DB.Sync Off
Parser docker
${TAIL_MEM_BUF_LIMIT}
${TAIL_BUFFER_CHUNK_SIZE}
${TAIL_BUFFER_MAX_SIZE}
Rotate_Wait 20
Refresh_Interval 30
Path_Key filepath
Skip_Long_Lines On
Ignore_Older 5m
Exclude_Path ${AZMON_CLUSTER_LOG_TAIL_EXCLUDE_PATH}

[INPUT]
Name tcp
Tag oms.container.perf.telegraf.*
Listen 0.0.0.0
Port 25229
Chunk_Size 32
Buffer_Size 64
Mem_Buf_Limit 5m
Name tail
Tag oms.container.log.flbplugin.*
Path C:\\var\\log\\containers\\omsagent*.log
Read_from_Head true
DB /etc/fluent-bit/omsagent-fluentbit-containers.db
sarahpeiffer marked this conversation as resolved.
Show resolved Hide resolved
DB.Sync Off
Parser docker
Mem_Buf_Limit 1m
Path_Key filepath
Skip_Long_Lines On
Ignore_Older 5m

[INPUT]
sarahpeiffer marked this conversation as resolved.
Show resolved Hide resolved
Name forward
Listen 127.0.0.1
Port 25230
Mem_Buf_Limit 10m
Buffer_Chunk_Size 32
Buffer_Max_Size 64

[INPUT]
Name tcp
Tag oms.container.perf.telegraf.*
Listen 0.0.0.0
Port 25229
Chunk_Size 32
Buffer_Size 64
Mem_Buf_Limit 5m

[OUTPUT]
Name oms
Expand Down
34 changes: 0 additions & 34 deletions build/windows/installer/conf/fluent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,6 @@
@log_level debug
</source>

<source>
@type tail
path "#{ENV['AZMON_LOG_TAIL_PATH']}"
exclude_path "#{ENV['AZMON_CLUSTER_LOG_TAIL_EXCLUDE_PATH']}"
pos_file /var/opt/microsoft/fluent/fluentd-containers.log.pos
tag oms.container.log.la
@log_level trace
path_key tailed_path
limit_recently_modified 5m
# if the container runtime is non docker then this will be updated to fluent-cri-parser.conf during container startup
@include fluent-docker-parser.conf
</source>

<source>
@type tail
path /var/log/containers/omsagent*.log
pos_file /opt/microsoft/fluent/omsagent-fluentd-containers.log.pos
tag oms.container.log.flbplugin
@log_level trace
path_key tailed_path
read_from_head true
# if the container runtime is non docker then this will be updated to fluent-cri-parser.conf during container startup
@include fluent-docker-parser.conf
</source>

#custom_metrics_mdm filter plugin
<filter mdm.cadvisorperf**>
@type cadvisor2mdm
Expand All @@ -52,15 +27,6 @@
</exclude>
</filter>

<filter oms.container.**>
@type record_transformer
# fluent-plugin-record-modifier more light-weight but needs to be installed (dependency worth it?)
remove_keys tailed_path
<record>
filepath ${record["tailed_path"]}
</record>
</filter>

<match mdm.cadvisorperf**>
@type mdm
@log_level debug
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/linux/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ chmod 777 /opt/telegraf
wget -qO - https://packages.fluentbit.io/fluentbit.key | sudo apt-key add -
sudo echo "deb https://packages.fluentbit.io/ubuntu/xenial xenial main" >> /etc/apt/sources.list
sudo apt-get update
sudo apt-get install td-agent-bit=1.6.8 -y
sudo apt-get install td-agent-bit=1.7.8 -y
ganga1980 marked this conversation as resolved.
Show resolved Hide resolved

# install ruby2.6
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F5DA5F09C3173AA6
Expand Down
1 change: 1 addition & 0 deletions kubernetes/windows/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ COPY ./omsagentwindows/installer/conf/fluent.conf /etc/fluent/
COPY ./omsagentwindows/installer/conf/fluent-cri-parser.conf /etc/fluent/
COPY ./omsagentwindows/installer/conf/fluent-docker-parser.conf /etc/fluent/
COPY ./omsagentwindows/installer/conf/fluent-bit.conf /etc/fluent-bit
COPY ./omsagentwindows/installer/conf/azm-containers-parser.conf /etc/fluent-bit/
COPY ./omsagentwindows/installer/conf/out_oms.conf /etc/omsagentwindows

# copy telegraf conf file
Expand Down
1 change: 1 addition & 0 deletions kubernetes/windows/Dockerfile-dev-image
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ COPY ./omsagentwindows/installer/conf/fluent.conf /etc/fluent/
COPY ./omsagentwindows/installer/conf/fluent-cri-parser.conf /etc/fluent/
sarahpeiffer marked this conversation as resolved.
Show resolved Hide resolved
COPY ./omsagentwindows/installer/conf/fluent-docker-parser.conf /etc/fluent/
COPY ./omsagentwindows/installer/conf/fluent-bit.conf /etc/fluent-bit
COPY ./omsagentwindows/installer/conf/azm-containers-parser.conf /etc/fluent-bit/
COPY ./omsagentwindows/installer/conf/out_oms.conf /etc/omsagentwindows

# copy telegraf conf file
Expand Down
15 changes: 11 additions & 4 deletions kubernetes/windows/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ function Set-EnvironmentVariables {
# run config parser
ruby /opt/omsagentwindows/scripts/ruby/tomlparser.rb
.\setenv.ps1

#Parse the configmap to set the right environment variables for agent config.
ruby /opt/omsagentwindows/scripts/ruby/tomlparser-agent-config.rb
.\setagentenv.ps1

#Replace placeholders in fluent-bit.conf
ruby /opt/omsagentwindows/scripts/ruby/td-agent-bit-conf-customizer.rb

# run mdm config parser
ruby /opt/omsagentwindows/scripts/ruby/tomlparser-mdm-metrics-config.rb
Expand Down Expand Up @@ -418,18 +425,18 @@ function Get-ContainerRuntime {

function Start-Fluent-Telegraf {

# Run fluent-bit service first so that we do not miss any logs being forwarded by the fluentd service and telegraf service.
$containerRuntime = Get-ContainerRuntime

# Run fluent-bit service first so that we do not miss any logs being forwarded by the telegraf service.
# Run fluent-bit as a background job. Switch this to a windows service once fluent-bit supports natively running as a windows service
Start-Job -ScriptBlock { Start-Process -NoNewWindow -FilePath "C:\opt\fluent-bit\bin\fluent-bit.exe" -ArgumentList @("-c", "C:\etc\fluent-bit\fluent-bit.conf", "-e", "C:\opt\omsagentwindows\out_oms.so") }

$containerRuntime = Get-ContainerRuntime

#register fluentd as a service and start
# there is a known issues with win32-service https://github.com/chef/win32-service/issues/70
if (![string]::IsNullOrEmpty($containerRuntime) -and [string]$containerRuntime.StartsWith('docker') -eq $false) {
# change parser from docker to cri if the container runtime is not docker
Write-Host "changing parser from Docker to CRI since container runtime : $($containerRuntime) and which is non-docker"
(Get-Content -Path C:/etc/fluent/fluent.conf -Raw) -replace 'fluent-docker-parser.conf', 'fluent-cri-parser.conf' | Set-Content C:/etc/fluent/fluent.conf
(Get-Content -Path C:/etc/fluent-bit/fluent-bit.conf -Raw) -replace 'docker', 'cri' | Set-Content C:/etc/fluent-bit/fluent-bit.conf
}

# Start telegraf only in sidecar scraping mode
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/windows/setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Write-Host ('Creating folder structure')
Write-Host ('Installing Fluent Bit');

try {
$fluentBitUri='https://github.com/microsoft/OMS-docker/releases/download/winakslogagent/td-agent-bit-1.4.0-win64.zip'
$fluentBitUri='https://fluentbit.io/releases/1.7/td-agent-bit-1.7.8-win64.zip'
Invoke-WebRequest -Uri $fluentBitUri -OutFile /installation/td-agent-bit.zip
Expand-Archive -Path /installation/td-agent-bit.zip -Destination /installation/fluent-bit
Move-Item -Path /installation/fluent-bit/*/* -Destination /opt/fluent-bit/ -ErrorAction SilentlyContinue
Expand Down