Skip to content
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

Sequel datetime class consistency #151

Merged

Conversation

yaauie
Copy link
Contributor

@yaauie yaauie commented Jan 23, 2024

Resolves a bug in which any one instance of a JDBC input plugin using jdbc_default_timezone changes the behaviour of plugin instances that do not use jdbc_default_timezone, by:

  • (a) always loading Sequel's named_timezones extension, and
  • (b) preventing Sequel#datetime_class from being anything other than its original default value.

This PR has two commits:

  • one with specs that succeed in isolation but fail when run with the rest of the spec suite (see commit message for details)
  • one with code-changes that ensure the above-provided specs always succeed, and that this plugin always uses the local context to parse times absent explicit configuration for the individual plugin, regardless of how other plugins are configured.

Resolves: #150
Relates: #53
Relat3es: #107

these tests SUCCEED when run on their own, but FAIL when run after any
instance of a plugin has been initialized with `jdbc_default_timezone`,
since doing so globally configures Sequel to use DateTime instead of
Time:

To validate, modify the `.ci/run.sh` execution line to be:
> ~~~
> bundle exec rspec spec --format documentation --example "without jdbc_default_timezone"
> ~~~
By default, when a plugin is configured _without_ `jdbc_default_timezone`
timestamps are assumed to be in the same timezone as the Logstash host
machine, because they are parsed with Ruby's `Time#parse` which uses
local context.

However, when any one plugin declares `jdbc_default_timezone`, we load
Sequel's `named_timezones` extension, which has a side-effect of globally
changing `Sequel.datetime_class` to ruby's `DateTime`. The plugins that
are configured with `jdbc_default_timezone` have enough information to
apply the separately-provided offset, but the plugins that do _not_ have
a `jdbc_default_timezone` directive become broken and effectively
fail to parse the timestamps as they did when run on their own.

Sequel's `named_timezones` extension supports being used with `Time`
objects, and is noted to override `Sequel#datetime_class` on load only
for historic reasons.

We force Sequel to use ruby's `Time` class globally (enforcing its
default and preventing it from being changed). This is done inside
of a separately-required bootstrap, which allows us to ensure it is
loaded exacltly once.
Copy link
Contributor

@andsel andsel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yaauie yaauie merged commit c0583ce into logstash-plugins:main May 23, 2024
2 checks passed
@yaauie yaauie deleted the sequel-datetime-class-consistency branch May 23, 2024 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

setting jdbc_default_timezone in one plugin instance affects behavior of plugins where it is not set
3 participants