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 default codec instantiation #68

Closed

Conversation

tsaarni
Copy link
Contributor

@tsaarni tsaarni commented Aug 18, 2023

This PR sets the default codec (temporarily) to nil to allow instantiating the default codec with format by testing for nil instead of testing for the class identity, which has not been working since logstash 7.2.0 due to elastic/logstash#11434.

Previously #55 was created with another workaround for the class comparison issue, but it was never merged. There has not been follow-up to this issue since then (as far as I can find).

Fixes #51

Signed-off-by: Tero Saarni <tero.saarni@est.tech>
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.

Asked for more clarifications

@codec = LogStash::Codecs::Plain.new({"format" => @message})
end

if @codec.nil?
Copy link
Contributor

Choose a reason for hiding this comment

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

@tsaarni why defaultnil assigment and then the nil(as if nil is a special value placeholder constant) instead of using the same path suggested in https://github.com/elastic/logstash/pull/11401/files which was listed in the issue you reported (elastic/logstash#11434) ?

Assigning the codec to nil to then change it register time is not a good practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used nil as a special value placeholder in attempt to avoid class identity comparison altogether. Comparing class identity by their string representation seemed bit awkward to me, but I'm happy with any fix as long as it works! :)

There already is a string-based alternative submitted here few years back but for some reason it was not merged #55. If the original submitter @jsvd is around maybe he could reconsider resurrecting the PR, or I can re-submit his fix here and add him as co-author.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW: What I really wanted to do was to set the default :codec to LogStash::Codecs::Plain.new({ "format" => @message }) but I could not achieve that, because obviously I have no access to instance variable @message when defining default codec for the class. If that was possible, it would be possible to avoid instantiating codec in register like introduced here long time ago 2c73283 (change which introduced the class identity comparison).

Copy link
Contributor

Choose a reason for hiding this comment

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

If you run tests on actual main, it fails for that check. To get the test back to green the string comparison works fine like in #65 which is why also this PR is green.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know why PR #55 wasn't merged, but seems the right way to fix it. May in some weeks @jsvd could confirm it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you run tests on actual main, it fails for that check. To get the test back to green the string comparison works fine like in #65 which is why also this PR is green.

Sorry, I did not understand, #65 has failed because of the codec problem as well. Maybe you meant #55? I agree, string comparing works, I'm happy if we get that in!

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad sorry, #69

Copy link
Contributor

Choose a reason for hiding this comment

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

@jsvd confirmed that the #55 was closed for some other reason, mainly because the Travis CI changes were already included.

@andsel
Copy link
Contributor

andsel commented Sep 8, 2023

Hi @tsaarni given that PR #69 fixes this I foresee two paths:

@tsaarni
Copy link
Contributor Author

tsaarni commented Sep 8, 2023

Let's merge #69 and close this one, thank you for fixing the bug!

@tsaarni tsaarni closed this Sep 8, 2023
@andsel
Copy link
Contributor

andsel commented Sep 8, 2023

Great, merged, so now you could rebase the next PR to review and move forward with the others :-)

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.

"message" configuration parameter ignored in Logstash 7.2.0 and up
2 participants