sensu / sensu-ruby-runtime

The Sensu Go Ruby Runtime Asset
MIT License
3 stars 23 forks source link

libyaml missing/broken from release #36

Closed ValkyrieOps closed 3 years ago

ValkyrieOps commented 3 years ago

OS Version CentOS 7.6.1810

Release 0.1.0

Issue Requiring 'yaml' in an asset fails. Attempting to run a require statement manually from irb gives the following output

[root@my_neat_host bin]# ./irb
irb(main):001:0> require 'yaml'
/var/cache/sensu/sensu-agent/2d7800432f90625a02aec4a10b084bc72e253572970694e932b5ccdc72fb30f5cf91ed4b51f90942965df5228e521b8f5f06da3d52b886b172ba08d4130251dc/lib/ruby/2.4.0/yaml.rb:5:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
LoadError: libyaml-0.so.2: cannot open shared object file: No such file or directory - /var/cache/sensu/sensu-agent/2d7800432f90625a02aec4a10b084bc72e253572970694e932b5ccdc72fb30f5cf91ed4b51f90942965df5228e521b8f5f06da3d52b886b172ba08d4130251dc/lib/ruby/2.4.0/x86_64-linux/psych.so
        from /var/cache/sensu/sensu-agent/2d7800432f90625a02aec4a10b084bc72e253572970694e932b5ccdc72fb30f5cf91ed4b51f90942965df5228e521b8f5f06da3d52b886b172ba08d4130251dc/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /var/cache/sensu/sensu-agent/2d7800432f90625a02aec4a10b084bc72e253572970694e932b5ccdc72fb30f5cf91ed4b51f90942965df5228e521b8f5f06da3d52b886b172ba08d4130251dc/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /var/cache/sensu/sensu-agent/2d7800432f90625a02aec4a10b084bc72e253572970694e932b5ccdc72fb30f5cf91ed4b51f90942965df5228e521b8f5f06da3d52b886b172ba08d4130251dc/lib/ruby/2.4.0/psych.rb:8:in `<top (required)>'
        from /var/cache/sensu/sensu-agent/2d7800432f90625a02aec4a10b084bc72e253572970694e932b5ccdc72fb30f5cf91ed4b51f90942965df5228e521b8f5f06da3d52b886b172ba08d4130251dc/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /var/cache/sensu/sensu-agent/2d7800432f90625a02aec4a10b084bc72e253572970694e932b5ccdc72fb30f5cf91ed4b51f90942965df5228e521b8f5f06da3d52b886b172ba08d4130251dc/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /var/cache/sensu/sensu-agent/2d7800432f90625a02aec4a10b084bc72e253572970694e932b5ccdc72fb30f5cf91ed4b51f90942965df5228e521b8f5f06da3d52b886b172ba08d4130251dc/lib/ruby/2.4.0/yaml.rb:6:in `<top (required)>'
        from /var/cache/sensu/sensu-agent/2d7800432f90625a02aec4a10b084bc72e253572970694e932b5ccdc72fb30f5cf91ed4b51f90942965df5228e521b8f5f06da3d52b886b172ba08d4130251dc/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /var/cache/sensu/sensu-agent/2d7800432f90625a02aec4a10b084bc72e253572970694e932b5ccdc72fb30f5cf91ed4b51f90942965df5228e521b8f5f06da3d52b886b172ba08d4130251dc/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'

Don't know if this is expected behavior but it seems to be hit or miss whether or not standard libraries load correctly. Running ./gem also fails in a similar fashion. Please let me know if I can provide any more info here. Thanks

jspaleta commented 3 years ago

I'm missing the context here, what do you mean from "inside an asset?"

when sensu-agent or sensu-backend make use of runtime assets the modify several environment variables, appending directories to both library search path and executable paths.

So I'm not sure what you are trying to show me with the command snippet because I don't know if you have prepared your interactive shell environment to mimic the behavior that sensu-agent does when using runtime assets before calling a check command.

ValkyrieOps commented 3 years ago

My fault I should have provided a better explanation. So to clarify, I have an asset which contains several ruby scripts (built as a gem), one of which calls for libyaml. The check that utilizes this asset also includes the sensu-ruby-runtime asset to provide ruby. That check is currently failing and in order to debug (perhaps incorrectly), I have attempted to load up irb on the host the check executes on to try and step through the issue.

I've done this in the past for other assets/checks by calling ruby from the sensu-agent asset cache bin directory, followed by the failing asset/checks location. In this case when doing so I am unable to load libyaml. Similarly trying to execute gem list, or a require 'yaml' statement from the sensu-ruby-runtime bin dir fails in the same way. Apologies if this methodology is incorrect or shouldn't work to begin with.

jspaleta commented 3 years ago

Okay so, not all possible native C library extensions are provided by the runtime asset. Only the things needed to build ruby-runtime itself.

If you are building a ruby based asset that needs additional compiled C libraries (instead of just pure Ruby) then you'll need to provide those libraries as part of the asset you are building.

Here's an example you can work from: https://github.com/sensu-plugins/sensu-plugins-postgres look at the .travis,yml and then the Dockerfiles in asset_build_scripts/ to customize the build process.

In the case of postgres, there's a need to install the postgres C library as the ruby gem calls into that C library. You'll probably need to do something similar for the libyaml. Notice the Dockerfiles do some cleverness with ldd to extract

When using irb to test, you need to make sure you update the LD_LIBRARY_PATH to also include your asset's library directory.

Here's where I do my sales pitch for migrating to golang for Sensu assets..its just soooo much easier to maintain. But if you need to use ruby for internal use, the postgres repo should provide you with a pattern you can follow.

ValkyrieOps commented 3 years ago

Thanks for the swift reply. Was actually just looking at that example you provided to see what I'm missing so we can chalk this up to a case of pebkac. Long term I agree it'll be better to migrate all the checks to golang for ease of use but unfortunately I'm stuck with some of this legacy stuff for now. Not the end of the world. I appreciate your feedback and thank you again!