Skip to content

Commit 79417b1

Browse files
authored
Log partial success warnings (#45)
* Log partial success warnings * Version and changelog * Add test and fix condition * Review comments
1 parent 5a84474 commit 79417b1

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.7.2
2+
3+
- Log response bodies when the response is `200` indicating the request was only partially accepted
4+
15
## 0.7.1
26

37
- Fix an error where max payload size was calculated using character count instead of bytes

lib/logstash/outputs/dynatrace.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ def log_retryable_response(response)
160160
end
161161
end
162162

163+
def log_partial_success_response(response)
164+
@logger.warn("Encountered partial success response", code: response.code, body: response.body)
165+
end
166+
163167
def log_error_response(response, ingest_endpoint_url, event)
164168
log_failure(
165169
"Encountered non-2xx HTTP code #{response.code}",
@@ -267,6 +271,8 @@ def send_event(event, attempt)
267271
response = client.post(ingest_endpoint_url, body: event, headers: headers)
268272

269273
if response_success?(response)
274+
# some events were not accepted but we don't know which ones or why
275+
log_partial_success_response(response) if response_partial_success?(response)
270276
[:success, event, attempt]
271277
elsif retryable_response?(response)
272278
log_retryable_response(response)
@@ -315,6 +321,10 @@ def response_success?(response)
315321
response.code >= 200 && response.code <= 299
316322
end
317323

324+
def response_partial_success?(response)
325+
response.code == 200
326+
end
327+
318328
def retryable_response?(response)
319329
RETRYABLE_CODES.include?(response.code)
320330
end

spec/outputs/dynatrace_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@
168168
end
169169
end
170170

171+
context 'with partial success responses' do
172+
let(:ingest_endpoint_url) { "http://localhost:#{port}/partial" }
173+
174+
before do
175+
allow(subject).to receive(:log_partial_success_response)
176+
end
177+
178+
it 'should warn on partial success' do
179+
subject.multi_receive([event])
180+
expect(subject).to have_received(:log_partial_success_response)
181+
end
182+
end
183+
171184
context 'with retryable failing requests' do
172185
let(:ingest_endpoint_url) { "http://localhost:#{port}/retry" }
173186
let(:api_key) { 'placeholder-key' }

spec/spec_helper.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ def self.retry_fail_count
9898

9999
multiroute(%w[get post put patch delete], '/good') do
100100
self.class.last_request = request
101-
[200, 'YUP']
101+
[204, 'YUP']
102+
end
103+
104+
multiroute(%w[get post put patch delete], '/partial') do
105+
self.class.last_request = request
106+
[200, 'partial success']
102107
end
103108

104109
multiroute(%w[get post put patch delete], '/bad') do

version.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
logstash-output-dynatrace: '0.7.1'
1+
logstash-output-dynatrace: '0.7.2'

0 commit comments

Comments
 (0)