Commit graph

1569 commits

Author SHA1 Message Date
Andrea Selva
830733d758
Provide opt-in flag to avoid fields name clash when log format is json (#15969)
Adds log.format.json.fix_duplicate_message_fields feature flag to rename the clashing fields when json logging format (log.format) is selected.
In case two message fields clashes on structured log message, then the second is renamed attaching _1 suffix to the field name.
By default the feature is disabled and requires user to explicitly enable the behaviour.

Co-authored-by: Rob Bavey <rob.bavey@elastic.co>
2024-04-17 16:37:05 +02:00
Mashhur
9483ee04c6
Fix the exception behavior when config.string contains ${VAR} in the comments. (#16050)
* Wipe out comment lines if config comment contains.

* Remove substitution var process when loading the YAML, instead align on the generic approach which LSCL happens during the pipeline compile.

* Update logstash-core/src/main/java/org/logstash/config/ir/PipelineConfig.java

Put the logging config back as it is being used with composed configs.
2024-04-11 07:32:28 -07:00
Andrea Selva
afa646fbcb
Introduce a new setting to give preference to Java heap or direct space buffer allocation type (#16054)
Introduce a new setting named `pipeline.buffer.type` which could be valued direct or heap to enable the allocation on Java heap.
The processing of the setting is done in `LogStash::Runner#execute` and sets the Java properties considered by Netty to disable the direct allocation: `io.netty.noPreferDirect`.
However, if that system property is already configured explicitly by the user (because set in `jvm.options`or `LS_JAVA_OPTS`) the setting doesn't take place and warning log is reported, respecting the user's will.

Co-authored-by: João Duarte <jsvd@users.noreply.github.com>
2024-04-10 15:23:47 +02:00
Andrea Selva
6a04854e4c
JDK 21 move (#15719)
Adaptations to run Logstash on JDK 21:

- Java 8 support is obsolete and will be removed.
- Thread's `getId` (not final) replaced by final `threadId` https://bugs.openjdk.org/browse/JDK-8017617
- Verify the warnings "this-escape" when a constructor use other method or pass around `this` reference to other methods https://bugs.openjdk.org/browse/JDK-8015831
- URL constructor is deprecated, use `<uri_instance>.toURL()` (since JDK 20)
-  Manages new (since JDK 20) `G1 Concurrent GC` MX Bean, [ref](https://github.com/elastic/logstash/pull/15719#issuecomment-1946367785)
2024-04-03 17:08:12 +02:00
João Duarte
59bd376360
upgrade ruby-maven-libs to 3.8.9 (#15894)
Given that JRuby comes with ruby-maven-libs 3.3.9 this commit upgrades the gem to 3.8.9 and ensures files from 3.3.9 are not included in the distribution.
2024-03-18 14:30:13 +01:00
carrychair
d1e624b81c
remove repetitions of "the" word (#15987)
Signed-off-by: carrychair <linghuchong404@gmail.com>
2024-03-17 10:53:59 +00:00
Andrea Selva
834c779c5a
Remove dlq writer dead code add some logs (#15965)
Remove unused method createFlushScheduler and add some debug logs to the finalizeSegment method to better follow what happens during its execution in case of problems.
2024-02-22 14:06:53 +01:00
Andrea Selva
18bbb3156c
Add shutdown step of DLQ flusher scheduled service (#15964)
This PR adds a shutdown method to the SchedulerService class used to handle actions to be executed on a certain cadence. In particular is used to execute scheduled finalization of DLQ head segment.
Updates the close method of the DLQ writer to invoke this additional shutdown on the service instance.
2024-02-22 12:33:23 +01:00
Andrea Selva
ff37e1e0d3
Fix failing DLQ test due to time scheduling (#15960)
Adds a burning of time condition to avoid a collision of time which, under certain circumstances, would fail the test.
The sealing of a segment happens if the segment is considered as stale, which requires 2 conditions:

- the segment must have received a write.
- the time of the last write must exceed the flush interval.

In this failing test, the flush interval is set to ZERO because of the synchronicity of the test, to avoid time dependency. However, with coarse grain timer resolution, could happen that the last write coincide with the time of the stale check, so fail the seal condition.
2024-02-22 11:28:31 +01:00
Ry Biesemeyer
38e8c5d3f9
flow_metrics: pull worker_utilization up to pipeline-level (#15912) 2024-02-06 11:50:34 -08:00
Dimitrios Liappis
c33afd4cd0
Mute DLQ test on Windows (#15843)
This commit mutes the DLQ test:
`testDLQWriterFlusherRemovesExpiredSegmentWhenCurrentHeadSegmentIsEmpty`
when running on Windows.

Closes https://github.com/elastic/logstash/issues/15768
2024-01-24 09:53:56 +02:00
Pavel Zorin
2c83a52380
[CI] Send Java and ruby tests to sonarqube simultaneously (#15810)
* Ruby code coverage with SimpleCov json formatter

* [CI] Send Java and ruby tests to sonarqube simultaneously

* Enabled COVERAGE for ruby tests

* Enabled COVERAGE for ruby tests

* Enabled COVERAGE for ruby tests

* Enabled COVERAGE for ruby tests

* Enabled COVERAGE for ruby tests

* Added compiled classes to artifacts

* Test change

* Removed test changes

* Returned back ENABLE_SONARQUBE condition

* Removed debug line

* Diable Ruby coverage if ENABLE_SONARQUBE is not true

* Run sonar scan on pull requests and onn push to main

* Run sonar can on release branches
2024-01-17 19:04:37 +00:00
Andrea Selva
50a589493c
Bump Puma lower version constraint to >= 6.4.2 (#15773) 2024-01-10 09:52:56 +00:00
Edmo Vamerlatti Costa
a21ced0946
Add system properties to configure Jackson's stream read constraints (#15720)
This commit added a few jvm.options properties to configure the Jackson read constraints defaults (Maximum Number value length, Maximum String value length, and Maximum Nesting depth).
2024-01-08 17:48:11 +01:00
Edmo Vamerlatti Costa
41ec183f09
Fix logstash-keystore multiple keys operations with command flags (#15737)
This commit fixes how the keystore tool handle the command's options, including validation for unknown options, and adding the --stdin flag to the add command.
2024-01-03 18:57:57 +01:00
Andrea Selva
48b0af1206
Replace Gradle's report.enabled setting to report's required property (#15706) 2023-12-20 12:40:10 +01:00
Andrea Selva
6b22cc8dd1
Separate scheduling of segments flushes from time (#15680)
Introduces a new interface named SchedulerService to abstract from the ScheduledExecutorService to execute the DLQ flushes of segments. Abstracting from time provides a benefit in testing, where the test doesn't have to wait for things to happen, but those things could happen synchronously.
2023-12-18 11:07:02 +01:00
Andrea Selva
eddd91454f
Shutdown DLQ segments flusher only if it has been started (#15649)
In DLQ unit testing sometime the DLQ writer is started explicitly without starting the segments flushers. In such cases the test 's logs contains exceptions which could lead to think that the test fails silently.

Avoid to invoke scheduledFlusher's shutdown when it's not started (such behaviour is present only in tests).
2023-12-05 09:06:24 +01:00
kaisecheng
05392ad16e
Added missing method of logger wrapper for puma (#15640)
This commit fixes no method error when node stats API got
invalid API path, which triggers puma to print error using stderr

Fix: #15639
2023-11-30 13:53:18 +00:00
Edmo Vamerlatti Costa
5543e3c3b2
Add support to add and remove multiple keystore keys in a single operation (#15612)
This commit added support to add and remove multiple keystore keys in a single operation. It also fixed the empty value validation for editing existing key values and added ASCII validation for values.
2023-11-30 10:21:51 +01:00
github-actions[bot]
b7c31f3fda
swap dataformat-yaml with snakeyaml (#15599) (#15606)
This removes the dependency on jackson's dataformat-yaml. Since there's only a single place where this library is used in core: to load the plugin alias definition, the code can be replaced by the underlying snakeyaml.

Co-authored-by: Andrea Selva <selva.andre@gmail.com>
(cherry picked from commit 93d8a9da32)

Co-authored-by: João Duarte <jsvd@users.noreply.github.com>
2023-11-22 12:07:10 +00:00
Edmo Vamerlatti Costa
57dc14c92c
Fix issue with Jackson 2.15: Can not write a field name, expecting a value (#15564)
This commit fixes the issue with Jackson > 2.15 and `log.format=json`: "Can not write a field name, expecting a value", by adding a default serializers for JRuby's objects.
2023-11-21 15:30:24 +01:00
Karen Metts
c060c00d7c
Doc: Add Elastic Agent collection (#15528)
Co-authored-by: Rob Bavey <rob.bavey@elastic.co>
2023-11-14 13:55:39 -05:00
Ry Biesemeyer
51886b9102
geoip: extract database manager to stand-alone feature (#15348)
* geoip: extract database manager to stand-alone feature

Introduces an Elastic-licensed GeoipDatabaseManagement tool that can be used
by ANY plugin running on Elastic-licensed Logstash to retrieve a subscription
to a GeoIP database that ensures EULA-compliance and frequent updates, and
migrates the previous Elastic-licensed code-in-Logstash-core extension to
the Geoip Filter to use this new tool, requiring ZERO changes to in-the-wild
versions of the plugin.

The implementation of the new tool follows the previous implementation as
closely as possible, but presents a new interface that ensures that a
consumer can ATOMICALLY subscribe to a database path without risk that the
subscriber will receive an update or expiry before it is finished applying
the initial value:

~~~ ruby
geoip_manager = LogStash::GeoipDatabaseManagement::Manager.instance
subscription = geoip_manager.subscribe('City')

subscription.observe(construct: ->(initial_dbinfo){ },
                     on_update: ->(updated_dbinfo){ },
                     on_expire: ->(       _      ){ })

subscription.release!
~~~

* docs: link in geoip database manager docs

* docs: reorganize pending 'geoip database management' feature

* docs: link to geoip pages from feature index

* geoip: add SubscriptionObserver "interface"

simplifies using Subscription#observe from Java

* geoip: fixup SubscriptionObserver after rename

* geoip: quacking like a SubscriptionObserver is enough

* geoip: simplify constants of legacy geoip filter extension

* geoip: bump logging level to debug for non-actionable log

* geoip: refine log message to omit non-actionable info

* re-enable invokedynamic (was disabled to avoid upstream bug)

* geoip: resolve testing fall-out from filter extension's "private" constants removal

* geoip: consistently use `DataPath#resolve` internally, too
2023-11-06 09:22:23 -08:00
Andrea Selva
90964fb559
Updates callsites synthax for i18n.t method to avoid deprecated and prohibited format (#15500)
Updates invocations of i18n.t method which are leftovers and missed in the original Ruby 3.1 update PR #14861

Without this, some error reporting logs are hidden by the mismatch of arguments error in translate the error message.
2023-10-25 11:42:46 +02:00
João Duarte
e626409695
Update JRuby, JDK and Jackson (#15477)
* update JDK to 17.0.8.1+1
* update JRuby to 9.4.4.0
* update jackson to 2.15.3
2023-10-23 11:17:01 +01:00
Andrea Selva
c0e812158c
Update Guava dependency to 32.1.2 (#15394) 2023-10-10 17:14:23 +02:00
Ry Biesemeyer
70081bbcac
deps: downgrade jruby, keep updated default-gem dependencies (forward-port #15283) (#15369)
* deps: downgrade jruby, keep updated default-gem dependencies (#15283)

forward-ports non-release-branch components of #15283 to `main`

* deps: downgrade jruby, keep updated default-gem dependencies

By downgrading JRuby to 9.4.2.0 we avoid the silent global crash of the
scheduler backing `Concurrent::TimerTask` that occurs when Jruby 9.4.3.0's
invokedynamic promotes a method to run natively, incorrectly.

Upstream bug: https://github.com/jruby/jruby/issues/7904

Along with the downgrade of JRuby itself to 9.4.2.0, we cherry-pick the
updates to gems that were included in the latest JRuby 9.4.3.0 to ensure
we don't back out relevant fixes to stdlib.

We also remove a pinned-dependency on `racc` that is no longer relevant.

Resolves: https://github.com/elastic/logstash/issues/15282

* Imported the licenses for some gems

- cgi
- date
- ffi-binary-libfixposix
- io-console
- net-http
- net-protocol
- reline
- time
- timeout
- uri

* specs: avoid mocking global ::Gem::Dependency::new

* build: remove redundanct dependsOn declaration

* deps: notice use of ffi-binary-libfixposix via Ruby license

this gem is tri-licensed `Ruby` / `EPL-2.0` / `LGPL-2.1-or-later` and
the Ruby license is preferred to EPL when available

---------

Co-authored-by: andsel <selva.andre@gmail.com>

* deps: add license notices for gems moved from default to bundled

---------

Co-authored-by: andsel <selva.andre@gmail.com>
2023-10-03 14:32:28 -07:00
Pavel Zorin
f90647d98d
Sonar integration with Java Tests code coverage (#15279)
* Sonar integration

* Removed sonar from test target
2023-09-15 00:47:38 +02:00
kaisecheng
cd78558121
fix NPE when getting native thread id (#15301)
This commit adds null guard to get the native thread when constructing pipeline report

Fix: #15300
2023-09-14 16:46:26 +01:00
Andrea Selva
58e23fbdc3
Fix the update of Puma (#15271)
Revert PR #15267 which updated Puma in Gemfile.template and correctly place it in logstash-core.gemspec, beeing a dependency of Logstash core.
2023-08-22 12:32:50 +02:00
Edmo Vamerlatti Costa
499091824b
Fix update oldest segment reference order (#15246)
The DeadLetterQueueWriter#updateOldestSegmentReference was sorting the existing segments by the lexicographic file names. For example, if there are a few segments on the DQL path with index 8, 9 and 10, it was choosing the 10 as the oldest segment instead of 8.
This commit changed it to comparing the segment ID as numbers, so the file deletion will happen following the proper order.
2023-08-16 10:00:08 +02:00
Mashhur
e890049c1b
Pipeline to pipeline communication acked queue improvements. (#15173)
* Pipeline to pipeline communication acked queue improvements.

* Handle InterruptedException exception in input back, warn message improvement when in-flight events are partially sent and other minor such as descriptive logs, etc improvements.

* Apply suggestions from code review

Check if queue is open after thread acquires the lock.

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

* Apply suggestions from code review

Unite test case improvement: use `assertThrows` when validating the exception.

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

* Pulling off of introducing  wrap with  operations.

* Introduce  functional interface to broadly use to catch the exception types.

* Addressing comments: do not retry sending inflight events on  case. We still throw  if we get error when opening queue.

* will not be reached input retry logic, removing.

* Move queue close check after thread acquiring a lock. Make read next page interface private since it is an internal use purpose.

* Apply suggestions from code review

Leave a comment for the write lock and remove unnecessary warning with `ensure_delivery=>false`

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

* Remove unused  method, check if current thread acquired lock when accessing next page.

* pq: getting possibly-shared access to next read page is illegal

The private `Queue#nextReadPage()` method requires that the caller has
exclusive ownership of the lock, and failing to have the lock is an
illegal state that cannot be recoverd from; it would leak the
effectively-private `Page` to a caller that cannot reliably use it
without corrupting other callers.

Both callers of this private method already call it with exclusive
access, so this safeguard is merely to prevent future development from
breaking the expectation unknowingly.

As such, we throw an `IllegalStateException`.

* pq: use shared queue-closed check for block and non-block reads

By moving the closed-check from the blocking `Queue#readBatch` to the
shared private `Queue#nextReadPage`, we ensure that both blocking reads
by `Queue#readBatch` and non-blocking reads by `Queue#nonBlockReadBatch`
behave the same when the queue has been closed.

* pq: make exception message constants descriptive

* p2p: clarify comment about cumulating retry behaviour

---------

Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com>
Co-authored-by: Ry Biesemeyer <ry.biesemeyer@elastic.co>
2023-08-08 16:05:41 -07:00
Edmo Vamerlatti Costa
88f42f334e
Fix DeadLetterQueueWriter unable to finalize segment error (#15233)
This commit moves the Files.size(...) call into the try catch block, that way, when the oldest segment is deleted by the DeadLetterQueueReader, no NoSuchFileException will be thrown up, and the writer will gracefully update the oldest segment on the next updateOldestSegmentReference invocation (scheduled flush, entry write, delete expired, etc).
It also adds the volatile keyword to the shared mutable variables, making sure that all the changes will be instantly visible among all the running threads (scheduler & writer).
2023-08-08 16:06:44 +02:00
Andres Rodriguez
cf67cb1377
Rubocop: Enable most SpaceInside cops (#15201)
Enabled:
* SpaceInsideArrayLiteralBrackets
* SpaceInsideParens
* SpaceInsidePercentLiteralDelimiters
* SpaceInsideStringInterpolation
* Add enforced style for SpaceInsideStringInterpolation

Enabled without offenses:
* SpaceInsideArrayPercentLiteral
* Layout/SpaceInsideRangeLiteral
* Layout/SpaceInsideReferenceBrackets
2023-07-20 09:49:46 -04:00
Andres Rodriguez
2165d43e1a
Rubocop: Enable SpaceBefore cops (#15197)
Enables the following cops:

 * Layout/SpaceBeforeBlockBraces
 * Layout/SpaceBeforeBrackets
 * Layout/SpaceBeforeComma
 * Layout/SpaceBeforeComment
 * Layout/SpaceBeforeFirstArg
 * Layout/SpaceBeforeSemicolon
2023-07-18 22:32:17 -04:00
Andres Rodriguez
4255a8fd1c
Rubocop: Enable SpaceAround cops (#15196)
* Enable SpaceARoundBlockParameters
* Enable SpaceAroundEqualsInParameterDefault
* Enable SpaceAroundKeyword
* Enable SpaceAroundOperators
* Enable SpaceBeforeBlockBraces, which yields no changes
2023-07-18 21:11:57 -04:00
Andres Rodriguez
acd87a69e7
Rubocop: Enable various EmptyLine cops (#15194)
Disabled:
 * EmptyLineAfterGuardClause
 * EmptyLineAfterMultilineCondition
 * EmptyLinesAroundAccessModifier

Enabled:
 * Layout/EmptyLineAfterMagicComment
 * Layout/EmptyLineBetweenDefs
 * Layout/EmptyLines
 * Layout/EmptyLinesAroundArguments
 * Layout/EmptyLinesAroundAttributeAccessor
 * Layout/EmptyLinesAroundBeginBody
 * Layout/EmptyLinesAroundBlockBody
 * Layout/EmptyLinesAroundExceptionHandlingKeywords
 * Layout/EmptyLinesAroundMethodBody
 * Layout/EmptyLinesAroundModuleBody
2023-07-18 16:49:16 -04:00
Andres Rodriguez
d95a0bba74
Fix deprecated ERB and BigDecimal instances (#15189) 2023-07-18 08:48:01 -04:00
Andres Rodriguez
1d558c35d0
Fix instances of deprecated class methods (#15183)
Replace ::File.exists? for ::File.exist?
2023-07-17 11:32:46 -04:00
Andres Rodriguez
b63ffea472
Enable SpaceAfterColon, SpaceAfterComma, SpaceAfterSemicolon (#15180)
Enable SpaceAfterColon, SpaceAfterComma, SpaceAfterSemicolon and fix occurrences.
2023-07-14 16:46:35 -04:00
Andres Rodriguez
26ff2f7db9
Enable Style/TrailingEmptyLines and fix ocurrences (#15179) 2023-07-14 14:46:33 -04:00
Andres Rodriguez
5e34aacc6e
Enable trailing whitespace formating (#15174)
* Enable Layout/TrailingWhitespace cop formation
* Remove Trailing Whitespaces
2023-07-14 13:22:02 -04:00
Edmo Vamerlatti Costa
6463a4aab1
Add API SSL supported protocols setting (#15166)
This commit adds a new Logstash API setting to configure the SSL/TLS supported protocols (api.ssl.supported_protocols).
2023-07-14 14:21:20 +02:00
Edmo Vamerlatti Costa
7c472b4498
Updated puma gem from 5.6 to 6.3 (#15158)
This commit updates the puma gem from version 5 to the latest version 6.3.
A few breaking changes were introduced in Puma 6.0.0, which required some refactoring on the Logstash side, especially to adapt it to the "Extracted LogWriter from Events #2798" changes.
Before this PR, all the logs generated by Puma were using the debug level, even the ones that were actually errors and needed attention/action from the users. This commit also changes the log level as following:
error(...): changed from debug to error
unknown_error(..): changed from debug to error
2023-07-12 17:46:34 +02:00
João Duarte
1d1fa7a471
update commons-io commons-compress jrjackson databind (#15125)
* update commons-io to 2.13.0 and commons-compress to 1.23.0

* update databind and jackson
2023-06-29 09:02:32 +02:00
Andrea Selva
26d1c7ccdb
Update to JRuby 9.4 (#14861)
Set of changes to make Logstash compatible to JRuby 9.4.
Bundle JRuby 9.4.3.0

- Redefine space token in `LSCL`  and `grammar` treetop from `_` which would generated methods in the form `def _0` (deprecated since `2.7`) to `sc`.
- `I18n.t` method doesn't accept hash as second argument
- `URI.encode` has been replaced with same functionality with `URI::Parser.new.escape`
- `YAML.load` needs explicit `fallback: false` to return false when the yaml string is empty (or contains only comments)
- JRuby's  `JavaClass` has been removed, now it can use `java.lang.Class` directly
- explicitly require gem `thwait` to satisfy `require "thwait"` (In `Gemfile.template` and `logstash-core/logstash-core.gemspec`)
- fix not args `clone` to be `def clone(*args)`
- fix `Enumeration.each_slice` which from `Ruby 3.1` is [chainable](https://rubyreferences.github.io/rubychanges/3.1.html#enumerableeach_cons-and-each_slice-return-a-receiver) and doesn't return `nil`. JRuby fixed in https://github.com/jruby/jruby/issues/7015
- Expanded `Down.download` arguments map ca16bbed3c302006967413eb9d3862f2da81f7ae
- Avoid to pass `nil` in the list of couples used in `Hash[ <list of couples> ]` which from Ruby `3.0` generates an `ArgumentError`
- Removed space not allowed between method name and parentheses `initialize (` is forbidden. 29b607dcdef98f81a73ad171639fd13aaa65e243
- With [Ruby 2.7 the `Kernel#open`](https://rubyreferences.github.io/rubychanges/2.7.html#network-and-web) doesn't fallback to `URI#open`, fixed test code that used that to verify open port. e5b70de54c5301f51a767da67294092af0cfafdc
- Avoid to drop `rdoc/` folder from vendored JRuby else `bin/logstash -i irb` would crash, commit b71f73e9c6edb81a7b7ae1305047e506f61c6e8c

Co-authored-by: João Duarte <jsvd@users.noreply.github.com>
2023-06-28 13:05:43 +02:00
Edmo Vamerlatti Costa
52bbbaa054
Change shutdown stalled method to also include the main/pipeline thread (#15056)
This commit changed the java_pipeline.rb to include the pipeline/main thread on the stalling threads info list, that way, Logstash can provide users with more helpful information when the stalling thread is the pipeline/main one.
2023-06-20 14:48:45 +02:00
Andres Rodriguez
0b68a36e28
Remove obsolete plugin version notice (#15032)
* Remove unneeded tests
2023-06-02 10:35:35 +01:00
Edmo Vamerlatti Costa
e76e582086
Add missing Elasticsearch SSL settings and replace deprecated options (xpack.monitoring and xpack.management) (#15045)
This commit adds missing Elasticsearch SSL settings and replaces deprecated options being used on `xpack.monitoring.*` and `xpack.management.*` settings:

Changes:
- Updated deprecated monitoring and management Elasticsearch's SSL settings so no warnings are logged.
- Added monitoring settings support for file-based certificates and for the cipher suites: `xpack.monitoring.elasticsearch.ssl.certificate`, `xpack.monitoring.elasticsearch.ssl.key`, and `xpack.monitoring.elasticsearch.ssl.cipher_suites`.
- Added management settings support for file-based certificates and for the cipher suites: `xpack.management.elasticsearch.ssl.certificate`, `xpack.management.elasticsearch.ssl.key`, and `xpack.management.elasticsearch.ssl.cipher_suites`.
2023-05-15 11:54:38 +02:00