Commit graph

1654 commits

Author SHA1 Message Date
Rob Bavey
c266470c2e
Add RedHat Univeral Base Image license information (#12287) 2020-09-30 11:13:50 -04:00
Rob Bavey
ab1ef2da2f
Fix keystore thread safety (#12233)
* Fix keystore thread safety

This commit is intended to fix thread safety issues with the  JavaKeystore implementation of the secret store.
From reading the code, it appears that thread safety for the keystore was intended to be provided by
a ReentrantReadWriteLock, a read lock for accessing secrets from the keystore, and a write lock for updating
secrets in the keystore.

In practice, this was insufficient, the act of accessing a secret from the keystore involved the mutation of
a shared keyStore object - the keyStore is `load`ed every time a secret is retrieved from the store.

Previous to https://github.com/elastic/logstash/pull/10794, this did not matter, each pipeline held its
own instance of the secret store, effectively meaning that only a single thread would ever access a key
store at any one time. This PR moved to using a shared keystore instance for substitution variables,
exposing the lack of thread safety in the JavaKeystore class.

This commit is intended to be the simplest change to fix the underlying issue, and does not address whether
we *need* to reload the secrets every time they are read.

Relates #12229
2020-09-10 15:26:12 -04:00
andsel
164a763d7e Fix to implement the blank? method that doesn't exists for String, is added by Rails framework 2020-09-04 07:29:04 -07:00
Colin Surprenant
726061d5c5 fix flushing upon empty batches with ordered execution
when running a pipeline with ordered execution, flushes on the pipeline
were no longer being called when compute is called with an empty batch, causing
issues with the aggregate filter, for example, not being able to push events on
timeout.
2020-08-26 12:07:01 -07:00
Rob Bavey
b6b85e1a1e Add test for ordered pipeline flushing fix 2020-08-26 12:07:01 -07:00
Colin Surprenant
e8d1073bdd ensure input plugin close is called upon termination or pipeline reload 2020-08-21 08:08:21 -07:00
Ry Biesemeyer
5c36bc02f8 lir: inject newline delimiter only when necessary
Our internal representation of the composite config file needs only to inject
newline delimiters if they are missing, and to avoid doing so if they are
present. This allows `PipelineConfig#sourceReferences()`, used to map back from
the composite line/column to source file/column, to correctly track an offset
using the source fragments `SourceWithMetadata#getLinesCount()`.

Fixes: #12155
2020-08-06 11:11:47 -07:00
Ry Biesemeyer
e8d6ae5e4c test: no-op refactor to avoid repeating implementation in test 2020-08-06 11:11:47 -07:00
Ry Biesemeyer
95e386e415 perf: fix memoization of PipelineConfig#configString() 2020-08-06 11:11:47 -07:00
Colin Surprenant
2afe60dbfc fix PipelineRegistry to avoid re-creating a pipeline in the process of being created
A pipeline in the process of being created was not marked as such in the pipeline registry resulting in a situation where a slow to initialize pipeline could be recreated on state convergence resulting in a PQ LockException because that pipeline was already existing and held the PQ lock. Replace native Java concurency with Ruby Mutex for simpler and straighforward implementation.
2020-07-13 14:48:44 -07:00
Colin Surprenant
62519acdef monitor worker threads exceptions to not crash logstash, just the failed pipeline
The worker threads were not correctly monitored for a worker loop exception resulting in a complete logstash crash upon any exception even when multiple pipelines are running. Now only the failed pipeline is terminated. If pipeline reloading is enabled, it is possible to edit the config and have that failed pipeline reloaded.
2020-07-13 14:48:44 -07:00
Joao Duarte
23efb8dde4 ensure 'starting logstash' log entry happens first 2020-07-06 07:02:13 -07:00
Joao Duarte
6ff20ad502 make PQ and DLQ tests use less disk space
Many DLQ and PQ tests were run with default settings for their size,
or otherwise set to values such as 1GB.
This meant that the container/machine the test ran on needed a lot of disk space
(i.e. 1GB for the test + 1GB for OS and Logstash + some more free space).

This commit drops the disk space requirement overall by a factor of 10 (e.g. 1GB to 100MB)
2020-07-02 09:43:01 -07:00
Joao Duarte
0e033f9aa8 fix pipeline spec that didn't wait for pipeline to terminate
this test only called "pipeline.start" and expected an output to receive
the "do_close" method call. Therefore it relies on a race condition that
the pipeline shuts down quickly enough, which could fail.
This change ensures the pipeline fully terminated before making the
assertion

This commit also removes an unused let from the time when logstash
output plugins had workers.
2020-07-02 03:13:57 -07:00
Joao Duarte
5e1a08bbfc ensure pipeline terminates execution before doing assertion
This test relies on the generator input sending 10 events and observing
the output. Calling shutdown immediately after start can cause the
plugin to abort earily.
This change waits for the execution to finish before performing the
test assertions.
2020-07-02 03:11:31 -07:00
Joao Duarte
fd98f2e226 remove need for extra ShutdownWatcher thread
The creation of a Ruby thread from Java seems to be a trigger
for jruby/jruby#6207.

Pipeline#shutdown now blocks on the ShutdownWatcher#start, which will wait for
pipeline.finished_execution? to be true.
This removes the need for the pattern:
  `pipeline.shutdown { block } && pipeline.thread.join`
And can be replaced with just `pipeline.shutdown`

To avoid having `shutdown` blocked waiting for ready? when pipeline crashes too quickly,
this method returns immediately if finished_execution? is true.

Most uses of pipeline#run have also been replaced by pipeline#start
since the latter will block until the pipeline is ready, again avoiding
the pattern:
  `pipeline.run && sleep 0.1 until pipeline.ready?`

Pipeline tests have been changed according to these two changes.

Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com>
2020-07-01 13:16:50 -07:00
Joao Duarte
c5a76a1ebe test improved cache reuse during generation 2020-07-01 01:58:08 -07:00
Joao Duarte
f44a3f85aa fix tests related to compiler cache due to reduced class generation 2020-07-01 01:58:08 -07:00
Joao Duarte
4c96422fff reduce Compiler Cache size to 100
The reduction from 500 to 100 is based on observations where 06d7f01fd
reduced the number of generated classes by about an order of magnitude
especially on very large pipelines (e.g. from ~600 to ~30).
2020-07-01 01:58:08 -07:00
Ry Biesemeyer
afd313b6b5 JEE: nix global compiler lock by normalizing to Dataset interface
Generated implementations of `Dataset` often have fields referencing
other specifically-generated `Dataset`, despite only using public methods
(`compute` and `clear`) defined on the `Dataset` interface.

By allowing the code generation to reference the interface instead of
the specific implementation, we eliminate the need for the compiler to chain
parent class loaders indefinitely, thereby eliminating the need for a global
mutual exclusion when compiling.

This change moves the locking semantics from the compiler to the non-evicting
cache itself, relying on tried-and-true `ConcurrentHashMap#computeIfAbsent`
to minimize synchronization and cache-priming stampedes.

This also vastly reduces the scope of `Dataset` implementations that we need
to generate, because datasets will no longer need to reference the specific
implementation details of all "downstream" datasets and will therefore be more
likely to match an implementation that has already been compiled and cached.
2020-07-01 01:58:08 -07:00
Colin Surprenant
454a856df8 do not call agent.converge_state_and_update before agent.execute 2020-06-30 11:14:26 -07:00
Colin Surprenant
12e7ab9d81 release queue dir lock upon exceptions while opening queue 2020-06-30 10:42:49 -07:00
Ry Biesemeyer
c70da3fb5c
plugin config: support space-deliminated URIs on list-type params (#12051)
* plugin config: support space-deliminated URIs on list-type params

Since whitespace is illegal in URIs, we can safely use it as a delimiter when
validating `list`-type `URI` params, enabling the expansion of an arbitrary
list of URIs from a single Environment- or Keystore-variable.

Resolves: https://github.com/elastic/logstash/issues/8157
Resolves: https://github.com/elastic/logstash/issues/6366

* Doc: Create section for cross-plugin functionality and add space delimiters

Co-authored-by: Karen Metts <karen.metts@elastic.co>
2020-06-26 14:44:46 -07:00
Joao Duarte
a0ea282277 improve test for cache difference 2020-06-26 09:50:36 -07:00
Colin Surprenant
ffac2dfbdc Changed the assignment of plugin.id to load the value dynamically istead of hardcode
Changed ComputeStepSyntaxElement to generate Java code to retrieve the plugin's id by a method instead of hardcoding the value in the generated code.
This permit to share more compiled classes, that differs only by plugin.id and speed up the pipeline compilation.

The change has been secured by future regression with unit test that track pipeline compilations times.

Co-authored-by: Andrea Selva <andsel@users.noreply.github.com>
Co-authored-by: João Duarte <jsvd@users.noreply.github.com>

Fixes: #12031
2020-06-25 06:09:34 -07:00
Karol Bucek
5eb25dc40b Feat: ship log4j2 commons-logging bridge with LS
Having the jar around would allow us to fine tune logging for libraries
such as manticore's http-client (4.5) using LS's `log4j2.properties`
e.g.

```
logger.apache_http_headers.name = org.apache.http.headers
logger.apache_http_headers.level = DEBUG
```
... to log http headers for each request

Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com>
2020-06-23 02:39:29 -07:00
Colin Surprenant
757bf6b2ce
fix Settings equality test which broke the PipelineConfig equality (#12009) 2020-06-11 19:42:49 -04:00
Joao Duarte
11e61b1abf Revert "upgrade google-java-format to 1.8"
This reverts commit 2229468f11.

google-java-format 1.8 is Java 11 only, so we can't use it
as Logstash is supported on Java 8.
2020-06-09 11:00:33 -07:00
Joao Duarte
124e1e6abc remove explicit return from Mutex#synchronize in Plugin Registry
ruby produces a LocalJumpError: unexpected return
error if there's a return in a block so this changes just uses
the value of the last expression as the value of the block
2020-06-09 09:59:10 -07:00
Joao Duarte
2229468f11 upgrade google-java-format to 1.8 2020-06-09 09:58:36 -07:00
Joao Duarte
a7ae0d55e6 update log4j script routes definition
fixes the change introduced with https://issues.apache.org/jira/browse/LOG4J2-2647
2020-06-09 06:26:31 -07:00
Joao Duarte
c2659c3cfa update log4j dependency to 2.13.3 2020-06-09 06:26:31 -07:00
Joao Duarte
1ebf1b2b13 update commons-codec to 1.14 2020-06-09 06:26:31 -07:00
Andrea Selva
1bba3adecf
Exposed again the pipelines queue.data and queue.capacity subdocuments for _node/stats (#11923)
Avoid to reassing the subdocument for queue metrics preferring a merge
With PR #10576 the PluginsStats.report(stats) overwrites the subsection related to queue instead of merge with newly created entries.
2020-06-04 15:21:51 +02:00
Rob Bavey
3bd95b11ff Disable flaky multiReceiveRecordsDurationInMillis test
Relates #11956
2020-06-02 14:00:44 -07:00
Colin Surprenant
0c38004bf3 display Java pipeline initialization time
Fixes #11749
2020-06-01 20:23:04 +00:00
Joao Duarte
d449fcf25a emit deprecation entry for netflow and azure modules
point users towards the beats modules instead
2020-05-29 15:26:23 +01:00
Rob Bavey
ac95667c11
Use task avoidance API in gradle scripts (#11914)
* Use task avoidance API in gradle scripts

This commit uses the task avoidance api (tasks.register vs task.create/
task DSL), as recommended since Gradle 5.1

This should reduce the execution of unnecessary tasks in build jobs, and
hopefully improve build resiliency and execution time.
2020-05-29 10:25:52 -04:00
Rob Bavey
50816c6f1d [Tests] Ignore flaky testTimeCallable test
Flaky test issue #11925
2020-05-26 11:07:56 -04:00
Karol Bucek
196ec20f6d Fix: avoid gsub (frame dependent) usage from Java
`RubyString#gsub` requires a (Ruby) frame to be present.
The method attempts to set a backref for the current caller's frame.
When the frame stack is empty there isn't really a place to set $~.

This can happen when a LogStash::Util::Loggable#logger is retrieved,
from the input worker thread while not being nested in any block.

Fixes #11874
2020-05-07 18:00:23 +00:00
Karol Bucek
413a7fe55e Performance: improve event.clone memory usage
for Strings with copy-on-write semantics when deep cloning.

motivated by "big" events reaching plugins such as split,
which might produce several new events out of a single one.

Fixes #11794
2020-05-07 14:10:28 +00:00
Joao Duarte
2ea7bd43ec RUNNER: print RUBY_DESCRIPTION at startup to facilitate debugging
Often when browsing logstash logs for debugging purposes we miss the
information about the Java version and platform being used.

Printing the global RUBY_PLATFORM gives us all of this information
plus the JRuby version as well.

Fixes #11852
2020-05-05 15:32:24 +00:00
Andrea Selva
d9f3d8b7db
Fix: missed 'equal' part in time comparison test (#11862)
In time comparison of LocalDateTime the isBefore is strict, so in case two instants has the same millisecond, it fails in test (happens in Windows tests)

Close: 11862
2020-05-04 17:19:09 +02:00
Andrea Selva
832d597278
Refactor: move PipelineConfig from Ruby to Java (#11824)
Reimplement the Ruby class PipelinceConfig in Java trying to keep the method signatures to limit the changes in client code, this is a step of other that intend to move all the configuration code in Java language.
Having all that code in Java unlock some reasoning about how to better implement it and probably an improvement in performance during process startup.
Moved also the spec into a JUnit and fixed here and there the failing tests

Closes: #11824
2020-04-29 18:16:49 +02:00
Rob Bavey
170f84d2a5
Rework monitoring to avoid using deprecated getSystemCpuLoad method… (#11786)
* Avoid using deprecated `getSystemCpuLoad` method with JDK14

JDK14 prefers the use of `getCpuLoad` over `getSystemCpuLoad`. This commit
reworks the call to use reflection to use the appropriate method call
depending on the version of the JDK being used.

* Added warning message if OperatingSystemMXBean not available
* Also corrected spacing after code review comments.
2020-04-24 10:39:27 -04:00
Ry Biesemeyer
de5888ba18 API: avoid starting webserver when http.enabled=false
In some workflows such as simple file manipulation, starting a webserver is
unnecessary overhead, and we should be able to avoid it.

Here we introduce a new parameter `http.enabled`, which defaults to `true` to
maintain the existing functionality.

Resolves: elastic/logstash#9408
Closes: elastic/logstash#11525

Co-authored-by: Benoit Dupont <benoit.dupont@gmail.com>

Fixes #11533
2020-04-21 20:08:46 +00:00
Joao Duarte
3481b38228 dont use qualifier or snapshot in logstash core version
Fixes #11813
2020-04-21 16:50:58 +00:00
Ry Biesemeyer
f1e301e0d7 settings: deprecate unit-less TimeValue values
We have "required" units for a variety of `TimeValue` settings when they are
provided as a `String`, but unquoted values in YAML have been passed through as
Integers, where we long assumed nanosecond units. This frequently leads to
surprise (e.g., when `config.reload.interval` is set to `60`, we consume 100%
of CPU in a tight loop trying to reload and re-parse the configs every 60
nanoseconds).

By making the setting retain the TimeValue object for the entirety of its
lifecycle, we can issue a deprecation notice the first time an Integer value is
encountered. As a secondary benefit, our usage of the setting value in code
becomes more clear since we are empowered to ask `TimeValue` for a numeric
value in a specific scale.

Fixes #11803
2020-04-20 16:15:49 +00:00
Joao Duarte
6cc4de77e3 update guava and httpclient dependencies
Fixes #11791
2020-04-15 13:49:54 +00:00
Andrea Selva
6a74872d50
Moved code out of LogStash::Compiler to org.logstash.config.ir.ConfigCompiler 2020-04-15 12:21:39 +02:00