rb-fluent-plugin-cloudwatch-logs 0.7.1.pre.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,105 @@
1
+ require 'test/unit'
2
+ require 'mocha/test_unit'
3
+ require 'fluent/test'
4
+ require 'securerandom'
5
+
6
+ require 'aws-sdk-cloudwatchlogs'
7
+
8
+ module CloudwatchLogsTestHelper
9
+ private
10
+ def logs
11
+ options = {}
12
+ options[:credentials] = Aws::Credentials.new(ENV['aws_key_id'], ENV['aws_sec_key']) if ENV['aws_key_id'] && ENV['aws_sec_key']
13
+ options[:region] = ENV['region'] if ENV['region']
14
+ options[:endpoint] = ENV['endpoint'] if ENV['endpoint']
15
+ options[:http_proxy] = ENV['http_proxy'] if ENV['http_proxy']
16
+ @logs ||= Aws::CloudWatchLogs::Client.new(options)
17
+ end
18
+
19
+ def log_group_name
20
+ @log_group_name ||= "fluent-plugin-cloudwatch-test-#{Time.now.to_f}"
21
+ end
22
+
23
+ def aws_key_id
24
+ "aws_key_id #{ENV['aws_key_id']}" if ENV['aws_key_id']
25
+ end
26
+
27
+ def aws_sec_key
28
+ "aws_sec_key #{ENV['aws_sec_key']}" if ENV['aws_sec_key']
29
+ end
30
+
31
+ def region
32
+ "region #{ENV['region']}" if ENV['region']
33
+ end
34
+
35
+ def endpoint
36
+ "endpoint #{ENV['endpoint']}" if ENV['endpoint']
37
+ end
38
+
39
+ def config_elementify(conf)
40
+ conf.split(' ').each_slice(2).map{|k, v| {k => v}}.first
41
+ end
42
+
43
+ def log_stream_name(log_stream_name_prefix = nil)
44
+ if !@log_stream_name
45
+ new_log_stream(log_stream_name_prefix)
46
+ end
47
+ @log_stream_name
48
+ end
49
+
50
+ def new_log_stream(log_stream_name_prefix = nil)
51
+ uuid = SecureRandom.uuid
52
+ @log_stream_name = log_stream_name_prefix ? log_stream_name_prefix + uuid : uuid
53
+ end
54
+
55
+ def get_log_group_tags(name = nil)
56
+ name ||= log_group_name
57
+ logs.list_tags_log_group(log_group_name: name).tags
58
+ end
59
+
60
+ def get_log_group_retention_days(name = nil)
61
+ name ||= log_group_name
62
+ logs.describe_log_groups(log_group_name_prefix: name, limit: 1).log_groups.first.retention_in_days
63
+ end
64
+
65
+ def clear_log_group
66
+ [log_group_name, fluentd_tag].each do |name|
67
+ begin
68
+ logs.delete_log_group(log_group_name: name)
69
+ rescue Aws::CloudWatchLogs::Errors::ResourceNotFoundException
70
+ # pass
71
+ end
72
+ end
73
+ end
74
+
75
+ def fluentd_tag
76
+ @fluentd_tag ||= "fluent.plugin.cloudwatch.test.#{Time.now.to_f}"
77
+ end
78
+
79
+ def create_log_stream()
80
+ begin
81
+ logs.create_log_group(log_group_name: log_group_name)
82
+ rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException
83
+ # pass
84
+ end
85
+
86
+ begin
87
+ logs.create_log_stream(log_group_name: log_group_name, log_stream_name: log_stream_name)
88
+ rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException
89
+ # pass
90
+ end
91
+ end
92
+
93
+ def get_log_events(group = log_group_name, stream = log_stream_name)
94
+ logs.get_log_events(log_group_name: group, log_stream_name: stream).events
95
+ end
96
+
97
+ def put_log_events(events)
98
+ args = {
99
+ log_events: events,
100
+ log_group_name: log_group_name,
101
+ log_stream_name: log_stream_name,
102
+ }
103
+ logs.put_log_events(args)
104
+ end
105
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rb-fluent-plugin-cloudwatch-logs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.1.pre.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryota Arai
8
+ - Other People
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2019-01-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 0.14.15
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 0.14.15
28
+ - !ruby/object:Gem::Dependency
29
+ name: aws-sdk-cloudwatchlogs
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: memory_profiler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.6'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.6'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: test-unit
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: mocha
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ description:
113
+ email:
114
+ - ryota.arai@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - ISSUE_TEMPLATE.md
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - example/fluentd.conf
126
+ - fluent-plugin-cloudwatch-logs.gemspec
127
+ - lib/fluent/plugin/cloudwatch/logs.rb
128
+ - lib/fluent/plugin/cloudwatch/logs/version.rb
129
+ - lib/fluent/plugin/in_cloudwatch_logs.rb
130
+ - lib/fluent/plugin/out_cloudwatch_logs.rb
131
+ - test/plugin/test_in_cloudwatch_logs.rb
132
+ - test/plugin/test_out_cloudwatch_logs.rb
133
+ - test/test_helper.rb
134
+ homepage: https://github.com/redbubble/fluent-plugin-cloudwatch-logs
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">"
150
+ - !ruby/object:Gem::Version
151
+ version: 1.3.1
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.7.6
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: CloudWatch Logs Plugin for Fluentd with memory profiling
158
+ test_files:
159
+ - test/plugin/test_in_cloudwatch_logs.rb
160
+ - test/plugin/test_out_cloudwatch_logs.rb
161
+ - test/test_helper.rb