logstash-input-gitlog 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: daf7dedeb82b1cbb34dbab8ca35ceb8ee31e3c0a1a2e19d02361526c5e5a3f11
4
+ data.tar.gz: 5bc12f97dc55ac75fdf46f0432c92fc1eed9ef3d9b44e606bbbb94a18da75f03
5
+ SHA512:
6
+ metadata.gz: 1c9936ac82f49ca5b183f6b7a4d8ce53964cd0c87c6a88e7b394ee69a86552b0860beaafbb4834917454f60092794a512541d3ae9655285ec94e39996a9068ab
7
+ data.tar.gz: 014f678a16b63cbd9e0aa471d7d350c25371d3c8bdee49296ea3384422c7869520d651e48d37e63f9fc58fcac8db0e87fc3de22d7a2687c9189f65449348f1fc
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ - Plugin created with the logstash plugin generator
@@ -0,0 +1,10 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * Ry Biesemeyer - ry.biesemeyer@elastic.co
6
+
7
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
8
+ Logstash, and you aren't on the list above and want to be, please let us know
9
+ and we'll make sure you're here. Contributions from folks like you are what make
10
+ open source awesome.
@@ -0,0 +1,2 @@
1
+ # logstash-input-gitlog
2
+ Example input plugin. This should help bootstrap your effort to write your own input plugin!
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Licensed under the Apache License, Version 2.0 (the "License");
2
+ you may not use this file except in compliance with the License.
3
+ You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
@@ -0,0 +1,92 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
+
5
+ It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
6
+
7
+ # Caveat: 0.x
8
+
9
+ This plugin is a skunkworks proof-of-concept.
10
+
11
+ It is known to be incompatible with other Logstash plugins, notably `logstash-output-email` and `logstash-output-imap`, which both have a dependency conflict regarding the `mime-type` gem; you will need to uninstall these plugins before using this project.
12
+
13
+ ## Documentation
14
+
15
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
16
+
17
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
18
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
19
+
20
+ ## Need Help?
21
+
22
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
23
+
24
+ ## Developing
25
+
26
+ ### 1. Plugin Developement and Testing
27
+
28
+ #### Code
29
+ - To get started, you'll need JRuby with the Bundler gem installed.
30
+
31
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
32
+
33
+ - Install dependencies
34
+ ```sh
35
+ bundle install
36
+ ```
37
+
38
+ #### Test
39
+
40
+ - Update your dependencies
41
+
42
+ ```sh
43
+ bundle install
44
+ ```
45
+
46
+ - Run tests
47
+
48
+ ```sh
49
+ bundle exec rspec
50
+ ```
51
+
52
+ ### 2. Running your unpublished Plugin in Logstash
53
+
54
+ #### 2.1 Run in a local Logstash clone
55
+
56
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
57
+ ```ruby
58
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
59
+ ```
60
+ - Install plugin
61
+ ```sh
62
+ bin/logstash-plugin install --no-verify
63
+ ```
64
+ - Run Logstash with your plugin
65
+ ```sh
66
+ bin/logstash -e 'filter {awesome {}}'
67
+ ```
68
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
69
+
70
+ #### 2.2 Run in an installed Logstash
71
+
72
+ You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
73
+
74
+ - Build your plugin gem
75
+ ```sh
76
+ gem build logstash-filter-awesome.gemspec
77
+ ```
78
+ - Install the plugin from the Logstash home
79
+ ```sh
80
+ bin/logstash-plugin install /your/local/plugin/logstash-filter-awesome.gem
81
+ ```
82
+ - Start Logstash and proceed to test the plugin
83
+
84
+ ## Contributing
85
+
86
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
87
+
88
+ Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
89
+
90
+ It is more important to the community that you are able to contribute.
91
+
92
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,161 @@
1
+ # encoding: utf-8
2
+ require "logstash/inputs/base"
3
+ require "logstash/namespace"
4
+ require 'set'
5
+
6
+ require "rjgit"
7
+
8
+ require 'java'
9
+
10
+ # Generate a repeating message.
11
+ #
12
+ # This plugin is intented only as an example.
13
+
14
+ class LogStash::Inputs::Gitlog < LogStash::Inputs::Base
15
+
16
+ import 'org.eclipse.jgit.revwalk.RevWalk'
17
+ import 'org.eclipse.jgit.revwalk.RevSort'
18
+
19
+ config_name "gitlog"
20
+
21
+ # If undefined, Logstash will complain, even if codec is unused.
22
+ default :codec, "plain"
23
+
24
+ config :path, :validate => :string, :required => true
25
+
26
+ config :head, :validate => :string, :default => 'master'
27
+
28
+ config :limit, :validate => :number, :default => nil
29
+
30
+ config :diff, :validate => :boolean, :default => false
31
+
32
+ config :delay, :validate => :number, :default => nil
33
+
34
+
35
+ public
36
+ def register
37
+ # ensure that configured `@path` points to a real file path
38
+ unless File.exists?(@path)
39
+ logger.error("path not found: `#{@path}`")
40
+ fail "path not found: `#{@path}`"
41
+ end
42
+
43
+ # ensure that configured `@path` points to a valid git repository
44
+ @repo = RJGit::Repo.new(@path)
45
+ unless @repo.valid?
46
+ logger.error("not a valid git repository `#{@path}`")
47
+ fail "not a valid git repository `#{@path}`"
48
+ end
49
+
50
+ # ensure that configured `@head` is a valid head reference
51
+ branch_head = @repo.jrepo.resolve(@head)
52
+ if branch_head.nil?
53
+ logger.error("not a valid branch, tag, or commit reference `#{@head}`", path: @path)
54
+ fail "not a valid branch, tag, or commit reference `#{@head}`"
55
+ else
56
+ logger.debug("resolved head `#{@head}` to `#{branch_head.get_name}`", path: @path)
57
+ end
58
+ end # def register
59
+
60
+ def run(queue)
61
+ # delay-tactic enables testability
62
+ unless @delay.nil?
63
+ logger.info("delaying for `#{delay}` seconds...")
64
+ sleep(@delay)
65
+ end
66
+
67
+ unprocessed_commits = Set.new
68
+
69
+ commits.each do |commit|
70
+ # we can abort the loop if stop? becomes true
71
+ break if stop?
72
+
73
+ hevent = {
74
+ "id" => commit.id,
75
+ "parents" => commit.parents.map(&:id),
76
+ "actor" => {
77
+ "name" => commit.actor.name,
78
+ "email" => commit.actor.email,
79
+ },
80
+ "committer" => {
81
+ "name" => commit.committer.name,
82
+ "email" => commit.committer.email,
83
+ },
84
+ "authored_date" => commit.authored_date,
85
+ "committed_date" => commit.committed_date,
86
+ "message" => commit.message,
87
+ "short_message" => commit.short_message,
88
+ }
89
+
90
+ # add diffs only if enabled
91
+ hevent["diffs"]= commit.diffs if @diffs
92
+
93
+ logger.trace("Created event from commit", event: hevent)
94
+
95
+ event = LogStash::Event.new(hevent)
96
+
97
+ decorate(event)
98
+ queue << event
99
+
100
+ # dragons: tracking unprocessed commits in this manner requires
101
+ # topographic children-before-parents processing.
102
+ commit.parents.each do |parent|
103
+ unprocessed_commits.add(parent.id)
104
+ end
105
+ unprocessed_commits.delete(commit.id)
106
+ end # loop
107
+
108
+ unless unprocessed_commits.empty?
109
+ logger.debug("unprocessed commits", commits: unprocessed_commits)
110
+ end
111
+ end # def run
112
+
113
+
114
+ def stop
115
+ # nothing to do in this case so it is not necessary to define stop
116
+ # examples of common "stop" tasks:
117
+ # * close sockets (unblocking blocking reads/accepts)
118
+ # * cleanup temporary files
119
+ # * terminate spawned threads
120
+ end
121
+
122
+ private
123
+
124
+ # returns a lazy Enumerator that will walk upwards on the repo from the configured `@head`,
125
+ # following all parents and respecting `@limit`.
126
+ #
127
+ # @return [Enumerator::Lazy<RJGit::Commit>] if no block given
128
+ # @yieldparam commit [RJGit::Commit]
129
+ # @yieldreturn [Object]
130
+ def commits
131
+ return enum_for(:commits).lazy unless block_given?
132
+
133
+ jrepo = @repo.jrepo
134
+ objhead = jrepo.resolve(@head)
135
+ walk = RevWalk.new(jrepo)
136
+
137
+ # dragons: the way unprocessed children are tracked requires TOPO ordering to be enabled
138
+ walk.sort(RevSort::TOPO, true)
139
+ walk.sort(RevSort::COMMIT_TIME_DESC, true)
140
+
141
+ root = walk.parse_commit(objhead)
142
+ walk.mark_start(root)
143
+
144
+ loop.with_index do |_, index|
145
+ logger.debug("crawling commits", index: index) if (index%1000).zero?
146
+
147
+ if @limit && (index >= @limit)
148
+ logger.info("crawl limit reached", index: index)
149
+ break
150
+ end
151
+
152
+ jcommit = walk.next
153
+ if jcommit.nil?
154
+ logger.info("crawl complete", index: index)
155
+ break
156
+ end
157
+
158
+ yield(RJGit::Commit.new(@repo, jcommit))
159
+ end
160
+ end
161
+ end # class LogStash::Inputs::Gitlog
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-input-gitlog'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = 'Logstash Events from Git History'
6
+ s.homepage = 'https://github.com/yaauie/logstash-input-gitlog'
7
+ s.authors = ['Ry Biesemeyer']
8
+ s.email = 'ry.biesemeyer@elastic.co'
9
+ s.require_paths = ['lib']
10
+
11
+ # Files
12
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
13
+ # Tests
14
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
15
+
16
+ # Special flag to let us know this is actually a logstash plugin
17
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
18
+
19
+ # Gem dependencies
20
+ s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
21
+ s.add_runtime_dependency 'logstash-codec-plain'
22
+ s.add_runtime_dependency 'stud', '>= 0.0.22'
23
+ s.add_runtime_dependency 'rjgit', '~> 4.10.0'
24
+ s.add_development_dependency 'logstash-devutils', '>= 0.0.16'
25
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/inputs/gitlog"
4
+
5
+ describe LogStash::Inputs::Gitlog do
6
+
7
+ it_behaves_like "an interruptible input plugin" do
8
+
9
+ # assumes that the local code is running from its own repository, with a valid reference `master`
10
+ # configure with 1s delay, since it runs too quickly for underlying test to validate that it can be interrupted
11
+ let(:git_repo_path) { File.expand_path("../../../", __FILE__) }
12
+ let(:config) { { "path" => git_repo_path, "delay" => 1} }
13
+ end
14
+
15
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-input-gitlog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ry Biesemeyer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ name: logstash-core-plugin-api
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ name: logstash-codec-plain
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.0.22
47
+ name: stud
48
+ prerelease: false
49
+ type: :runtime
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.22
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 4.10.0
61
+ name: rjgit
62
+ prerelease: false
63
+ type: :runtime
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 4.10.0
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 0.0.16
75
+ name: logstash-devutils
76
+ prerelease: false
77
+ type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.16
83
+ description:
84
+ email: ry.biesemeyer@elastic.co
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - CHANGELOG.md
90
+ - CONTRIBUTORS
91
+ - DEVELOPER.md
92
+ - Gemfile
93
+ - LICENSE
94
+ - README.md
95
+ - lib/logstash/inputs/gitlog.rb
96
+ - logstash-input-gitlog.gemspec
97
+ - spec/inputs/gitlog_spec.rb
98
+ homepage: https://github.com/yaauie/logstash-input-gitlog
99
+ licenses:
100
+ - Apache-2.0
101
+ metadata:
102
+ logstash_plugin: 'true'
103
+ logstash_group: input
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.6.11
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Logstash Events from Git History
124
+ test_files:
125
+ - spec/inputs/gitlog_spec.rb