1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-10-17 14:01:01 +00:00

297 Commits

Author SHA1 Message Date
58b58cfe4a Test sane behavior when trying to set fields or tags causing exception in Rack::Middleware 2018-01-30 18:37:25 +01:00
ce12e26bba Simplify the Rack middleware to write request log immediately
Previously, we would only setup a `::Rack::BodyProxy` to eventually log
the request once the response is deivered to the client. We did this
mainly in order to have a more "accurate" duration in the logs, similar
to what the `::Rack::CommonLogger` middleware does.

This has some significant disadvantages though:

* If an exception is raised by an outer middleware after we returned,
the response is never delivered and the log is lost.
* If a timeout occured (and e.g. a Unicorn worker is killed or a
`Rack::Timeout` stroke) before we return the full response, the log is
lost.
* If the client goes away before the request is finished, the app server
might decide no just throw away the response.

Besides addressing these issues, logging directly after the request
leaves our middleware scope makes the whole process much easier to
reason about.
2018-01-30 18:36:47 +01:00
1c461bf8da Specify exact behavior for @version and @timestamp fields for Logstash encoder 2018-01-27 00:48:51 +01:00
1d16d366a0 Test JSON encoder behavior with a missing timestamp 2018-01-27 00:47:25 +01:00
952ecd5c73 Ensure that the JSON encoder correctly serializes the event timestamp 2018-01-27 00:36:03 +01:00
d6cc062b93 Omit an empty message when encoding an event as JSON 2018-01-27 00:36:03 +01:00
7f6e7e86c6 Add tests to ensure the the Message encoder can deal with uncommon messages 2018-01-27 00:36:03 +01:00
18abd892ba Test that Adapter::File.from_uri only accepts file URIs 2018-01-25 11:14:27 +01:00
6d4106fcb7 Add Select and Remove filters to filter which fields get passed to the encoder 2018-01-25 10:52:42 +01:00
dda72c2f84 Work around deprecations on Ruby 2.5.0 2018-01-24 20:18:50 +01:00
99d2f489dd Update Copyright year 2018-01-24 00:21:04 +01:00
577c065900 Allow to define a File adapter using a file:// URI 2018-01-23 23:54:48 +01:00
39f12047cb Add helper method to parse URI parameter from an adapter URI 2018-01-23 23:53:31 +01:00
c194b00b34 Improve code formatting and fix Rubocop issues 2018-01-23 23:21:58 +01:00
38a5c669a3 Allow to register complex URI schemes for Adapters
Most notably, we want to use the plus character in URI schemes. By only
checking the first character of the scheme registration, we can better
fullfil our contract and better distinguish between schemes and class
names of registered Adapters.
2018-01-22 01:11:27 +01:00
e8bf2c31bd Raise ArgumentError when trying to resolve an unknown adapter URI
If we were to fall through, undefined schemes would always end up as a
file adapter. This is generally undesired since it hides the fact that
we have not found a suitable adapter. Most of the time, this will be a
configuration error which should be reported early.

If a user still wants to create a file adapter with a filename that
looks like a URI, they can create a Rackstash::Adapter::File object
manually.
2018-01-22 01:05:06 +01:00
bdeb0534c9 Allow to set the Flow#raise_on_error setting with the same getter/setter protocol as all the other values 2018-01-12 23:34:17 +01:00
96f102875f Allow to set Flow#raise_on_error? to aid in debugging flows 2018-01-12 21:03:52 +01:00
7c424edfe0 Remove debug code from specs 2018-01-03 20:40:51 +01:00
65d75523c3 Ensure only valid classes can be registered as filters and encoders 2018-01-03 20:40:31 +01:00
fe44186da4 Add filter to mask of IP addresses in event fields 2018-01-03 20:39:24 +01:00
9ed350cb8d Allow fields to hold force-inspected BasicObjects 2017-12-21 01:19:10 +01:00
6eaeaedaf8 Register encoders using a ClassRegistry 2017-12-20 23:58:32 +01:00
de6b60925a Allow to define conditionals on built filters
Now you can define optional filters which only run if some condition is
true or false. This can be used to e.g. update fields depending on some
tags being present in the event.
2017-12-20 23:40:20 +01:00
a475a5c6fc Use the ClassRegistry to register filters
This removes the requirement that filters need to be defined in the
Rackstash::Filters namespace in order to be usable with a short name.
Filters can be registered with an arbitrary name.

As before, raw blocks / procs can be defined as ad-hoc filters.
2017-12-20 23:40:20 +01:00
01593a9b8b Add Rackstash::ClassRegistry to register filters and encoders
Using the ClassRegistry, we can register short names for filter and
encoder classes so that they can be specified in a shorter and more
readable way during creation of the logger.
2017-12-20 23:06:25 +01:00
1b2dd09000 Add FilterChain#push as an alias to FilterChain#<< 2017-12-20 21:39:55 +01:00
0782f31d45 Test that FilterChain#append returns the original filter chain 2017-12-20 21:39:15 +01:00
6bfe8ecb25 Provide prepend alias for FilterChain@unshift
Ruby 2.5 introduces this alias for all arrays.
2017-12-20 21:33:49 +01:00
43a303b09d Include Enumerable module into Flows 2017-12-20 21:27:12 +01:00
40e151ecb8 Rename the SkipEvent filter to DropIf to make the intention clearer 2017-12-20 18:41:40 +01:00
1671b04dfb Add Fields::Hash#each and make the Hash class an Enumerable 2017-12-12 19:58:46 +01:00
e472b7fbce Add Fields::Hash#length to emulate Hash#length 2017-12-12 19:29:28 +01:00
d382a245f3 Add Fields::Hash#fetch to emulate Hash#fetch 2017-12-12 19:26:44 +01:00
9150b2e0ac Properly test every code path for Rackstash::Helpers::Time
Even if it doesn't look like it, there might (and in fact did) lure
unexpected errors even in seemlingly obvious code-paths.
2017-12-05 19:30:39 +01:00
6ce668e09d Allow to include the event's timestamp as a message tag in the Message encoder 2017-12-05 19:07:46 +01:00
8cdd000b0c Allow to add error details with Logger#add_error 2017-12-05 18:59:21 +01:00
26597680af Set rack.errors in the Rack::Middlware
This ensures that other middlewares whi want to log to the default
rack.errors stream will log to a sensible location instead of the usual
default of raw STDOUT or STDERR.
2017-12-05 18:55:08 +01:00
3b8e76329c Explicitly load Rackstash::Version again during coverage tests 2017-11-29 12:16:47 +01:00
969e1e8cf3 Use a plain optional argument for normalize_timestamp 2017-11-14 08:56:02 +01:00
57119a3266 Rename the abstract adapter base class to BaseAdapter
This avoides the name clashes (and the resulting uncertanty with name
resolution) between the base class and its containing module.
2017-10-21 16:57:01 +02:00
d721c1fc72 Singularize the Filters module
Since we are using single objects from this namespaces, it is much
more suitable to be named in singular than in plural.
2017-10-21 16:38:07 +02:00
aa37d47b8f Singularize the Adapter and Encoder modules
Since we are using single objects from these namespaces, they are much
more suitable to be named in singular than in plural.
2017-10-20 22:27:50 +02:00
e857cdb9f1 Return an existing filter instance in Filters.build 2017-10-20 20:22:38 +02:00
8db2c917c2 Fix a couple of Rubocop warnings
All of these changes are either simple formatting changes or clarify
existing meaning. None of these changes affects externally visible
behavior.
2017-10-20 19:51:11 +02:00
c1e3c99ab5 Do not write empty lines to IO and File adapters
If a line is completely empty, it is not useful to log it at all since
it would be invisible on the created logstream anyway. If we get passed
an empty String from the encoder, we can thus silently ignore it.
2017-10-19 23:06:45 +02:00
ca685bb13b Do not prefix an empty messages with tags
If an event's message is completely empty (usually because there was
nothing logged at all), it isn't very useful to output this bare marked
up message at all. We thus ignore it and pass it along unchanged in the
Message encoder.

Note that we still add tags for messages consisting of other whitespace
like e.g. a newline added from a formatted empty message added to a
Logger.
2017-10-19 23:03:48 +02:00
c58c70febb Add Rack middleware
The middleware can be used in a Rack appliction wrap all log messages
emitted to the logger during a single request in a single emitted log
event. This ensures that all data concerning the request, including log
messages as well as additional fields and tags are logged as one single
event.

This ensures that the data is kept as a whole when the log event is
handled by later systems like Logstash. Each request can be analyzed as
a whole without having to group or parse complex multi-line log formats.
2017-10-18 00:21:43 +02:00
cb95c0b0e4 Add new data-only buffering mode to Buffer
With this, the Buffer knows three buffering modes:

* :full - This is the same as the previous buffering-enabled mode. With
  this, we buffer everything and never auto-flush
* :none - the previous non-buffering mode. We autoflush everytime there
  is a new messase or explicitly added fields. All stored data is
  cleared afterwards.
* :data - the new mode. It behaves almost like :none with the notable
  exception that we retain fields and tags after the auto flush.

The new mode is especially useful to emulate a regular Logger even when
using per-request buffers. With that, you can add fields once to a
buffer. Each time a message is added, it will be flushed directly
without waiting for the request to be finished. Yet, the flows can still
take advantage of all the previously added fields and tags to properly
format the emitted log event.
2017-10-17 23:31:13 +02:00
2e5c39d5d0 Add filters to add default fields or tags to an event 2017-10-10 21:30:35 +02:00