From 67160fb76f7a1bdc40566a9fbd11bf066615f6be Mon Sep 17 00:00:00 2001 From: Ladislav Andel Date: Fri, 26 Jun 2026 09:13:16 +0200 Subject: [PATCH] feat(logger): GDC_LOGGING_APPENDER=CONSOLE routes splunk channel to stdout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When GDC_LOGGING_APPENDER=CONSOLE is set, the brick's splunk-shaped log channel writes to STDOUT instead of constructing a RemoteSyslogLogger to NODE_NAME:514. Default SYSLOG preserves the existing behavior. This mirrors the appender pattern adopted by Bear webapp services and lets Alloy scrape pod stdout natively (Loki-native ingestion) without going through the host rsyslog → /mnt/log/gdc-ruby hop. JIRA: GRIF-233 --- .../bricks/middleware/logger_middleware.rb | 11 +++-- .../middleware/logger_middleware_spec.rb | 40 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/lib/gooddata/bricks/middleware/logger_middleware.rb b/lib/gooddata/bricks/middleware/logger_middleware.rb index 997d30335..967fefe2d 100644 --- a/lib/gooddata/bricks/middleware/logger_middleware.rb +++ b/lib/gooddata/bricks/middleware/logger_middleware.rb @@ -53,9 +53,14 @@ def call(params) unless params['NO_SPLUNK_LOGGING'] && params['NO_SPLUNK_LOGGING'].to_b GoodData.logger.info "Statistics collecting is turned ON. All the data is anonymous." - # NODE_NAME is set up by k8s execmgr - syslog_node = ENV['NODE_NAME'] - splunk_file_logger = syslog_node ? RemoteSyslogLogger.new(syslog_node, 514, program: "lcm_ruby_brick", facility: 'local2') : Logger.new(STDOUT) + logging_appender = ENV['GDC_LOGGING_APPENDER'] || 'SYSLOG' + splunk_file_logger = if logging_appender == 'CONSOLE' + Logger.new(STDOUT) + else + # NODE_NAME is set up by k8s execmgr + syslog_node = ENV['NODE_NAME'] + syslog_node ? RemoteSyslogLogger.new(syslog_node, 514, program: "lcm_ruby_brick", facility: 'local2') : Logger.new(STDOUT) + end splunk_logger = SplunkLoggerDecorator.new splunk_file_logger splunk_logger.level = params['SPLUNK_LOG_LEVEL'] || GoodData::DEFAULT_SPLUNKLOG_LEVEL splunk_logger = splunk_logger.extend(ContextLoggerDecorator) diff --git a/spec/unit/bricks/middleware/logger_middleware_spec.rb b/spec/unit/bricks/middleware/logger_middleware_spec.rb index f847bd658..b281157ba 100644 --- a/spec/unit/bricks/middleware/logger_middleware_spec.rb +++ b/spec/unit/bricks/middleware/logger_middleware_spec.rb @@ -100,6 +100,46 @@ end end + context 'when GDC_LOGGING_APPENDER is CONSOLE' do + let(:params) { { it_does: 'not matter' } } + + around do |example| + original_appender = ENV['GDC_LOGGING_APPENDER'] + ENV['GDC_LOGGING_APPENDER'] = 'CONSOLE' + example.run + ENV['GDC_LOGGING_APPENDER'] = original_appender + end + + it 'does not create a remote syslog forwarder' do + ENV['NODE_NAME'] = '12.12.12.12' + expect(RemoteSyslogLogger).not_to receive(:new) + subject.call(params) + end + + it 'still registers the splunk logger channel' do + expect(GoodData).to receive(:splunk_logging_on).with(splunk_logger) + subject.call(params) + end + end + + context 'when GDC_LOGGING_APPENDER is SYSLOG' do + let(:params) { { it_does: 'not matter' } } + let(:node_name) { '12.12.12.12' } + + around do |example| + original_appender = ENV['GDC_LOGGING_APPENDER'] + ENV['GDC_LOGGING_APPENDER'] = 'SYSLOG' + example.run + ENV['GDC_LOGGING_APPENDER'] = original_appender + end + + it 'creates a remote syslog forwarder' do + ENV['NODE_NAME'] = node_name + expect(RemoteSyslogLogger).to receive(:new).with(node_name, 514, program: 'lcm_ruby_brick', facility: 'local2') + subject.call(params) + end + end + context 'GDC_LOG_LEVEL' do let(:params) { { 'GDC_LOG_LEVEL' => log_level } }