Class: Fluent::Plugin::CloudwatchLogsInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_cloudwatch_logs.rb

Constant Summary collapse

DEFAULT_STORAGE_TYPE =
'local'

Instance Method Summary collapse

Constructor Details

#initializeCloudwatchLogsInput

Returns a new instance of CloudwatchLogsInput.



65
66
67
68
69
70
# File 'lib/fluent/plugin/in_cloudwatch_logs.rb', line 65

def initialize
  super

  @parser = nil
  require 'aws-sdk-cloudwatchlogs'
end

Instance Method Details

#configure(conf) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fluent/plugin/in_cloudwatch_logs.rb', line 72

def configure(conf)
  compat_parameters_convert(conf, :parser)
  super
  configure_parser(conf)

  @start_time = (Time.strptime(@start_time, @time_range_format).to_f * 1000).floor if @start_time
  @end_time = (Time.strptime(@end_time, @time_range_format).to_f * 1000).floor if @end_time
  if @start_time && @end_time && (@end_time < @start_time)
    raise Fluent::ConfigError, "end_time(#{@end_time}) should be greater than start_time(#{@start_time})."
  end
  @next_token_storage = storage_create(usage: 'store_next_tokens', conf: config, default_type: DEFAULT_STORAGE_TYPE)
end

#shutdownObject



142
143
144
145
# File 'lib/fluent/plugin/in_cloudwatch_logs.rb', line 142

def shutdown
  @finished = true
  super
end

#startObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/fluent/plugin/in_cloudwatch_logs.rb', line 85

def start
  super
  options = {}
  options[:region] = @region if @region
  options[:endpoint] = @endpoint if @endpoint
  options[:ssl_verify_peer] = @ssl_verify_peer
  options[:http_proxy] = @http_proxy if @http_proxy

  if @aws_use_sts
    Aws.config[:region] = options[:region]
    credentials_options = {
      role_arn: @aws_sts_role_arn,
      role_session_name: @aws_sts_session_name,
      external_id: @aws_sts_external_id,
      policy: @aws_sts_policy,
      duration_seconds: @aws_sts_duration_seconds
    }
    credentials_options[:sts_endpoint_url] = @aws_sts_endpoint_url if @aws_sts_endpoint_url
    if @region and @aws_sts_endpoint_url
      credentials_options[:client] = Aws::STS::Client.new(:region => @region, endpoint: @aws_sts_endpoint_url)
    elsif @region
      credentials_options[:client] = Aws::STS::Client.new(:region => @region)
    end
    options[:credentials] = Aws::AssumeRoleCredentials.new(credentials_options)
  elsif @web_identity_credentials
    c = @web_identity_credentials
    credentials_options = {}
    credentials_options[:role_arn] = c.role_arn
    credentials_options[:role_session_name] = c.role_session_name
    credentials_options[:web_identity_token_file] = c.web_identity_token_file
    credentials_options[:policy] = c.policy if c.policy
    credentials_options[:duration_seconds] = c.duration_seconds if c.duration_seconds
    if @region
      credentials_options[:client] = Aws::STS::Client.new(:region => @region)
    end
    options[:credentials] = Aws::AssumeRoleWebIdentityCredentials.new(credentials_options)
  elsif @aws_ecs_authentication
    # collect AWS credential from ECS relative uri ENV variable
    aws_container_credentials_relative_uri = ENV["AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"]
    options[:credentials] = Aws::ECSCredentials.new({credential_path: aws_container_credentials_relative_uri}).credentials
  else
    options[:credentials] = Aws::Credentials.new(@aws_key_id, @aws_sec_key) if @aws_key_id && @aws_sec_key
  end

  @logs = Aws::CloudWatchLogs::Client.new(options)

  @finished = false
  thread_create(:in_cloudwatch_logs_runner, &method(:run))

  @json_handler = case @json_handler
                  when :yajl
                    Yajl
                  when :json
                    JSON
                  end
end

#state_key_for(log_stream_name, log_group_name = nil) ⇒ Object

No private for testing



148
149
150
151
152
153
154
155
156
# File 'lib/fluent/plugin/in_cloudwatch_logs.rb', line 148

def state_key_for(log_stream_name, log_group_name = nil)
  if log_group_name && log_stream_name
    "#{@state_file}_#{log_group_name.gsub(File::SEPARATOR, '-')}_#{log_stream_name.gsub(File::SEPARATOR, '-')}"
  elsif log_stream_name
    "#{@state_file}_#{log_stream_name.gsub(File::SEPARATOR, '-')}"
  else
    @state_file
  end
end