Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/links.yml
Original file line number Diff line number Diff line change
@@ -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 }}
4 changes: 2 additions & 2 deletions lib/logstash/outputs/opensearch/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 10 additions & 11 deletions lib/logstash/outputs/opensearch/http_client/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions lib/logstash/outputs/opensearch/template_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/logstash/plugin_mixins/opensearch/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions spec/integration/outputs/no_opensearch_on_startup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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") }

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/outputs/opensearch/http_client/pool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/outputs/opensearch/template_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/outputs/opensearch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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' } }
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/outputs/opensearch_ssl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down