Commit graph

835 commits

Author SHA1 Message Date
Rob Bavey
092892cdd4
Add thread safety around Puma startup/shutdown (#14080)
If #stop is called on Puma before #run is finished - for example, when an
incorrect configuration is specified, Puma can be left with threads hanging
around.
This is due to a check/notify pipe used to signal state changes not being created
until halfway through the #run method, enabling a window where #stop can be called
before the pipe has been created, leading to the run thread not exiting. Prior to
jruby-9.3.x, this would tend to be benign and Logstash would exit normally. However,
jruby-9.3.x introduced a tear down as part of the shutdown mechanism, which will join
active threads on shutdown. This puma issue would cause an indefinite hang on exit
when this condition is triggered.
2022-05-10 13:22:45 -04:00
kaisecheng
41cb3d3680
Hide Shutdown Watcher stall message when PQ draining (#13934)
Hide shutdown stall message when queue is draining
Fixed: #9544

Co-authored-by: Andrea Selva <selva.andre@gmail.com>
2022-05-10 13:46:15 +01:00
Andrea Selva
229e7ce5ea
Introduce a retry mechanism in pipeline-to-pipeline (#14027)
Updates the `internalReceive` method implementation in Pipeline Input to catch exception error and return the position where the stream was interrupted. Modify the EventBus's batch forwarding logic to handle errors from Pipeline Input and apply retry logic only from last error position in the batch of events.

Co-authored-by: Karol Bucek <kares@users.noreply.github.com>
2022-05-05 16:16:28 +02:00
Rob Bavey
e02a9e00c7
Fix plugin classloading (#14060)
Prior to this commit, attempting to use a custom java plugin installed from rubygems would
fail as the `files` field used to find jar files in the gem is not populated for such gems

This commit uses the `full_require_path` to find the jar file for a native jar plugin,
which should work regardless of where the gem was installed from, locally or via rubygems

Additionally, this commit will only attempt to locate the jar file inside the gem when it
is required (only when the experimental separate plugin class loader is used)

This commit builds on the work done in #13888

Relates: #13888, #11305

Co-authored-by: twosom <two_somang@icloud.com>
Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com>
2022-05-03 17:49:21 -04:00
Mashhur
d8e08e9f20
Add complex password policy on basic auth (#14045)
* Apply complex password policy on HTTP basic auth.
2022-05-03 09:57:46 -07:00
Mashhur
25796737c3
Prevent Logstash from running as root. (#14046)
* Prevent Logstash from running as root.

Co-authored-by: João Duarte <jsvd@users.noreply.github.com>
2022-05-02 08:53:35 -07:00
Andrea Selva
c1fe7095c3
Implements DLQ storage policy (#13923)
Exposes dead_letter_queue.storage_policy configuration setting to explicitly enable the drop_older behavior in DLQs.

Moving from a drop_newer to a drop_older behavior has impact both on the writer side and to the reader side.
The implementation leverage the fact that a complete DLQ segment can be removed to free up space; on the writer side when the dead_letter_queue.max_bytes limit is reached it has to remove old segments.

On the reader side, the consuming has to be adapted to don't expect a continuous flow of segments, it could face an hole due to removal of tail segments.

Co-authored-by: João Duarte <jsvd@users.noreply.github.com>
Co-authored-by: Karen Metts <35154725+karenzone@users.noreply.github.com>
2022-04-28 09:16:03 +02:00
kaisecheng
e8cd0d3039
Fix stopped pipeline unable to be deleted in registry (#14018)
Prior to the change, pipeline `stop` and `delete` happen in two converge cycles, which
has a gap letting the stopped pipeline compare with the same pipeline definition
in central pipeline management, hence Logstash see the stopped pipeline as graceful finish
and not to delete in registry

This commit creates StopAndDelete action to delete running pipeline in one converge cycle

Fixed: #14017
2022-04-27 09:30:16 +01:00
Rob Bavey
4e77f1b79d
Make AliasRegistry a singleton (#14002)
* Make AliasRegistry a singleton

The current implementation of AliasRegistry will create an instance of the Alias Registry for each
pipeline, which appears to potentially result in situations, such as in #13996, where multiple pipelines
are simultaneously loading an alias registry from a yaml file in the jar file using getResourceAsStream, with
the potential of the first thread closing the jar file underneath subsequent threads, leading to errors when
reading the yaml file as the JarFile has been closed after the initial thread completed accessing.

This commit changes the AliasRegistry to be a singleton, as is the PluginRegistry.

Relates: #13996, #13666

* Update reflections library to 0.9.12 to avoid multi threading bug

Earlier versions of the reflections library used in the plugin registry would
use caches on JarUrlConnection, which when closed would also close the jar file
for other resources using it, such as the AliasRegistry. This, combined with the
fact that the AliasRegistry could be created simultaneously by many threads/pipelines
could cause issues during AliasRegistry creation leading to failure to create a
pipeline.

* Avoid use of URLConnection caching when getting alias yaml resource
* Use idiomatic ruby when accessing Java getInstance method

Co-authored-by: Andrea Selva <selva.andre@gmail.com>
2022-04-26 11:15:30 -04:00
Rob Bavey
1291b5edcc
Further improve check on "running pipelines" after SIGHUP (#13995)
As pointed out in this post merge review comment, there is a window
where we could miss a pipeline transitioning from 'loading' to 'running'
in the original fix, as separate calls are made to the pipeline registry.
This commit fixes that by making a single call to the pipeline registry which
allows for also returning pipelines in the `loading` state.

Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com>
2022-04-14 10:10:59 -04:00
Rob Bavey
7b2bec2e7a
Fix reload of pipelines via SIGHUP (#13994)
When logstash is run without automatic reloading, it is still possible to reload configurations
by using 'SIGHUP'. This functionality was broken in #12444, which split non-terminated pipelines
into "loading" and "running" states. The call `no_pipelines?` in agent#execute would no longer
find pipelines in a "loading" state, causing the loop to exit, and logstash to shutdown. This
commit tests for pipelines in a "loading" state to restore functionality
2022-04-13 12:48:15 -04:00
Rob Bavey
339a67fe37
Convert Exception during converge to a failed action (#13969)
Certain errors during pipeline converge will emit an IllegalStateException - for example attempting
to reference an environment variable that does not exist. Attempting to add a java exception to the
converge result would result in an uncaught exception in a pipeline thread leading to an unclean
shutdown.

This had the effect of,prior to this commit, Logstash behaviour varying depending on the class of
error that caused a pipeline not to start - an invalid pipeline configuration would still enable
logstash to start other pipelines in a multiple pipeline configuration, or automatic reloading
enabling changes to the configuration to allow the pipeline to start(in multi- and single pipeline
configurations).
However, a missing environment variable would cause Logstash to crash hard no matter what.

This was discovered when updating to jruby-9.3.3.0, when new clean up code joining existing
threads to perform a graceful shutdown was stuck indefinitely, due to the webserver shutdown
code not being called, due to the unclean shutdown.
2022-04-12 10:04:10 -04:00
Andrea Selva
1d31816a4b
Correct the class reference to the MetricNotFound exception (#13970)
Fix the class reference `Instrument::MetricStore::MetricNotFound`  to be `LogStash::Instrument::MetricStore::MetricNotFound` and do not raise a constant not found reference when the point "/_node/stats" is queried and no pipelines are defined.
2022-04-04 09:26:53 +02:00
Rob Bavey
43c6576344
Improve safety of stats retrieval from queue (#13942)
This commit guards against reading a value from a stat that may not be
populated before an attempt is made to retrieve its value, potentially causing
a `undefined method `[]' for nil:NilClass`.
2022-03-28 20:04:53 -04:00
kaisecheng
71772074a7
PQ size check for multiple pipelines (#13877)
Fixed unable to start causing by queue.max_bytes: 0
Added PQ size checking for multiple pipelines in converging

Fixed: #12213
2022-03-24 18:11:32 +00:00
kaisecheng
1a5030bd63
add backoff to checkpoint write (#13902)
This commit changes `queue.checkpoint.retry` to `true` by default allowing retry of checkpoint write failure.
Add exponential backoff retry to checkpoint write to mitigate AccessDeniedExcpetion in Windows.
Fixed: #12345
2022-03-24 09:19:45 +00:00
Ry Biesemeyer
e9455ca81e
pipeline-info: increase safety of transforming stats (#13345)
When a pipeline isn't fully initialized, we run the risk of attempting to
format pipeline info that isn't yet fully-shaped. By using safe-fallback
methods like `Hash#dig` and conditional-chaining, we can avoid the spurious
`NoMethodError` caused by sending `[]` to nil.
2022-03-04 10:49:52 -08:00
Ry Biesemeyer
a6c0e75b53
api: avoid 5xx when stats/events not yet populated (#13424)
* api: avoid 5xx when stats/events not yet populated

* Add catching of metrics exception also for retrieve of :queue metrics. No pipelines means no queues created

* Added empty result when no pipelines is present and query for node info API

Co-authored-by: andsel <selva.andre@gmail.com>
2022-03-04 08:42:28 -08:00
kaisecheng
21de1c1da9
expose shutdown request state of pipeline (#13811)
This commit exposes the pipeline shutdown request state to output plugin

Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com>
2022-02-28 23:37:27 +00:00
Karol Bucek
4f32c4fd48
Refactor: revisit logstash bootstraping bits (#13791)
* Refactor: logstash boot to know what to do
* Refactor: reduce LOAD_PATH - load jars directly
* Refactor: unused requires in runner
* Refactor: boot - require libs when to be used
2022-02-17 13:59:38 +01:00
Karol Bucek
3637a30e8f
Refactor: drop redundant (jruby-complete.jar) dependency (#13159)
Co-authored-by: João Duarte <jsvd@users.noreply.github.com>
2022-02-02 06:55:26 +01:00
kaisecheng
6a28ac10ee
add compatibility for plugins not in support matrix (#12534)
Fixed: #11236
2022-01-25 08:28:42 -08:00
Ry Biesemeyer
2a5e54cd21
logging: move init into environment's settings post-processor (#13221)
* logging: move init into environment's settings post-processor

Ensures that the non-runner command line utilities like `bin/logstash-keystore`
correctly initialize the logger as-configured.

* fixup: ensure we get ruby stdlib URI & File
2022-01-20 10:45:33 -08:00
Ry Biesemeyer
4b430a5f69
stats api: startup resilience when stats are partially formed (#13645) 2022-01-20 08:44:46 -08:00
Andrea Selva
d4bdcc936d
Add info log of JVM flags used to configure Logstash (#13531)
Logs the JVM flags and options used to launch Logstash.
2022-01-18 14:07:37 +01:00
Andrea Selva
e27fdeb252
Avoid to itereate with each_index (#13603)
Sometime the deep_replace could be invoked by plugins, using the LogStash::Config::Mixin#validate.
This method receives a Ruby hash which could contains Java ArrayList instead of Ruby Array.
The iteration method `each_index` is not available for ArrayList, so resort to some form of "plain old way".
The reason why an ArrayList is recognized as a Ruby Array is due to the override classes, like RubyJavaIntegration.JavaCollectionOverride that monkey patches Ruby Array, so that a Java Collection could be seen as a RubyArray but it doesn't implement all the abstractions, like `each_index`.

Co-authored-by: Karol Bucek <kares@users.noreply.github.com>
Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com>
2022-01-12 17:09:50 +01:00
kaisecheng
7d5c5f09d3
Fix unknown type warning of geoip metrics (#13382)
This commit changes the value of the geoip metric from Symbol to String to remove warning and refactors metrics part

Fixed: #13197
2022-01-11 11:16:43 +00:00
Karol Bucek
32b8739f6f
Fix: delegating from deprecated setting (#13481) 2021-12-08 13:21:24 +01:00
Karol Bucek
32690cb96f
Fix: patch Puma around a JRuby ARM64 bug (#13447)
Co-authored-by: João Duarte <jsvd@users.noreply.github.com>
2021-11-25 16:59:13 +01:00
Ry Biesemeyer
c3e498a24b
ECS on by default for Logstash 8, again (#13391)
* ecs: report pipeline's ECS-compatibility with INFO at startup

Because the pipeline-level setting `pipeline.ecs_compatibility` affects the
default behaviour of nearly every plugin in the pipeline, an INFO-level log
message will provide useful hints, especially to our users who upgrade to
Logstash 8 without first reading the breaking changes docs.

For example, when we have two pipelines `old` and `new` whose `pipeline.ecs_compatibility` is `disabled` and `v8` respectively, we would get the following log messages:

> ~~~
> [2021-11-04T18:43:21,810][INFO ][logstash.javapipeline    ] Pipeline `old` is configured with `pipeline.ecs_compatibility: disabled` setting. All plugins in this pipeline will default to `ecs_compatibility => disabled` unless explicitly configured otherwise.
> [2021-11-04T18:43:21,817][INFO ][logstash.javapipeline    ] Pipeline `new` is configured with `pipeline.ecs_compatibility: v8` setting. All plugins in this pipeline will default to `ecs_compatibility => v8` unless explicitly configured otherwise.
> ~~~

* ecs: make v8 the default for 8.0

* ecs: `pipeline.ecs_compatibility` defaults to `v8`

Related: elastic/logstash#11623

* doc: temporarily remove deep link from breaking changes doc to fix build
2021-11-17 13:17:23 -08:00
Karol Bucek
64800cd3a9
Feat: use Java thread name in thread info (#13156) 2021-11-15 18:28:00 +01:00
João Duarte
4919286e42
rename references of master branch to main branch (#13301) 2021-11-08 10:23:46 +00:00
Rob Bavey
462191ebbf
Forwardport #13358 to master: Add deprecation warnings for JAVA_HOME/… (#13365)
* Forwardport #13358 to master: Add warnings for JAVA_HOME/older versions of Java

Forwardport PR #13358 to master branch. Original message:

* Add deprecation warnings for JAVA_HOME/older versions of Java

Logstash 8.0 will remove support for java versions before java 11, this commit
adds entries to the deprecation log warning against this.
Also adds use of `JAVA_HOME` to the deprecation log.

* Change deprecation log entries to warnings to indicate imminent issue
2021-10-26 21:48:13 -04:00
Ry Biesemeyer
15930ccd3e
Secure API (#13308)
* settings: add "deprecated alias" support

A deprecated alias provides a path for renaming a setting.

 - When a deprecated alias is set on its own, a deprecation notice is emitted
   but fetching the canonical setting value will reflect the value set with the
   deprecated alias.
 - When both the canonical setting (new name) and the deprecated alias (old
   name) are specified, it is an error condition.
 - When the value of the deprecated alias is queried, a warning is emitted to
   the logger and only the value explicitly set to the deprecated alias is
   returned.

Additionally, some relevant cleanup is also included:

 - Starting Logstash with invalid settings no longer results in the obtuse "An
   unexpected error occurred" with backtrace and exception data obscuring the
   issue. Instead, a simple message is emitted indicating that the settings are
   invalid along with the originating exception's message.
 - The various settings implementations share a common logger, instead of each
   implementation class providing its own. This is aimed to reduce noise from
   the logs and to ensure specs validating logging do not need to tie so
   closely to implementation details.

* settings: add password-wrapped setting

* settings: make any setting type capable of being nullable

* settings: add `Settings#names` to power programatic iteration

* cli: route CLI-flag deprecations in to deprecation logger

* settings: group API-related settings under `api.*`

retains deprecated aliases, and is fully backward-compatible.

* webserver: cleanup orphaned attr accessors for never-set ivars

* api: pull settings extraction down from agent

This net-no-change refactor introduces a new method `WebServer#from_settings`
that bridges the gap between Logstash settings and Puma-related options, so
that future additions to the API settings don't add complexity to the Agent.

It also has the benefit of initializing the API Rack App and just ONCE, instead
of once per attempted HTTP port.

* api: add optional TLS/SSL

* docs: reference API security settings

* api: when configured securely, bind to all available interfaces by default

* cleanup: remove unused cert artifacts

* tests: generate fresh webserver certificates

* certs: actually add the binary keystores 🤦
2021-10-19 14:13:20 -07:00
Karol Bucek
a4712291d5
Refactor: avoid global mutex on ecs_compatibility (#13036) 2021-08-24 11:24:32 +02:00
Rob Bavey
4707cbd94c
Bundler: freeze lockfile on run, and "normalize" platform on plugin changes (#13015)
This PR enables the upgrade of bundler to the latest version.

Prior to this PR, the ability to do so was blocked by bundler.setup in versions of bundler > `2.23` making runtime changes to `Gemfile.lock` (unless the lock file was `frozen`) based on the specific platform the application was being run on, overriding any platforms (including generic `java` platform) set during build time. This was in conflict with changes made in #12782, which prevented the logstash user writing to files in `/usr/share/logstash`.

This PR will freeze the lockfile when logstash is run, and unfreeze it when manipulating plugins (install, update, remove, install from offline pack) to allow new plugins to be added. While unfrozen, changes are also made to ensure that the platform list remains as the generic `java` platform, and not changed to the specific platform for the runtime JVM.

This PR also introduces a new runtime flag, `--enable-local-plugin-development`. This flag is intended for use by Logstash developers only, and enables a mode of operation where a Gemfile can be manipulated, eg

```
gem "logstash-integration-kafka", :path => '/users/developer/code/plugins/logstash-integration-kafka'
```

to facilitate quick and simple plugin testing.

This PR also sets the `silence_root_warning` flag to avoid bundler printing out alarming looking warning messages when `sudo` is used. This warning message was concerning for users - it would be printed out during normal operation of `bin/logstash-plugin install/update/remove` when run under `sudo`, which is the expected mode of operation when logstash is installed to run as a service via rpm/deb packages. 

This PR also updates the vagrant based integration tests to ensure that Logstash still runs after plugin update/install/remove operations, fixes up some regular expressions that would cause test failures, and removes some dead code from tests.

## Release notes

* Updated Bundler to latest version
* Ensured that `Gemfile.lock` are appropriately frozen
* Added new developer-only flag to facilitate local plugin development to allow unfrozen lockfile in a development environment
2021-08-17 09:35:30 -04:00
Ry Biesemeyer
68f3cf3d90
ecs_compatibility: revert breaking change; keep disabled as default for 8.0.0 (#13080)
As we close in on the availability of 8.0.0 alphas, we are reassessing which
breaking changes are _necessary_, and which are merely _desired_. And while
we would love to be in a world where ECS was on by default, and have put
substantial effort into designing an upgrade path that would be as simple as
possible, we have determined that the time may not be right to change the
default value out of under our users.

This change restores the default value for `pipeline.ecs_compatibility` to
`disabled`, ensuring pipelines will continue running in Logstash 8 as they have
in Logstash 7 without modification. We will still encourage our users to be
explicit about which behaviour they desire, and will revisit making ECS on by
default at a later date.
2021-07-20 14:45:36 -07:00
Karol Bucek
68c753439d
Feat: event factory support (#13017)
Introduce a `new_event` (factory) interface for the Ruby plugin API.

Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com>

+ Refactor: keep (useful) causes mapping to Ruby errors

+ Refactor: avoid trim-ing (large) json strings

+ Feat: a synchronize(object) {} helper for Ruby

+ Feat: a (thread-safe) lazy_init_attr {} helper
2021-06-28 10:53:56 +02:00
kaisecheng
5a209ba830
Add geoip database metrics to /node/stats API (#13004)
This PR adds geoip database status, last update timestamp, download stats counter to Node Stats API
2021-06-23 17:35:15 +02:00
Ry Biesemeyer
1a4be956c4
ecs: on-by-default plus docs (#12830)
* noop: avoid declaring default value in config file

* docs: ecs compatibility from 7.x perspective

Co-authored-by: Karen Metts <karen.metts@elastic.co>

* ecs: on by default

We know that ECS version 8 will release along-side Logstash 8.0, but its scope
is still coming into focus. In this changeset, we change the default value
of `pipeline.ecs_compatibility` from `disabled` to `v1`, which is a
significantly closer approximation to what will eventually ship in Logstash
8.0.0.

* docs: ecs from 8.x perspective

Co-authored-by: Karen Metts <karen.metts@elastic.co>

Co-authored-by: Karen Metts <karen.metts@elastic.co>
2021-06-21 11:00:08 -07:00
Julien Mailleret
6ae2146a75
Fix UBI source URL (#13008)
This commit fix the source URL for UBI image to ensure that it stays
consistent with the URL generated in
https://artifacts.elastic.co/reports/dependencies/dependencies-current.html
2021-06-21 16:06:10 +02:00
Ry Biesemeyer
49e6b0e010
Allow per-pipeline config of ECS Compatibility mode via Central Management (#12861)
* spec: noop refactor of xpack central management

* spec: validate central management settings loading

* central management: allow pipeline.ordered and pipeline.ecs_compatibility settings
2021-06-17 13:59:53 -07:00
Erwin Dondorp
d19d8c679b
Support for UTF-16 and other multi-byte-character logfiles (#9702)
* Added support for UTF-16 and other multi-byte-character logfiles

* added testcase for usage of \0
2021-05-05 10:22:02 -07:00
Andrea Selva
5e7759767a
Load a plugin by alias name. (#12796)
Introcuce the concept of alias for a plugin.

Creates an AliasRegistry to map plugin aliases to original plugins.
If a real plugin with same name of the an alias is present in the system, then the real plugin take precedence during the
instantiation of the pipeline.

Simplified the error handling in class lookup

Co-authored-by: Ry Biesemeyer <ry.biesemeyer@elastic.co>
2021-04-20 22:21:33 +02:00
Karol Bucek
e8e393bdc7
Fix: logstash-keystore failing with an error (#12784)
* Fix: missing password dependency require

which causes `bin/logstash-keystore` to fail with an error:
```
ERROR: Failed to load settings file from "path.settings". Aborting...
path.setting=/logstash-7.12.0/config, exception=NameError,
message=>uninitialized constant LogStash::Util::Password

```

* Fix: review all LS parts depending on Password

* Test: bin/logstash-keystore create/list
2021-04-08 08:10:36 +02:00
andsel
91996cf2a2 Fix Logstash pipelines management in case of slow loading pipelines or disabled webserver (#12571)
This commit avoid an error in gathering monitoring information when webserver is disabled or is not yet started;
which could happen with slow loading pipelines or no pipelines defined from the central management UI.
2021-02-16 05:54:12 -08:00
andsel
79d8f47437 Separate "not terminated" pipeline state into "running" and "loading".
This change fix the behavior of considering as "running" also pipelines that are still in "loading", both "loading" and "running" is considered as "not terminated".
Fixed a flakyness in tests due to different ways to looks at the same thing: pipeline status.
The pipeline status is determined by both `pipeline.running?` and by `agent.pipelines_running`.
The first checks for an atomic boolean in pipeline object, the second check for the status in PipelineRegistry.

Fixes #12190
2021-02-15 07:23:21 -08:00
kaisecheng
bdb9453293
Fix showing deprecation warning of command line flags (#12592)
Fix missing deprecation warning. Store the deprecation message in memory and remove them once it shows to users

Fixed: #12587
2021-02-03 13:14:29 +01:00
andsel
8bdd601c1b Reintroduce the work done in PR #12614 erroneusly removed by PR #12582 2021-02-02 01:03:17 -08:00
andsel
fd446c9b70 [Doc] added instruction on how to update and when an existing LS installation is update to LS 7.12+ and use JDK15
co-authored-by: karenzone@users.noreply.github.com
2021-02-02 00:12:31 -08:00