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

Fix error if timezone with name is used in parser #2421

Merged
merged 4 commits into from
Jun 5, 2019
Merged

Fix error if timezone with name is used in parser #2421

merged 4 commits into from
Jun 5, 2019

Conversation

jonasrutishauser
Copy link
Contributor

What this PR does / why we need it:
Fixes a TypeError: nil can't be coerced into Integer when a timezone name is used in a parser configuration.

Signed-off-by: Jonas Rutishauser <jonas.rutishauser@alumni.ethz.ch>
@repeatedly
Copy link
Member

Hmm... Could you show the actual example?
timezone Europe/Zurich has this problem?

@jonasrutishauser
Copy link
Contributor Author

Every zone name has this problem (see https://makandracards.com/makandra/67330-why-you-can-t-use-timezone-codes-like-pst-or-bst-for-time-objects).
With daylight saving time it is needed to use a zone name and the validation on line 155 accepts it whilst the parsing implementation on line 206 is not able to handle it.
And yes it is this config:

[...]
<parse>
  [...]
  timezone Europe/Zurich
</parse>
[...]

@repeatedly
Copy link
Member

Thanks. I will check it.

@repeatedly
Copy link
Member

repeatedly commented Jun 5, 2019

Your patch has performance penalty and it is not good for existing users.
So need to rewrite the patch like below:

when timezone
  offset = Fluent::Timezone.utc_offset(timezone)
  if offset.respond_to?(:call)
    ->(t) { Time.now.localtime.utc_offset + offset.call(t) }
  else
    ->(t) { Time.now.localtime.utc_offset + offset }
  end
when strptime
  if offset_diff.respond_to?(:call)
    ->(v) { t = strptime.exec(v); Fluent::EventTime.new(t.to_i + offset_diff.call(t), t.nsec) }
  else
    ->(v) { t = strptime.exec(v); Fluent::EventTime.new(t.to_i + offset_diff, t.nsec) }
  end
# same as format

Signed-off-by: Jonas Rutishauser <jonas.rutishauser@alumni.ethz.ch>
Signed-off-by: Jonas Rutishauser <jonas.rutishauser@alumni.ethz.ch>
@repeatedly
Copy link
Member

@ganmacs Could you also check this patch? I want to release v1.5.1 with this patch.

@repeatedly repeatedly added the bug Something isn't working label Jun 5, 2019
lib/fluent/time.rb Outdated Show resolved Hide resolved
Signed-off-by: Jonas Rutishauser <jonas.rutishauser@alumni.ethz.ch>
@repeatedly repeatedly merged commit 5ca5ddd into fluent:master Jun 5, 2019
@repeatedly
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants