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

Loki Logstash Plugin #1822

Merged
merged 30 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3159e46
Logstash plugin
adityacs Mar 26, 2020
0994c44
include_labels
adityacs Apr 10, 2020
727bdcb
include_labels
adityacs Apr 10, 2020
88587c1
Removes binary.
cyriltovena Apr 17, 2020
9c9b072
Improve documentation and remove the push path.
cyriltovena Apr 17, 2020
d45c9db
Move to cmd.
cyriltovena Jul 13, 2020
a21605a
Add more precision for jruby.
cyriltovena Jul 13, 2020
87895e9
Update docs/clients/logstash/README.md
cyriltovena Jul 13, 2020
913dbbb
p
cyriltovena Jul 13, 2020
9b9a250
ignore
cyriltovena Jul 13, 2020
1a4de4a
remove ignore file/
cyriltovena Jul 13, 2020
659ca6b
More precision for installing jruby
cyriltovena Jul 13, 2020
c2b33e3
Rename without Grafana
cyriltovena Jul 13, 2020
cbef9a4
A lot of refactoring and testing.
cyriltovena Jul 14, 2020
d10f042
change delay logic
adityacs Jul 15, 2020
26875cb
Fully tested version.
cyriltovena Jul 15, 2020
5a1af98
Merge branch 'loki_logstash_plugin' of github.com:adityacs/loki into …
cyriltovena Jul 15, 2020
1366ef8
Forgot to save merge.
cyriltovena Jul 15, 2020
99f504d
working version.
cyriltovena Jul 15, 2020
4776178
Makefile + easier docker build.
cyriltovena Jul 16, 2020
425d375
adds ci to build logstash image.
cyriltovena Jul 16, 2020
0d2acee
Fix build for logstash.
cyriltovena Jul 16, 2020
37508d1
Adds example with helm charts.
cyriltovena Jul 16, 2020
a8cde47
Fix target to send 10 logs with logstash.
cyriltovena Jul 16, 2020
0a266ec
Improved documentation.
cyriltovena Jul 16, 2020
4ae8cc7
add missing helm add repo for external repo
cyriltovena Jul 16, 2020
c87581a
Review comment.
cyriltovena Jul 16, 2020
3e6a5cf
Fixes loki service in Promtail.
cyriltovena Jul 17, 2020
29ee215
Merge remote-tracking branch 'upstream/master' into loki_logstash_plugin
cyriltovena Jul 17, 2020
e9fb63a
Update loki-stack version
cyriltovena Jul 17, 2020
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ version: 2
branches: { only: master }
<<: *tags

.no-master:
&no-master # contrary to tags, the branches must be excluded
.no-master: &no-master # contrary to tags, the branches must be excluded
branches: { ignore: master }

workflows:
Expand Down Expand Up @@ -136,6 +135,7 @@ jobs:
- run:
name: Run Chart Tests
command: |
helm repo add elastic https://helm.elastic.co
ct lint --chart-dirs=production/helm --check-version-increment=false --validate-maintainers=false
ct install --build-id=${CIRCLE_BUILD_NUM} --charts production/helm/loki-stack
Expand Down
25 changes: 25 additions & 0 deletions .drone/drone.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,30 @@ local fluentd() = pipeline('fluentd-amd64') + arch_image('amd64', 'latest,master
depends_on: ['check'],
};

local logstash() = pipeline('logstash-amd64') + arch_image('amd64', 'latest,master') {
steps+: [
// dry run for everything that is not tag or master
docker('amd64', 'logstash') {
depends_on: ['image-tag'],
when: condition('exclude').tagMaster,
settings+: {
dry_run: true,
repo: 'grafana/logstash-output-loki',
},
},
] + [
// publish for tag or master
docker('amd64', 'logstash') {
depends_on: ['image-tag'],
when: condition('include').tagMaster,
settings+: {
repo: 'grafana/logstash-output-loki',
},
},
],
depends_on: ['check'],
};

local multiarch_image(arch) = pipeline('docker-' + arch) + arch_image(arch) {
steps+: [
// dry run for everything that is not tag or master
Expand Down Expand Up @@ -206,6 +230,7 @@ local manifest(apps) = pipeline('manifest') {
] + [
fluentbit(),
fluentd(),
logstash(),
] + [
manifest(['promtail', 'loki', 'loki-canary']) {
trigger: condition('include').tagMaster,
Expand Down
56 changes: 56 additions & 0 deletions .drone/drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,62 @@ steps:
depends_on:
- check

---
kind: pipeline
name: logstash-amd64

platform:
os: linux
arch: amd64

steps:
- name: image-tag
image: alpine
commands:
- apk add --no-cache bash git
- git fetch origin --tags
- echo $(./tools/image-tag)-amd64 > .tags
- echo ",latest,master" >> .tags

- name: build-logstash-image
image: plugins/docker
settings:
dockerfile: cmd/logstash/Dockerfile
dry_run: true
password:
from_secret: docker_password
repo: grafana/logstash-output-loki
username:
from_secret: docker_username
when:
ref:
exclude:
- refs/heads/master
- refs/heads/k??
- refs/tags/v*
depends_on:
- image-tag

- name: publish-logstash-image
image: plugins/docker
settings:
dockerfile: cmd/logstash/Dockerfile
password:
from_secret: docker_password
repo: grafana/logstash-output-loki
username:
from_secret: docker_username
when:
ref:
- refs/heads/master
- refs/heads/k??
- refs/tags/v*
depends_on:
- image-tag

depends_on:
- check

---
kind: pipeline
name: manifest
Expand Down
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,25 @@ fluentd-test: LOKI_URL ?= http://localhost:3100/loki/api/
fluentd-test:
LOKI_URL="$(LOKI_URL)" docker-compose -f cmd/fluentd/docker/docker-compose.yml up --build #$(IMAGE_PREFIX)/fluent-plugin-loki:$(IMAGE_TAG)

##################
# logstash plugin #
##################
logstash-image:
$(SUDO) docker build -t $(IMAGE_PREFIX)/logstash-output-loki:$(IMAGE_TAG) -f cmd/logstash/Dockerfile ./

# Send 10 lines to the local Loki instance.
logstash-push-test-logs: LOKI_URL ?= http://host.docker.internal:3100/loki/api/v1/push
logstash-push-test-logs:
$(SUDO) docker run -e LOKI_URL="$(LOKI_URL)" -v `pwd`/cmd/logstash/loki-test.conf:/home/logstash/loki.conf --rm \
$(IMAGE_PREFIX)/logstash-output-loki:$(IMAGE_TAG) -f loki.conf

logstash-push:
$(SUDO) $(PUSH_OCI) $(IMAGE_PREFIX)/logstash-output-loki:$(IMAGE_TAG)

# Enter an env already configure to build and test logstash output plugin.
logstash-env:
$(SUDO) docker run -v `pwd`/cmd/logstash:/home/logstash/ -it --rm --entrypoint /bin/sh $(IMAGE_PREFIX)/logstash-output-loki:$(IMAGE_TAG)

########################
# Bigtable Backup Tool #
########################
Expand Down
7 changes: 7 additions & 0 deletions cmd/logstash/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.gem
.ruby-version
.bundle
logstash
path
!lib
.rakeTasks
24 changes: 24 additions & 0 deletions cmd/logstash/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM logstash:7.6.2

USER logstash
ENV PATH /usr/share/logstash/vendor/jruby/bin:/usr/share/logstash/vendor/bundle/jruby/2.5.0/bin:$PATH
ENV LOGSTASH_PATH="/usr/share/logstash"
ENV GEM_PATH /usr/share/logstash/vendor/bundle/jruby/2.5.0
ENV GEM_HOME /usr/share/logstash/vendor/bundle/jruby/2.5.0

RUN gem install bundler:2.1.4

COPY --chown=logstash:logstash ./cmd/logstash/ /home/logstash/
WORKDIR /home/logstash/


RUN bundle install --path=/usr/share/logstash/vendor/bundle && \
bundle exec rake vendor && \
bundle exec rspec

RUN cat logstash-output-loki.gemspec | grep s.version | awk '{print $3}' | cut -d "'" -f 2 > VERSION

RUN gem build logstash-output-loki.gemspec && \
PLUGIN_VERSION=$(cat VERSION); /usr/share/logstash/bin/logstash-plugin install logstash-output-loki-${PLUGIN_VERSION}.gem

EXPOSE 5044
14 changes: 14 additions & 0 deletions cmd/logstash/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
source 'https://rubygems.org'

gemspec

logstash_path = ENV["LOGSTASH_PATH"] || "./logstash"

if Dir.exist?(logstash_path)
gem 'logstash-core', :path => "#{logstash_path}/logstash-core"
gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api"
else
raise 'missing logstash vendoring'
end

gem "webmock", "~> 3.8"
74 changes: 74 additions & 0 deletions cmd/logstash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributing to Loki Logstash Output Plugin

For information about hwo to use this plugin see this [documentation](../../docs/clients/logstash/README.md).

## Install dependencies

First you need to setup JRuby environment to build this plugin. Refer https://github.com/rbenv/rbenv for setting up your rbenv environment.

After setting up `rbenv`. Install JRuby

```bash
rbenv install jruby-9.2.10.0
rbenv local jruby-9.2.10.0
```

Check that the environment is configured

```bash
ruby --version
jruby 9.2.10
```

You should use make sure you are running jruby and not ruby. If the command below still shows ruby and not jruby, check that PATH contains `$HOME/.rbenv/shims` and `$HOME/.rbenv/bin`. Also verify that you have this in your bash profile:

```bash
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
```

Then install bundler
`gem install bundler:2.1.4`

Follow those instructions to [install logstash](https://www.elastic.co/guide/en/logstash/current/installing-logstash.html) before moving to the next section.

## Install dependencies and Build plugin

### Install required packages

```bash
git clone git@github.com:elastic/logstash.git
cd logstash
git checkout tags/v7.6.2
export LOGSTASH_PATH=`pwd`
Comment on lines +40 to +43
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

export GEM_PATH=$LOGSTASH_PATH/vendor/bundle/jruby/2.5.0
export GEM_HOME=$LOGSTASH_PATH/vendor/bundle/jruby/2.5.0
./gradlew assemble
cd ..
ruby -S bundle install
ruby -S bundle exec rake vendor
```

### Build the plugin

`gem build logstash-output-loki.gemspec`

### Test

`ruby -S bundle exec rspec`

Alternatively if you don't want to install JRuby. Enter inside logstash-loki container.

```bash
docker build -t logstash-loki ./
docker run -v `pwd`/spec:/home/logstash/spec -it --rm --entrypoint /bin/sh logstash-loki
bundle exec rspec
```

## Install plugin to local logstash

`bin/logstash-plugin install --no-verify --local logstash-output-loki-1.0.0.gem`

## Send sample event and check plugin is working

`bin/logstash -f loki.conf`
1 change: 1 addition & 0 deletions cmd/logstash/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "logstash/devutils/rake"
Loading