diff --git a/.github/workflows/links.yml b/.github/workflows/links.yml new file mode 100644 index 0000000..faf49f7 --- /dev/null +++ b/.github/workflows/links.yml @@ -0,0 +1,25 @@ +name: Link Checker +on: + push: + branches: + - "*" + pull_request: + branches: + - "*" + +jobs: + linkchecker: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: lychee Link Checker + id: lychee + uses: lycheeverse/lychee-action@master + with: + args: --accept=200,403,429 "**/*.html" "**/*.md" "**/*.txt" "**/*.json" + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + - name: Fail if there were link errors + run: exit ${{ steps.lychee.outputs.exit_code }} \ No newline at end of file diff --git a/lib/logstash/outputs/opensearch/http_client.rb b/lib/logstash/outputs/opensearch/http_client.rb index 618b35d..af09e88 100644 --- a/lib/logstash/outputs/opensearch/http_client.rb +++ b/lib/logstash/outputs/opensearch/http_client.rb @@ -93,8 +93,8 @@ def template_install(name, template, force=false) template_put(name, template) end - def last_es_version - @pool.last_es_version + def last_version + @pool.last_version end def maximum_seen_major_version diff --git a/lib/logstash/outputs/opensearch/http_client/pool.rb b/lib/logstash/outputs/opensearch/http_client/pool.rb index 78e298e..68a80f6 100644 --- a/lib/logstash/outputs/opensearch/http_client/pool.rb +++ b/lib/logstash/outputs/opensearch/http_client/pool.rb @@ -77,7 +77,7 @@ def initialize(logger, adapter, initial_urls=[], options={}) @url_info = {} @stopping = false - @last_es_version = Concurrent::AtomicReference.new + @last_version = Concurrent::AtomicReference.new end def start @@ -233,10 +233,10 @@ def healthcheck! # If no exception was raised it must have succeeded! logger.warn("Restored connection to ES instance", url: url.sanitized.to_s) # We reconnected to this node, check its ES version - es_version = get_es_version(url) + version = get_version(url) @state_mutex.synchronize do - meta[:version] = es_version - set_last_es_version(es_version, url) + meta[:version] = version + set_last_version(version, url) meta[:state] = :alive end rescue HostUnreachableError, BadResponseCodeError => e @@ -412,14 +412,13 @@ def return_connection(url) end end - def get_es_version(url) + def get_version(url) request = perform_request_to_url(url, :get, ROOT_URI_PATH) LogStash::Json.load(request.body)["version"]["number"] # e.g. "7.10.0" - #return "7.10.2" end - def last_es_version - @last_es_version.get + def last_version + @last_version.get end def maximum_seen_major_version @@ -429,12 +428,12 @@ def maximum_seen_major_version private # @private executing within @state_mutex - def set_last_es_version(version, url) - @last_es_version.set(version) + def set_last_version(version, url) + @last_version.set(version) major = major_version(version) if @maximum_seen_major_version.nil? - @logger.info("OpenSearch version determined (#{version})", es_version: major) + @logger.info("OpenSearch version determined (#{version})", version: major) set_maximum_seen_major_version(major) elsif major > @maximum_seen_major_version warn_on_higher_major_version(major, url) diff --git a/lib/logstash/outputs/opensearch/template_manager.rb b/lib/logstash/outputs/opensearch/template_manager.rb index e80d6e6..0f80dd1 100644 --- a/lib/logstash/outputs/opensearch/template_manager.rb +++ b/lib/logstash/outputs/opensearch/template_manager.rb @@ -9,7 +9,7 @@ module LogStash; module Outputs; class OpenSearch class TemplateManager - # To be mixed into the elasticsearch plugin base + # To be mixed into the opensearch plugin base def self.install_template(plugin) return unless plugin.manage_template if plugin.template @@ -26,11 +26,11 @@ def self.install_template(plugin) end private - def self.load_default_template(es_major_version, ecs_compatibility) - template_path = default_template_path(es_major_version, ecs_compatibility) + def self.load_default_template(major_version, ecs_compatibility) + template_path = default_template_path(major_version, ecs_compatibility) read_template_file(template_path) rescue => e - fail "Failed to load default template for Elasticsearch v#{es_major_version} with ECS #{ecs_compatibility}; caused by: #{e.inspect}" + fail "Failed to load default template for OpenSearch v#{major_version} with ECS #{ecs_compatibility}; caused by: #{e.inspect}" end def self.install(client, template_name, template, template_overwrite) @@ -45,9 +45,9 @@ def self.template_name(plugin) plugin.template_name end - def self.default_template_path(es_major_version, ecs_compatibility=:disabled) - template_version = es_major_version - default_template_name = "templates/ecs-#{ecs_compatibility}/elasticsearch-#{template_version}x.json" + def self.default_template_path(major_version, ecs_compatibility=:disabled) + template_version = major_version + default_template_name = "templates/ecs-#{ecs_compatibility}/#{template_version}x.json" ::File.expand_path(default_template_name, ::File.dirname(__FILE__)) end diff --git a/lib/logstash/outputs/opensearch/templates/ecs-disabled/elasticsearch-1x.json b/lib/logstash/outputs/opensearch/templates/ecs-disabled/1x.json similarity index 100% rename from lib/logstash/outputs/opensearch/templates/ecs-disabled/elasticsearch-1x.json rename to lib/logstash/outputs/opensearch/templates/ecs-disabled/1x.json diff --git a/lib/logstash/outputs/opensearch/templates/ecs-disabled/elasticsearch-7x.json b/lib/logstash/outputs/opensearch/templates/ecs-disabled/7x.json similarity index 100% rename from lib/logstash/outputs/opensearch/templates/ecs-disabled/elasticsearch-7x.json rename to lib/logstash/outputs/opensearch/templates/ecs-disabled/7x.json diff --git a/lib/logstash/plugin_mixins/opensearch/common.rb b/lib/logstash/plugin_mixins/opensearch/common.rb index 632d4a8..bfd023a 100644 --- a/lib/logstash/plugin_mixins/opensearch/common.rb +++ b/lib/logstash/plugin_mixins/opensearch/common.rb @@ -58,8 +58,8 @@ def finish_register end protected :finish_register - def last_es_version - client.last_es_version + def last_version + client.last_version end def maximum_seen_major_version diff --git a/spec/integration/outputs/no_opensearch_on_startup_spec.rb b/spec/integration/outputs/no_opensearch_on_startup_spec.rb index ef28366..f4702ea 100644 --- a/spec/integration/outputs/no_opensearch_on_startup_spec.rb +++ b/spec/integration/outputs/no_opensearch_on_startup_spec.rb @@ -10,7 +10,7 @@ require "logstash/outputs/opensearch" require_relative "../../../spec/opensearch_spec_helper" -describe "elasticsearch is down on startup", :integration => true do +describe "opensearch is down on startup", :integration => true do let(:event1) { LogStash::Event.new("somevalue" => 100, "@timestamp" => "2014-11-17T20:37:17.223Z", "@metadata" => {"retry_count" => 0}) } let(:event2) { LogStash::Event.new("message" => "a") } @@ -41,22 +41,22 @@ subject.close end - it 'should ingest events when Elasticsearch recovers before documents are sent' do - allow_any_instance_of(LogStash::Outputs::OpenSearch::HttpClient::Pool).to receive(:get_es_version).and_raise(::LogStash::Outputs::OpenSearch::HttpClient::Pool::HostUnreachableError.new(StandardError.new, "big fail")) + it 'should ingest events when OpenSearch recovers before documents are sent' do + allow_any_instance_of(LogStash::Outputs::OpenSearch::HttpClient::Pool).to receive(:get_version).and_raise(::LogStash::Outputs::OpenSearch::HttpClient::Pool::HostUnreachableError.new(StandardError.new, "big fail")) subject.register - allow_any_instance_of(LogStash::Outputs::OpenSearch::HttpClient::Pool).to receive(:get_es_version).and_return(OpenSearchHelper.version) + allow_any_instance_of(LogStash::Outputs::OpenSearch::HttpClient::Pool).to receive(:get_version).and_return(OpenSearchHelper.version) subject.multi_receive([event1, event2]) @es.indices.refresh r = @es.search(index: 'logstash-*') expect(r).to have_hits(2) end - it 'should ingest events when Elasticsearch recovers after documents are sent' do - allow_any_instance_of(LogStash::Outputs::OpenSearch::HttpClient::Pool).to receive(:get_es_version).and_raise(::LogStash::Outputs::OpenSearch::HttpClient::Pool::HostUnreachableError.new(StandardError.new, "big fail")) + it 'should ingest events when OpenSearch recovers after documents are sent' do + allow_any_instance_of(LogStash::Outputs::OpenSearch::HttpClient::Pool).to receive(:get_version).and_raise(::LogStash::Outputs::OpenSearch::HttpClient::Pool::HostUnreachableError.new(StandardError.new, "big fail")) subject.register Thread.new do sleep 4 - allow_any_instance_of(LogStash::Outputs::OpenSearch::HttpClient::Pool).to receive(:get_es_version).and_return(OpenSearchHelper.version) + allow_any_instance_of(LogStash::Outputs::OpenSearch::HttpClient::Pool).to receive(:get_version).and_return(OpenSearchHelper.version) end subject.multi_receive([event1, event2]) @es.indices.refresh diff --git a/spec/unit/outputs/opensearch/http_client/pool_spec.rb b/spec/unit/outputs/opensearch/http_client/pool_spec.rb index ca66f9f..a57ec0f 100644 --- a/spec/unit/outputs/opensearch/http_client/pool_spec.rb +++ b/spec/unit/outputs/opensearch/http_client/pool_spec.rb @@ -16,7 +16,7 @@ let(:adapter) { LogStash::Outputs::OpenSearch::HttpClient::ManticoreAdapter.new(logger) } let(:initial_urls) { [::LogStash::Util::SafeURI.new("http://localhost:9200")] } let(:options) { {:resurrect_delay => 2, :url_normalizer => proc {|u| u}} } # Shorten the delay a bit to speed up tests - let(:es_node_versions) { [ "0.0.0" ] } + let(:node_versions) { [ "0.0.0" ] } subject { described_class.new(logger, adapter, initial_urls, options) } @@ -30,7 +30,7 @@ allow(::Manticore::Client).to receive(:new).and_return(manticore_double) - allow(subject).to receive(:get_es_version).with(any_args).and_return(*es_node_versions) + allow(subject).to receive(:get_version).with(any_args).and_return(*node_versions) end after do @@ -214,7 +214,7 @@ end context "if there are nodes with multiple major versions" do - let(:es_node_versions) { [ "0.0.0", "6.0.0" ] } + let(:node_versions) { [ "0.0.0", "6.0.0" ] } it "picks the largest major version" do expect(subject.maximum_seen_major_version).to eq(6) end diff --git a/spec/unit/outputs/opensearch/template_manager_spec.rb b/spec/unit/outputs/opensearch/template_manager_spec.rb index 1caf92a..8e26406 100644 --- a/spec/unit/outputs/opensearch/template_manager_spec.rb +++ b/spec/unit/outputs/opensearch/template_manager_spec.rb @@ -15,7 +15,7 @@ describe ".default_template_path" do context 'when ECS v1 is requested' do it 'resolves' do - expect(described_class.default_template_path(7, :v1)).to end_with("/templates/ecs-v1/elasticsearch-7x.json") + expect(described_class.default_template_path(7, :v1)).to end_with("/templates/ecs-v1/7x.json") end end end diff --git a/spec/unit/outputs/opensearch_spec.rb b/spec/unit/outputs/opensearch_spec.rb index d496872..91d2670 100644 --- a/spec/unit/outputs/opensearch_spec.rb +++ b/spec/unit/outputs/opensearch_spec.rb @@ -279,7 +279,7 @@ let(:events) { [ ::LogStash::Event.new("foo" => "bar1"), ::LogStash::Event.new("foo" => "bar2") ] } let(:bulk_response) do - # shouldn't really happen but we've seen this happen - here ES returns more items than were sent + # shouldn't really happen but we've seen this happen - here OpenSearch returns more items than were sent { "took"=>1, "ingest_took"=>9, "errors"=>true, "items"=>[{"index"=>{"_index"=>"bar1", "_type"=>"_doc", "_id"=>nil, "status"=>500, "error"=>{"type" => "illegal_state_exception", @@ -752,7 +752,7 @@ end - describe "post-register ES setup" do + describe "post-register OpenSearch setup" do let(:do_register) { false } let(:version) { '7.10.0' } let(:options) { { 'hosts' => '127.0.0.1:9999' } } @@ -761,7 +761,7 @@ before do allow(logger).to receive(:error) # expect tracking - allow(subject).to receive(:last_es_version).and_return version + allow(subject).to receive(:last_version).and_return version # make successful_connection? return true: allow(subject).to receive(:maximum_seen_major_version).and_return Integer(version.split('.').first) allow(subject).to receive(:stop_after_successful_connection_thread) diff --git a/spec/unit/outputs/opensearch_ssl_spec.rb b/spec/unit/outputs/opensearch_ssl_spec.rb index 71e69a1..9be7b68 100644 --- a/spec/unit/outputs/opensearch_ssl_spec.rb +++ b/spec/unit/outputs/opensearch_ssl_spec.rb @@ -40,7 +40,7 @@ subject.close end - it "should pass the flag to the ES client" do + it "should pass the flag to the OpenSearch client" do expect(::Manticore::Client).to receive(:new) do |args| expect(args[:ssl]).to eq(:enabled => true, :verify => false) end.and_return(manticore_double) @@ -79,7 +79,7 @@ next LogStash::Outputs::OpenSearch.new(settings) end - it "should pass the keystore parameters to the ES client" do + it "should pass the keystore parameters to the OpenSearch client" do expect(::Manticore::Client).to receive(:new) do |args| expect(args[:ssl]).to include(:keystore => keystore_path, :keystore_password => "test") end.and_call_original