16
16
subject ( :plugin ) { LogStash ::Filters ::ElasticIntegration . new ( config ) }
17
17
18
18
let ( :mock_geoip_database_manager ) { double ( "LogStash::GeoipDatabaseManagement::Manager" , :enabled? => false ) }
19
- before ( :each ) { allow ( plugin ) . to receive ( :load_geoip_database_manager! ) . and_return ( mock_geoip_database_manager ) }
19
+ before ( :each ) {
20
+ allow ( plugin ) . to receive ( :load_geoip_database_manager! ) . and_return ( mock_geoip_database_manager )
21
+ allow ( plugin ) . to receive ( :logger ) . and_return ( mock_logger )
22
+ }
23
+
24
+ let ( :mock_logger ) { double ( "Logger" ) . as_null_object }
20
25
21
26
describe 'the plugin class' do
22
27
subject { described_class }
29
34
allow ( java . lang . System ) . to receive ( :getProperty ) . with ( "java.specification.version" ) . and_return ( "11.0.16.1" )
30
35
end
31
36
32
- it 'prevents initialization and presents helpful guidancee ' do
37
+ it 'prevents initialization and presents helpful guidance ' do
33
38
expect { described_class . new ( { } ) } . to raise_error ( LogStash ::EnvironmentError )
34
39
. with_message ( including ( "requires Java 17 or later" , # reason +
35
40
"current JVM version `11.0.16.1`" ,
65
70
66
71
describe "plugin register" do
67
72
68
- before ( :each ) { allow ( plugin ) . to receive ( :perform_preflight_check! ) . and_return ( true ) }
73
+ before ( :each ) { allow ( plugin ) . to receive ( :connected_es_version_info ) . and_return ( connected_es_version_info ) }
74
+ before ( :each ) { allow ( plugin ) . to receive ( :check_user_privileges! ) . and_return ( true ) }
75
+ before ( :each ) { allow ( plugin ) . to receive ( :check_es_cluster_license! ) . and_return ( true ) }
69
76
before ( :each ) { allow ( plugin ) . to receive ( :serverless? ) . and_return ( false ) }
70
77
71
78
let ( :registered_plugin ) { plugin . tap ( &:register ) }
72
79
after ( :each ) { plugin . close }
73
80
81
+ let ( :connected_es_version_info ) { { 'number' => '8.17.0' , 'build_flavor' => 'default' } }
82
+
74
83
shared_examples "validate `ssl_enabled`" do
75
84
it "enables SSL" do
76
85
expect ( registered_plugin . ssl_enabled ) . to be_truthy
722
731
end
723
732
end
724
733
734
+ describe "plugin vs connected ES versions compatibility" do
735
+ let ( :config ) { super ( ) . merge ( "hosts" => %w[ 127.0.0.2:9300 ] ) }
736
+ let ( :version ) { LogStash ::Filters ::ElasticIntegration ::VERSION }
737
+ let ( :plugin_major_version ) { version . split ( '.' ) . first . to_i }
738
+ let ( :plugin_minor_version ) { version . split ( '.' ) [ 1 ] . to_i }
739
+ let ( :base_message ) { "This #{ version } version of plugin embedded Ingest node components from Elasticsearch #{ plugin_major_version } .#{ plugin_minor_version } " }
740
+ let ( :expected_message ) { }
741
+
742
+ before ( :each ) { plugin . tap ( &:check_versions_alignment ) }
743
+
744
+ it "informs which version of ES the plugin is built from" do
745
+ expected_message =
746
+ "This plugin v#{ version } is connected to the same MAJOR/MINOR version " +
747
+ "of Elasticsearch v#{ connected_es_version_info [ 'number' ] } ."
748
+
749
+ expect ( mock_logger ) . to have_received ( :info ) . with ( base_message )
750
+ expect ( mock_logger ) . to have_received ( :debug ) . with ( expected_message )
751
+ end
752
+
753
+ shared_examples "version mismatch" do |version_type , ahead_or_behind , first_log_level , second_log_level |
754
+ let ( :connected_es_version_info ) do
755
+ major = plugin_major_version
756
+ minor = plugin_minor_version
757
+ major += ahead_or_behind == :ahead ? -1 : 1 if version_type == :major
758
+ minor += ahead_or_behind == :ahead ? -1 : 1 if version_type == :minor
759
+ { "number" => "#{ major } .#{ minor } .10" , "major" => "#{ major } " , "minor" => "#{ minor } " , "build_flavor" => "default" }
760
+ end
761
+
762
+ it "informs to update" do
763
+ expect ( mock_logger ) . to have_received ( first_log_level ) . with ( base_message )
764
+ expect ( mock_logger ) . to have_received ( second_log_level ) . with ( expected_message )
765
+ end
766
+ end
767
+
768
+ context "plugin major version is behind" do
769
+ let ( :expected_message ) {
770
+ "This plugin v#{ version } is connected to a newer MAJOR version of " +
771
+ "Elasticsearch v#{ connected_es_version_info [ 'number' ] } , and may have trouble loading or " +
772
+ "running pipelines that use new features; for the best experience, " +
773
+ "update this plugin to at least v#{ connected_es_version_info [ 'major' ] } .#{ connected_es_version_info [ 'minor' ] } ."
774
+ }
775
+ include_examples "version mismatch" , :major , :behind , :info , :warn
776
+ end
777
+
778
+ context "plugin major version is ahead" do
779
+ let ( :expected_message ) {
780
+ "This plugin v#{ version } is connected to an older MAJOR version of " +
781
+ "Elasticsearch v#{ connected_es_version_info [ 'number' ] } , and may have trouble loading or " +
782
+ "running pipelines that use features that were deprecated before " +
783
+ "Elasticsearch v#{ plugin_major_version } .0; for the best experience, " +
784
+ "align major/minor versions across the Elastic Stack."
785
+ }
786
+ include_examples "version mismatch" , :major , :ahead , :info , :warn
787
+ end
788
+
789
+ context "plugin minor version is behind" do
790
+ let ( :expected_message ) {
791
+ "This plugin v#{ version } is connected to a newer MINOR version of " +
792
+ "Elasticsearch v#{ connected_es_version_info [ 'number' ] } , and may have trouble loading or " +
793
+ "running pipelines that use new features; for the best experience, " +
794
+ "update this plugin to at least v#{ connected_es_version_info [ 'major' ] } .#{ connected_es_version_info [ 'minor' ] } ."
795
+ }
796
+ include_examples "version mismatch" , :minor , :behind , :info , :warn
797
+ end
798
+
799
+ context "plugin minor version is ahead" do
800
+ let ( :expected_message ) {
801
+ "This plugin v#{ version } is connected to an older MINOR version of " +
802
+ "Elasticsearch v#{ connected_es_version_info [ 'number' ] } ; for the best experience, " +
803
+ "align major/minor versions across the Elastic Stack."
804
+ }
805
+ include_examples "version mismatch" , :minor , :ahead , :info , :info
806
+ end
807
+
808
+ end
725
809
end
726
810
end
0 commit comments