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

Cache groups #6

Merged
merged 2 commits into from
Dec 4, 2024
Merged
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
29 changes: 21 additions & 8 deletions lib/logstash/inputs/cloudwatch_logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class LogStash::Inputs::CloudWatch_Logs < LogStash::Inputs::Base
# seconds before now to read back from.
config :start_position, :default => 'beginning'


# def register
public
def register
Expand All @@ -60,9 +59,9 @@ def register
@sincedb = {}

check_start_position_validity

Aws::ConfigService::Client.new(aws_options_hash)
@cloudwatch = Aws::CloudWatchLogs::Client.new(aws_options_hash)
@tag_cache = {}
Aws::ConfigService::Client.new(aws_options_hash)

if @sincedb_path.nil?
if settings
Expand Down Expand Up @@ -203,12 +202,19 @@ def process_group(group)
@priority << group
end #def process_group

# def process_log
def fetch_tags(log_group_name)
if @tag_cache.key?(log_group_name)
return @tag_cache[log_group_name][:tags]
else
tags = fetch_tags_from_cloudwatch(log_group_name)
@tag_cache[log_group_name] = { tags: tags}
return tags
end
end

private
def process_log(log, group)
tag_params = {
:log_group_name => group
}
def fetch_tags_from_cloudwatch(log_group_name)
tag_params = { log_group_name: log_group_name}
response = @cloudwatch.list_tags_log_group(tag_params)
tags = response.tags

Expand All @@ -219,6 +225,13 @@ def process_log(log, group)
tags.delete(key)
end
end
tags
end

# def process_log
private
def process_log(log, group)
tags = fetch_tags(group)

@logger.debug("processing_log #{log}")
@codec.decode(log.message.to_str) do |event|
Expand Down
4 changes: 2 additions & 2 deletions logstash-input-cloudwatch_logs.gemspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Gem::Specification.new do |s|

s.name = 'logstash-input-cloudwatch_logs'
s.version = '1.1.0'
s.version = '1.1.1'
s.licenses = ['Apache-2.0']
s.summary = 'Stream events from CloudWatch Logs.'
s.description = 'This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program'
s.homepage = ''
s.require_paths = ['lib']

s.authors = 'Cloud-gov'
# Files
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']

Expand Down
Loading