logstash-input-google_pubsub 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5833affff693fc86005d9fd0f29215e8eeb9f154
4
- data.tar.gz: f65d91acd4a6c805a3587558a7ef8c252c1435ed
3
+ metadata.gz: 7b261bb9333fce81b2dc53f8474d332a16de4519
4
+ data.tar.gz: fee0a4acafa699ced1feb58cedfaeaea9bcd1fa8
5
5
  SHA512:
6
- metadata.gz: 96b4e044b16625abc380a4372da3b3c63dd856b7070c7e11ff255a73acdc586054be168d3cd7f66e53a7ca352c2663bf29989c850e00a535ea4472cedceda87b
7
- data.tar.gz: 2ee4c5fc0519b9689618b5dfab52232389e4e6c900d4ea632dff96577f948e84b411c7b9f04a68222a2d47aec8be22868bd196456c7c23c67bfdd07d95543d14
6
+ metadata.gz: d54ac43c05cc10acce0a696e067a681bb1155ed3388f5f2b47d99e936c337259086eb32944793405e84163e71246b25eaf70e63aa8dab8b1ccd7c6b647044ff5
7
+ data.tar.gz: e54671aae537ff2cd6176f4c38a61912ab0be6fdc2a3ad91d544eb375ecb3179b66a33344fe69744d29373b89e00a45a98f716645a913ac1e788126cc9d68b8e
@@ -22,10 +22,106 @@ require "logstash/namespace"
22
22
  # Google deps
23
23
  require "google/api_client"
24
24
 
25
- # Generate a repeating message.
25
+ # This is a https://github.com/elastic/logstash[Logstash] input plugin for
26
+ # https://cloud.google.com/pubsub/[Google Pub/Sub]. The plugin can subscribe
27
+ # to a topic and ingest messages.
28
+ #
29
+ # The main motivation behind the development of this plugin was to ingest
30
+ # https://cloud.google.com/logging/[Stackdriver Logging] messages via the
31
+ # https://cloud.google.com/logging/docs/export/using_exported_logs[Exported Logs]
32
+ # feature of Stackdriver Logging.
33
+ #
34
+ # ==== Prerequisites
35
+ #
36
+ # You must first create a Google Cloud Platform project and enable the the
37
+ # Google Pub/Sub API. If you intend to use the plugin ingest Stackdriver Logging
38
+ # messages, you must also enable the Stackdriver Logging API and configure log
39
+ # exporting to Pub/Sub. There is plentiful information on
40
+ # https://cloud.google.com/ to get started:
41
+ #
42
+ # - Google Cloud Platform Projects and https://cloud.google.com/docs/overview/[Overview]
43
+ # - Google Cloud Pub/Sub https://cloud.google.com/pubsub/[documentation]
44
+ # - Stackdriver Logging https://cloud.google.com/logging/[documentation]
45
+ #
46
+ # ==== Cloud Pub/Sub
47
+ #
48
+ # Currently, this module requires you to create a `topic` manually and specify
49
+ # it in the logstash config file. You must also specify a `subscription`, but
50
+ # the plugin will attempt to create the pull-based `subscription` on its own.
51
+ #
52
+ # All messages received from Pub/Sub will be converted to a logstash `event`
53
+ # and added to the processing pipeline queue. All Pub/Sub messages will be
54
+ # `acknowledged` and removed from the Pub/Sub `topic` (please see more about
55
+ # https://cloud.google.com/pubsub/overview#concepts)[Pub/Sub concepts].
56
+ #
57
+ # It is generally assumed that incoming messages will be in JSON and added to
58
+ # the logstash `event` as-is. However, if a plain text message is received, the
59
+ # plugin will return the raw text in as `raw_message` in the logstash `event`.
60
+ #
61
+ # ==== Authentication
62
+ #
63
+ # You have two options for authentication depending on where you run Logstash.
64
+ #
65
+ # 1. If you are running Logstash outside of Google Cloud Platform, then you will
66
+ # need to create a Google Cloud Platform Service Account and specify the full
67
+ # path to the JSON private key file in your config. You must assign sufficient
68
+ # roles to the Service Account to create a subscription and to pull messages
69
+ # from the subscription. Learn more about GCP Service Accounts and IAM roles
70
+ # here:
71
+ #
72
+ # - Google Cloud Platform IAM https://cloud.google.com/iam/[overview]
73
+ # - Creating Service Accounts https://cloud.google.com/iam/docs/creating-managing-service-accounts[overview]
74
+ # - Granting Roles https://cloud.google.com/iam/docs/granting-roles-to-service-accounts[overview]
75
+ #
76
+ # 1. If you are running Logstash on a Google Compute Engine instance, you may opt
77
+ # to use Application Default Credentials. In this case, you will not need to
78
+ # specify a JSON private key file in your config.
79
+ #
80
+ # ==== Stackdriver Logging (optional)
81
+ #
82
+ # If you intend to use the logstash plugin for Stackdriver Logging message
83
+ # ingestion, you must first manually set up the Export option to Cloud Pub/Sub and
84
+ # the manually create the `topic`. Please see the more detailed instructions at,
85
+ # https://cloud.google.com/logging/docs/export/using_exported_logs [Exported Logs]
86
+ # and ensure that the https://cloud.google.com/logging/docs/export/configure_export#manual-access-pubsub[necessary permissions]
87
+ # have also been manually configured.
88
+ #
89
+ # Logging messages from Stackdriver Logging exported to Pub/Sub are received as
90
+ # JSON and converted to a logstash `event` as-is in
91
+ # https://cloud.google.com/logging/docs/export/using_exported_logs#log_entries_in_google_pubsub_topics[this format].
92
+ #
93
+ # ==== Sample Configuration
94
+ #
95
+ # Below is a copy of the included `example.conf-tmpl` file that shows a basic
96
+ # configuration for this plugin.
97
+ #
98
+ # [source,ruby]
99
+ # ----------------------------------
100
+ # input {
101
+ # google_pubsub {
102
+ # # Your GCP project id (name)
103
+ # project_id => "my-project-1234"
104
+ #
105
+ # # The topic name below is currently hard-coded in the plugin. You
106
+ # # must first create this topic by hand and ensure you are exporting
107
+ # # logging to this pubsub topic.
108
+ # topic => "logstash-input-dev"
109
+ #
110
+ # # The subscription name is customizeable. The plugin will attempt to
111
+ # # create the subscription (but use the hard-coded topic name above).
112
+ # subscription => "logstash-sub"
113
+ #
114
+ # # If you are running logstash within GCE, it will use
115
+ # # Application Default Credentials and use GCE's metadata
116
+ # # service to fetch tokens. However, if you are running logstash
117
+ # # outside of GCE, you will need to specify the service account's
118
+ # # JSON key file below.
119
+ # #json_key_file => "/home/erjohnso/pkey.json"
120
+ # }
121
+ # }
122
+ # output { stdout { codec => rubydebug } }
123
+ # ----------------------------------
26
124
  #
27
- # This plugin is intented only as an example.
28
-
29
125
  class LogStash::Inputs::GooglePubSub < LogStash::Inputs::Base
30
126
  config_name "google_pubsub"
31
127
 
@@ -51,22 +147,22 @@ class LogStash::Inputs::GooglePubSub < LogStash::Inputs::Base
51
147
  private
52
148
  def request(options)
53
149
  begin
54
- @logger.info("Sending an API request")
150
+ @logger.debug("Sending an API request")
55
151
  result = @client.execute(options)
56
152
  rescue ArgumentError => e
57
- @logger.info("Authorizing...")
153
+ @logger.debug("Authorizing...")
58
154
  @client.authorization.fetch_access_token!
59
- @logger.info("...authorized")
155
+ @logger.debug("...authorized")
60
156
  request(options)
61
157
  rescue Faraday::TimeoutError => e
62
- @logger.info("Request timeout, re-trying request")
158
+ @logger.debug("Request timeout, re-trying request")
63
159
  request(options)
64
160
  end
65
161
  end # def request
66
162
 
67
163
  public
68
164
  def register
69
- @logger.info("Registering Google PubSub Input: project_id=#{@project_id}, topic=#{@topic}, subscription=#{@subscription}")
165
+ @logger.debug("Registering Google PubSub Input: project_id=#{@project_id}, topic=#{@topic}, subscription=#{@subscription}")
70
166
  @topic = "projects/#{@project_id}/topics/#{@topic}"
71
167
  @subscription = "projects/#{@project_id}/subscriptions/#{@subscription}"
72
168
  @subscription_exists = false
@@ -86,7 +182,7 @@ class LogStash::Inputs::GooglePubSub < LogStash::Inputs::Base
86
182
  # - googleauth ~> 0.3 requires multi_json 1.11.0 that conflicts
87
183
  # with logstash-2.3.2's multi_json 1.11.3
88
184
  if @json_key_file
89
- @logger.info("Authorizing with JSON key file: #{@json_key_file}")
185
+ @logger.debug("Authorizing with JSON key file: #{@json_key_file}")
90
186
  file_path = File.expand_path(@json_key_file)
91
187
  key_json = File.open(file_path, "r", &:read)
92
188
  key_json = JSON.parse(key_json)
@@ -116,7 +212,7 @@ class LogStash::Inputs::GooglePubSub < LogStash::Inputs::Base
116
212
  def run(queue)
117
213
  # Attempt to create the subscription
118
214
  if !@subscription_exists
119
- @logger.info("Creating subscription #{subscription}")
215
+ @logger.debug("Creating subscription #{subscription}")
120
216
  result = request(
121
217
  :api_method => @pubsub.projects.subscriptions.create,
122
218
  :parameters => {'name' => @subscription},
@@ -131,7 +227,7 @@ class LogStash::Inputs::GooglePubSub < LogStash::Inputs::Base
131
227
  @subscription_exists = true
132
228
  end # if !@subscription
133
229
 
134
- @logger.info("Pulling messages from sub '#{subscription}'")
230
+ @logger.debug("Pulling messages from sub '#{subscription}'")
135
231
  while !stop?
136
232
  # Pull and queue messages
137
233
  messages = []
@@ -150,7 +246,7 @@ class LogStash::Inputs::GooglePubSub < LogStash::Inputs::Base
150
246
  messages = messages["receivedMessages"]
151
247
  end
152
248
  else
153
- @logger.info("Error pulling messages:'#{result.error_message}'")
249
+ @logger.error("Error pulling messages:'#{result.error_message}'")
154
250
  end
155
251
 
156
252
  if messages
@@ -177,7 +273,7 @@ class LogStash::Inputs::GooglePubSub < LogStash::Inputs::Base
177
273
  }
178
274
  )
179
275
  if result.error?
180
- @logger.info("Error #{result.status}: #{result.error_message}")
276
+ @logger.error("Error #{result.status}: #{result.error_message}")
181
277
  end
182
278
  end # if messages
183
279
  end # loop
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-input-google_pubsub'
3
- s.version = '0.9.0'
3
+ s.version = '1.0.0'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.summary = "Logstash input plugin for Google Cloud Pub/Sub."
6
6
  s.description = "This gem is a Logstash input plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program."
@@ -18,12 +18,12 @@ Gem::Specification.new do |s|
18
18
  s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
19
19
 
20
20
  # Gem dependencies
21
- s.add_runtime_dependency "logstash-core", ">= 2.0.0", "< 3.0.0"
21
+ s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
22
22
  s.add_runtime_dependency 'logstash-codec-plain'
23
23
  s.add_runtime_dependency 'stud', '>= 0.0.22'
24
24
  # Google dependencies
25
25
  # google-api-client >= 0.9 requires ruby2 which is not currently compatible
26
26
  # with JRuby
27
27
  s.add_runtime_dependency 'google-api-client', '~> 0.8.6', '< 0.9'
28
- s.add_development_dependency 'logstash-devutils', '~>0.0', '>= 0.0.16'
28
+ s.add_development_dependency 'logstash-devutils'
29
29
  end
@@ -21,7 +21,7 @@ describe LogStash::Inputs::GooglePubSub do
21
21
  let(:bad1) { { 'topic' => 'foo', 'subscription' => 'bar' } }
22
22
  let(:bad2) { { 'project_id' => 'foo', 'subscription' => 'bar' } }
23
23
  let(:bad3) { { 'project_id' => 'foo', 'topic' => 'bar' } }
24
- let(:config) { { 'project_id' => 'myproj', 'subscription' => 'foo', 'topic' => 'bar', 'json_key_file' => '/home/erjohnso/fake.json' } }
24
+ let(:config) { { 'project_id' => 'myproj', 'subscription' => 'foo', 'topic' => 'bar' } }
25
25
 
26
26
  it "ensures required config options are present" do
27
27
  expect {
@@ -34,12 +34,4 @@ describe LogStash::Inputs::GooglePubSub do
34
34
  plugin = LogStash::Inputs::GooglePubSub.new(bad3)
35
35
  }.to raise_error(LogStash::ConfigurationError)
36
36
  end
37
-
38
- it "validates register vars" do
39
- plugin = LogStash::Inputs::GooglePubSub.new(config)
40
- plugin.register
41
- expect(plugin.topic).to eq("projects/myproj/topics/bar")
42
- expect(plugin.subscription).to eq("projects/myproj/subscriptions/foo")
43
- end
44
-
45
37
  end
metadata CHANGED
@@ -1,65 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-google_pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Johnson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-04 00:00:00.000000000 Z
11
+ date: 2017-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: logstash-core
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: 2.0.0
20
- - - "<"
18
+ version: '1.60'
19
+ - - "<="
21
20
  - !ruby/object:Gem::Version
22
- version: 3.0.0
23
- type: :runtime
21
+ version: '2.99'
22
+ name: logstash-core-plugin-api
24
23
  prerelease: false
24
+ type: :runtime
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 2.0.0
30
- - - "<"
29
+ version: '1.60'
30
+ - - "<="
31
31
  - !ruby/object:Gem::Version
32
- version: 3.0.0
32
+ version: '2.99'
33
33
  - !ruby/object:Gem::Dependency
34
- name: logstash-codec-plain
35
34
  requirement: !ruby/object:Gem::Requirement
36
35
  requirements:
37
36
  - - ">="
38
37
  - !ruby/object:Gem::Version
39
38
  version: '0'
40
- type: :runtime
39
+ name: logstash-codec-plain
41
40
  prerelease: false
41
+ type: :runtime
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
- name: stud
49
48
  requirement: !ruby/object:Gem::Requirement
50
49
  requirements:
51
50
  - - ">="
52
51
  - !ruby/object:Gem::Version
53
52
  version: 0.0.22
54
- type: :runtime
53
+ name: stud
55
54
  prerelease: false
55
+ type: :runtime
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: 0.0.22
61
61
  - !ruby/object:Gem::Dependency
62
- name: google-api-client
63
62
  requirement: !ruby/object:Gem::Requirement
64
63
  requirements:
65
64
  - - "~>"
@@ -68,8 +67,9 @@ dependencies:
68
67
  - - "<"
69
68
  - !ruby/object:Gem::Version
70
69
  version: '0.9'
71
- type: :runtime
70
+ name: google-api-client
72
71
  prerelease: false
72
+ type: :runtime
73
73
  version_requirements: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - "~>"
@@ -79,28 +79,20 @@ dependencies:
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0.9'
81
81
  - !ruby/object:Gem::Dependency
82
- name: logstash-devutils
83
82
  requirement: !ruby/object:Gem::Requirement
84
83
  requirements:
85
- - - "~>"
86
- - !ruby/object:Gem::Version
87
- version: '0.0'
88
84
  - - ">="
89
85
  - !ruby/object:Gem::Version
90
- version: 0.0.16
91
- type: :development
86
+ version: '0'
87
+ name: logstash-devutils
92
88
  prerelease: false
89
+ type: :development
93
90
  version_requirements: !ruby/object:Gem::Requirement
94
91
  requirements:
95
- - - "~>"
96
- - !ruby/object:Gem::Version
97
- version: '0.0'
98
92
  - - ">="
99
93
  - !ruby/object:Gem::Version
100
- version: 0.0.16
101
- description: This gem is a Logstash input plugin required to be installed on top of
102
- the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
103
- gem is not a stand-alone program.
94
+ version: '0'
95
+ description: This gem is a Logstash input plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program.
104
96
  email: erjohnso@google.com
105
97
  executables: []
106
98
  extensions: []
@@ -121,7 +113,7 @@ licenses:
121
113
  metadata:
122
114
  logstash_plugin: 'true'
123
115
  logstash_group: input
124
- post_install_message:
116
+ post_install_message:
125
117
  rdoc_options: []
126
118
  require_paths:
127
119
  - lib
@@ -136,9 +128,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
128
  - !ruby/object:Gem::Version
137
129
  version: '0'
138
130
  requirements: []
139
- rubyforge_project:
140
- rubygems_version: 2.5.1
141
- signing_key:
131
+ rubyforge_project:
132
+ rubygems_version: 2.4.8
133
+ signing_key:
142
134
  specification_version: 4
143
135
  summary: Logstash input plugin for Google Cloud Pub/Sub.
144
136
  test_files: