-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Logstash plugins] fixed config validation bug in output; added tests…
… and retries for input; some doc tweaks
- Loading branch information
1 parent
4810e0b
commit d4ffaab
Showing
13 changed files
with
215 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
integration/logstash-plugins/logstash-input-vespa/spec/inputs/vespa_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# encoding: utf-8 | ||
require "logstash/devutils/rspec/spec_helper" | ||
require "logstash/inputs/vespa" | ||
require "webmock/rspec" | ||
|
||
describe LogStash::Inputs::Vespa do | ||
let(:config) do | ||
{ | ||
"cluster" => "test-cluster", | ||
"vespa_url" => "http://localhost:8080", | ||
"retry_delay" => 0.1, # Small delay for faster tests | ||
"max_retries" => 3 | ||
} | ||
end | ||
|
||
let(:plugin) { described_class.new(config) } | ||
let(:queue) { Queue.new } | ||
let(:base_uri) { "#{config['vespa_url']}/document/v1/" } | ||
let(:uri_params) { "cluster=test-cluster&wantedDocumentCount=100&concurrency=1&timeout=180" } | ||
|
||
before do | ||
plugin.register | ||
allow(plugin).to receive(:sleep) # Mock sleep to speed up tests | ||
end | ||
|
||
describe "#run" do | ||
context "when server returns retriable errors" do | ||
it "retries on 503 Service Unavailable" do | ||
stub_request(:get, "#{base_uri}?#{uri_params}") | ||
.to_return( | ||
{ status: 503, body: "Service Unavailable" }, | ||
{ status: 503, body: "Service Unavailable" }, | ||
{ status: 200, body: '{"documents": [], "documentCount": 0}' } | ||
) | ||
|
||
plugin.run(queue) | ||
expect(a_request(:get, "#{base_uri}?#{uri_params}")).to have_been_made.times(3) | ||
end | ||
|
||
it "retries on 502 Bad Gateway" do | ||
stub_request(:get, "#{base_uri}?#{uri_params}") | ||
.to_return( | ||
{ status: 502, body: "Bad Gateway" }, | ||
{ status: 200, body: '{"documents": [], "documentCount": 0}' } | ||
) | ||
|
||
plugin.run(queue) | ||
expect(a_request(:get, "#{base_uri}?#{uri_params}")).to have_been_made.times(2) | ||
end | ||
|
||
it "stops after max_retries attempts" do | ||
stub_request(:get, "#{base_uri}?#{uri_params}") | ||
.to_return(status: 503, body: "Service Unavailable").times(4) | ||
|
||
plugin.run(queue) | ||
expect(a_request(:get, "#{base_uri}?#{uri_params}")).to have_been_made.times(config["max_retries"]) | ||
end | ||
end | ||
|
||
context "when server returns non-retriable errors" do | ||
it "does not retry on 404 Not Found" do | ||
stub_request(:get, "#{base_uri}?#{uri_params}") | ||
.to_return(status: 404, body: "Not Found") | ||
|
||
plugin.run(queue) | ||
expect(a_request(:get, "#{base_uri}?#{uri_params}")).to have_been_made.times(1) | ||
end | ||
|
||
it "does not retry on 401 Unauthorized" do | ||
stub_request(:get, "#{base_uri}?#{uri_params}") | ||
.to_return(status: 401, body: "Unauthorized") | ||
|
||
plugin.run(queue) | ||
expect(a_request(:get, "#{base_uri}?#{uri_params}")).to have_been_made.times(1) | ||
end | ||
end | ||
|
||
context "when server returns successful responses" do | ||
it "processes documents and follows continuation tokens" do | ||
|
||
# First response with continuation token | ||
first_response = { | ||
"pathId" => "/document/v1/", | ||
"documents" => [ | ||
{"id" => "id:namespace:doctype::doc1", "fields" => {"field1" => "value1", "field2" => 7.0}}, | ||
{"id" => "id:namespace:doctype::doc2", "fields" => {"field1" => "value2", "field2" => 8.0}} | ||
], | ||
"documentCount" => 2, | ||
"continuation" => "AAAAAA" | ||
} | ||
|
||
# Second response without continuation (last page) | ||
last_response = { | ||
"pathId" => "/document/v1/", | ||
"documents" => [ | ||
{"id" => "id:namespace:doctype::doc3", "fields" => {"field1" => "value3", "field2" => 9.0}} | ||
], | ||
"documentCount" => 1 | ||
} | ||
|
||
# Stub the requests | ||
stub_request(:get, "#{base_uri}?#{uri_params}") | ||
.to_return(status: 200, body: first_response.to_json) | ||
|
||
stub_request(:get, "#{base_uri}?#{uri_params}&continuation=AAAAAA") | ||
.to_return(status: 200, body: last_response.to_json) | ||
|
||
plugin.run(queue) | ||
|
||
expect(queue.size).to eq(3) # Total of 3 documents | ||
expect(a_request(:get, "#{base_uri}?#{uri_params}")).to have_been_made.once | ||
expect(a_request(:get, "#{base_uri}?#{uri_params}&continuation=AAAAAA")).to have_been_made.once | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.5.0 | ||
0.5.1 |
Binary file added
BIN
+42.6 KB
integration/logstash-plugins/logstash-output-vespa/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
integration/logstash-plugins/logstash-output-vespa/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters