-
Notifications
You must be signed in to change notification settings - Fork 0
Logstash rework #52
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
Merged
Merged
Logstash rework #52
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
5ae9615
initial blueprints
bharel 8af9550
Logstash ready for review, will add docs, tests.
bharel 1f55c7e
doc
bharel 1c34716
So pwetty
bharel ea45f63
Here you go Ben, no number for you.
bharel 5e75623
CR fixes
bharel 6b9fe6b
Update yellowbox/extras/logstash.py
bharel f277fe7
docstring
bharel 88cea40
.
bharel 6fe8b6a
tests
bharel 2c6ba0e
Update tests/extras/test_logstash.py
bharel 36a94e5
bloops
bharel 51187c6
format
bharel 3ceb195
.
bharel 4175c1c
Update yellowbox/extras/logstash.py
bharel 499095a
.
bharel 3fe1f91
.
bharel 69490ca
.
bharel 4b49989
.
bharel 6e34054
autoformat
bharel f19e09e
.
bharel 3a6c52e
.
bharel 6a356e2
benben
bharel 7f68bb2
linter bug
bharel 1832c9f
coverage.
bharel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,115 @@ | ||
from yellowbox.extras.logstash import LogstashService | ||
from time import sleep | ||
|
||
# rebuilding the logstash service is an ongoing ticket, for now we just want to make sure it runs alright | ||
import pytest | ||
import json | ||
import socket | ||
from yellowbox.extras.logstash import FakeLogstashService | ||
|
||
@pytest.fixture | ||
def logstash(): | ||
ls = FakeLogstashService() | ||
ls.start() | ||
return ls | ||
|
||
|
||
def create_socket(logstash): | ||
return socket.create_connection((logstash.local_host, logstash.port)) | ||
|
||
|
||
def send_record(logstash, **kwargs): | ||
s = create_socket(logstash) | ||
s.sendall(json.dumps(kwargs).encode("utf-8")+b"\n") | ||
s.close() | ||
sleep(0.01) | ||
|
||
|
||
def send_records(logstash, *records): | ||
s = create_socket(logstash) | ||
data = "\n".join([json.dumps(record) for record in records]) + "\n" | ||
data = data.encode("utf-8") | ||
s.sendall(data) | ||
s.close() | ||
sleep(0.01) | ||
bharel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def test_sanity(logstash): | ||
send_record(logstash, msg="test") | ||
assert logstash.records[0] == {"msg": "test"} | ||
|
||
|
||
def test_multiple_records(logstash): | ||
send_records(logstash, {"msg": "hello"}, {"msg": "meow"}) | ||
assert logstash.records == [{"msg": "hello"}, {"msg": "meow"}] | ||
|
||
|
||
def test_multiple_connections(logstash): | ||
send_record(logstash, msg="test") | ||
send_record(logstash, msg="test2") | ||
bharel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert logstash.records == [{"msg": "test"}, {"msg": "test2"}] | ||
|
||
|
||
def test_half_record(logstash): | ||
s = create_socket(logstash) | ||
s.sendall(b'{"ms') | ||
s.sendall(b'g": "t') | ||
s.sendall(b'est"}\n') | ||
s.close() | ||
sleep(0.01) | ||
assert logstash.records[0] == {"msg": "test"} | ||
|
||
|
||
def test_bad_record(logstash): | ||
s = create_socket(logstash) | ||
s.sendall(b"{'sdafasdgsdgs\n") | ||
sleep(0.05) | ||
|
||
# Bad socket was closed | ||
with pytest.raises(BrokenPipeError): | ||
s.sendall(b"asdasd") | ||
sleep(0.05) | ||
s.sendall(b"asdasd") | ||
|
||
# Server still works | ||
send_record(logstash, msg="hello") | ||
assert logstash.records == [{"msg": "hello"}] | ||
|
||
|
||
def test_assert_logs(logstash): | ||
send_record(logstash, level="INFO") | ||
|
||
with pytest.raises(AssertionError): | ||
logstash.assert_logs("ERROR") | ||
|
||
send_record(logstash, level="ERROR") | ||
|
||
# Doesn't throw an error | ||
logstash.assert_logs("ERROR") | ||
|
||
|
||
def test_assert_no_logs(logstash): | ||
send_record(logstash, level="INFO") | ||
|
||
# Doesn't throw an error | ||
logstash.assert_no_logs("ERROR") | ||
|
||
send_record(logstash, level="ERROR", message="hello") | ||
|
||
with pytest.raises(AssertionError): | ||
logstash.assert_no_logs("ERROR") | ||
|
||
|
||
def test_filter_records(logstash): | ||
send_records(logstash, {"level": "INFO"}, {"level": "WARNING"}, | ||
{"level": "ERROR"}) | ||
assert list(logstash.filter_records("warning")) == [ | ||
{"level": "WARNING"}, {"level": "ERROR"}] | ||
|
||
|
||
def test_is_alive(): | ||
logstash = FakeLogstashService() | ||
assert not logstash.is_alive() | ||
logstash.start() | ||
assert logstash.is_alive() | ||
logstash.stop() | ||
assert not logstash.is_alive() | ||
|
||
def test_make(docker_client): | ||
with LogstashService.run(docker_client): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.