-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add response body for partial 207 errors for aggregated payload #751
Merged
VinnyQ
merged 2 commits into
rax-maas:master
from
VinnyQ:response_body_for_partial_failures
Nov 10, 2016
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,18 +37,18 @@ | |
import java.io.*; | ||
import java.net.URISyntaxException; | ||
import java.util.*; | ||
import java.util.regex.Pattern; | ||
import java.util.zip.GZIPOutputStream; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
import static junit.framework.Assert.assertTrue; | ||
import static org.mockito.Mockito.*; | ||
import static org.junit.Assert.*; | ||
import static com.rackspacecloud.blueflood.TestUtils.*; | ||
|
||
public class HttpHandlerIntegrationTest extends HttpIntegrationTestBase { | ||
|
||
static private final String TENANT_ID = "acTEST"; | ||
static private long BEFORE_CURRENT_COLLECTIONTIME_MS = Configuration.getInstance().getLongProperty( CoreConfig.BEFORE_CURRENT_COLLECTIONTIME_MS ); | ||
static private long AFTER_CURRENT_COLLECTIONTIME_MS = Configuration.getInstance().getLongProperty( CoreConfig.AFTER_CURRENT_COLLECTIONTIME_MS ); | ||
|
||
//A time stamp 2 days ago | ||
private final long baseMillis = Calendar.getInstance().getTimeInMillis() - 172800000; | ||
|
@@ -85,7 +85,7 @@ public void testHttpIngestionInvalidPastCollectionTime() throws Exception { | |
|
||
String postfix = getPostfix(); | ||
|
||
long time = System.currentTimeMillis() - TIME_DIFF_MS - Configuration.getInstance().getLongProperty( CoreConfig.BEFORE_CURRENT_COLLECTIONTIME_MS ); | ||
long time = System.currentTimeMillis() - TIME_DIFF_MS - BEFORE_CURRENT_COLLECTIONTIME_MS; | ||
|
||
HttpResponse response = postGenMetric(TENANT_ID, postfix, postPath, time ); | ||
|
||
|
@@ -95,8 +95,8 @@ public void testHttpIngestionInvalidPastCollectionTime() throws Exception { | |
assertEquals("Number of errors invalid", 3, errorResponse.getErrors().size()); | ||
for (int i = 0; i < 3; i++) { | ||
assertEquals("Invalid error source", "collectionTime", errorResponse.getErrors().get(i).getSource()); | ||
assertEquals("Invalid error message", "Out of bounds. Cannot be more than 259200000 milliseconds into the past." + | ||
" Cannot be more than 600000 milliseconds into the future", errorResponse.getErrors().get(0).getMessage()); | ||
assertEquals("Invalid error message", "Out of bounds. Cannot be more than " + BEFORE_CURRENT_COLLECTIONTIME_MS + " milliseconds into the past." + | ||
" Cannot be more than " + AFTER_CURRENT_COLLECTIONTIME_MS + " milliseconds into the future", errorResponse.getErrors().get(i).getMessage()); | ||
} | ||
|
||
} | ||
|
@@ -106,7 +106,7 @@ public void testHttpIngestionInvalidFutureCollectionTime() throws Exception { | |
|
||
String postfix = getPostfix(); | ||
|
||
long time = System.currentTimeMillis() + TIME_DIFF_MS + Configuration.getInstance().getLongProperty( CoreConfig.AFTER_CURRENT_COLLECTIONTIME_MS ); | ||
long time = System.currentTimeMillis() + TIME_DIFF_MS + AFTER_CURRENT_COLLECTIONTIME_MS; | ||
|
||
HttpResponse response = postGenMetric(TENANT_ID, postfix, postPath, time ); | ||
|
||
|
@@ -116,17 +116,17 @@ public void testHttpIngestionInvalidFutureCollectionTime() throws Exception { | |
assertEquals("Number of errors invalid", 3, errorResponse.getErrors().size()); | ||
for (int i = 0; i < 3; i++) { | ||
assertEquals("Invalid error source", "collectionTime", errorResponse.getErrors().get(i).getSource()); | ||
assertEquals("Invalid error message", "Out of bounds. Cannot be more than 259200000 milliseconds into the past." + | ||
" Cannot be more than 600000 milliseconds into the future", errorResponse.getErrors().get(0).getMessage()); | ||
assertEquals("Invalid error message", "Out of bounds. Cannot be more than " + BEFORE_CURRENT_COLLECTIONTIME_MS + " milliseconds into the past." + | ||
" Cannot be more than " + AFTER_CURRENT_COLLECTIONTIME_MS + " milliseconds into the future", errorResponse.getErrors().get(i).getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testHttpIngestionPartialInvalidCollectionTime() throws Exception { | ||
String postfix = getPostfix(); | ||
long validTime = System.currentTimeMillis(); | ||
long pastTime = System.currentTimeMillis() - TIME_DIFF_MS - Configuration.getInstance().getLongProperty( CoreConfig.BEFORE_CURRENT_COLLECTIONTIME_MS ); | ||
long futureTime = System.currentTimeMillis() + TIME_DIFF_MS + Configuration.getInstance().getLongProperty( CoreConfig.AFTER_CURRENT_COLLECTIONTIME_MS ); | ||
long pastTime = System.currentTimeMillis() - TIME_DIFF_MS - BEFORE_CURRENT_COLLECTIONTIME_MS; | ||
long futureTime = System.currentTimeMillis() + TIME_DIFF_MS + AFTER_CURRENT_COLLECTIONTIME_MS; | ||
|
||
String jsonBody = getJsonFromFile("sample_multi_payload_with_different_time.json", postfix); | ||
jsonBody = updateTimeStampJson(jsonBody, "\"%TIMESTAMP_1%\"", validTime); | ||
|
@@ -139,7 +139,11 @@ public void testHttpIngestionPartialInvalidCollectionTime() throws Exception { | |
|
||
try { | ||
assertEquals("Should get status 207 from " + String.format(postMultiPath, TENANT_ID), 207, response.getStatusLine().getStatusCode() ); | ||
assertTrue("", errorResponse.getErrors().size() > 0); | ||
for (int i = 0; i < 4; i++) { | ||
assertEquals("Invalid error source", "collectionTime", errorResponse.getErrors().get(i).getSource()); | ||
assertEquals("Invalid error message", "Out of bounds. Cannot be more than " + BEFORE_CURRENT_COLLECTIONTIME_MS + " milliseconds into the past." + | ||
" Cannot be more than " + AFTER_CURRENT_COLLECTIONTIME_MS + " milliseconds into the future", errorResponse.getErrors().get(i).getMessage()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
finally { | ||
EntityUtils.consume( response.getEntity() ); // Releases connection apparently | ||
|
@@ -149,33 +153,31 @@ public void testHttpIngestionPartialInvalidCollectionTime() throws Exception { | |
@Test | ||
public void testHttpAggregatedIngestionInvalidPastCollectionTime() throws IOException, URISyntaxException { | ||
|
||
long timestamp = System.currentTimeMillis() - TIME_DIFF_MS | ||
- Configuration.getInstance().getLongProperty( CoreConfig.BEFORE_CURRENT_COLLECTIONTIME_MS ); | ||
long timestamp = System.currentTimeMillis() - TIME_DIFF_MS - BEFORE_CURRENT_COLLECTIONTIME_MS; | ||
|
||
HttpResponse response = postMetric("333333", postAggregatedPath, "sample_payload.json", timestamp, getPostfix()); | ||
ErrorResponse errorResponse = getErrorResponse(response); | ||
|
||
assertEquals(400, response.getStatusLine().getStatusCode()); | ||
assertEquals("Number of errors invalid", 1, errorResponse.getErrors().size()); | ||
assertEquals("Invalid error source", "timestamp", errorResponse.getErrors().get(0).getSource()); | ||
assertEquals("Invalid error message", "Out of bounds. Cannot be more than 259200000 milliseconds into the past." + | ||
" Cannot be more than 600000 milliseconds into the future", errorResponse.getErrors().get(0).getMessage()); | ||
assertEquals("Invalid error message", "Out of bounds. Cannot be more than " + BEFORE_CURRENT_COLLECTIONTIME_MS + " milliseconds into the past." + | ||
" Cannot be more than " + AFTER_CURRENT_COLLECTIONTIME_MS + " milliseconds into the future", errorResponse.getErrors().get(0).getMessage()); | ||
} | ||
|
||
@Test | ||
public void testHttpAggregatedIngestionInvalidFutureCollectionTime() throws IOException, URISyntaxException { | ||
|
||
long timestamp = System.currentTimeMillis() + TIME_DIFF_MS | ||
+ Configuration.getInstance().getLongProperty( CoreConfig.AFTER_CURRENT_COLLECTIONTIME_MS ); | ||
long timestamp = System.currentTimeMillis() + TIME_DIFF_MS + AFTER_CURRENT_COLLECTIONTIME_MS; | ||
|
||
HttpResponse response = postMetric("333333", postAggregatedPath, "sample_payload.json", timestamp, getPostfix()); | ||
ErrorResponse errorResponse = getErrorResponse(response); | ||
|
||
assertEquals(400, response.getStatusLine().getStatusCode()); | ||
assertEquals("Number of errors invalid", 1, errorResponse.getErrors().size()); | ||
assertEquals("Invalid error source", "timestamp", errorResponse.getErrors().get(0).getSource()); | ||
assertEquals("Invalid error message", "Out of bounds. Cannot be more than 259200000 milliseconds into the past." + | ||
" Cannot be more than 600000 milliseconds into the future", errorResponse.getErrors().get(0).getMessage()); | ||
assertEquals("Invalid error message", "Out of bounds. Cannot be more than " + BEFORE_CURRENT_COLLECTIONTIME_MS + " milliseconds into the past." + | ||
" Cannot be more than " + AFTER_CURRENT_COLLECTIONTIME_MS + " milliseconds into the future", errorResponse.getErrors().get(0).getMessage()); | ||
} | ||
|
||
@Test | ||
|
@@ -207,8 +209,7 @@ locator, RollupType.COUNTER, new Range( start, end ), | |
@Test | ||
public void testHttpAggregatedMultiIngestionInvalidPastCollectionTime() throws IOException, URISyntaxException { | ||
|
||
long timestamp = System.currentTimeMillis() - TIME_DIFF_MS | ||
- Configuration.getInstance().getLongProperty( CoreConfig.BEFORE_CURRENT_COLLECTIONTIME_MS ); | ||
long timestamp = System.currentTimeMillis() - TIME_DIFF_MS - BEFORE_CURRENT_COLLECTIONTIME_MS; | ||
|
||
String postfix = getPostfix(); | ||
|
||
|
@@ -222,16 +223,15 @@ public void testHttpAggregatedMultiIngestionInvalidPastCollectionTime() throws I | |
|
||
assertEquals("Number of errors invalid", 3, errorResponse.getErrors().size()); | ||
assertEquals("Invalid error source", "timestamp", errorResponse.getErrors().get(0).getSource()); | ||
assertEquals("Invalid error message", "Out of bounds. Cannot be more than 259200000 milliseconds into the past." + | ||
" Cannot be more than 600000 milliseconds into the future", errorResponse.getErrors().get(0).getMessage()); | ||
assertEquals("Invalid error message", "Out of bounds. Cannot be more than " + BEFORE_CURRENT_COLLECTIONTIME_MS + " milliseconds into the past." + | ||
" Cannot be more than " + AFTER_CURRENT_COLLECTIONTIME_MS + " milliseconds into the future", errorResponse.getErrors().get(0).getMessage()); | ||
} | ||
|
||
|
||
@Test | ||
public void testHttpAggregatedMultiIngestionInvalidFutureCollectionTime() throws IOException, URISyntaxException { | ||
|
||
long timestamp = System.currentTimeMillis() + TIME_DIFF_MS | ||
+ Configuration.getInstance().getLongProperty( CoreConfig.AFTER_CURRENT_COLLECTIONTIME_MS ); | ||
long timestamp = System.currentTimeMillis() + TIME_DIFF_MS + AFTER_CURRENT_COLLECTIONTIME_MS; | ||
|
||
String postfix = getPostfix(); | ||
|
||
|
@@ -245,8 +245,8 @@ public void testHttpAggregatedMultiIngestionInvalidFutureCollectionTime() throws | |
|
||
assertEquals("Number of errors invalid", 3, errorResponse.getErrors().size()); | ||
assertEquals("Invalid error source", "timestamp", errorResponse.getErrors().get(0).getSource()); | ||
assertEquals("Invalid error message", "Out of bounds. Cannot be more than 259200000 milliseconds into the past." + | ||
" Cannot be more than 600000 milliseconds into the future", errorResponse.getErrors().get(0).getMessage()); | ||
assertEquals("Invalid error message", "Out of bounds. Cannot be more than " + BEFORE_CURRENT_COLLECTIONTIME_MS + " milliseconds into the past." + | ||
" Cannot be more than " + AFTER_CURRENT_COLLECTIONTIME_MS + " milliseconds into the future", errorResponse.getErrors().get(0).getMessage()); | ||
} | ||
|
||
@Test | ||
|
@@ -292,8 +292,8 @@ locator2, RollupType.ENUM, new Range(start, end), | |
public void testHttpAggregatedMultiPartialInvalidCollectionTime() throws Exception { | ||
String postfix = getPostfix(); | ||
long validTime = System.currentTimeMillis(); | ||
long pastTime = System.currentTimeMillis() - TIME_DIFF_MS - Configuration.getInstance().getLongProperty( CoreConfig.BEFORE_CURRENT_COLLECTIONTIME_MS ); | ||
long futureTime = System.currentTimeMillis() + TIME_DIFF_MS + Configuration.getInstance().getLongProperty( CoreConfig.AFTER_CURRENT_COLLECTIONTIME_MS ); | ||
long pastTime = System.currentTimeMillis() - TIME_DIFF_MS - BEFORE_CURRENT_COLLECTIONTIME_MS; | ||
long futureTime = System.currentTimeMillis() + TIME_DIFF_MS + AFTER_CURRENT_COLLECTIONTIME_MS; | ||
|
||
String jsonBody = getJsonFromFile("sample_multi_aggregated_payload_with_different_time.json", postfix); | ||
jsonBody = updateTimeStampJson(jsonBody, "\"%TIMESTAMP_1%\"", validTime); | ||
|
@@ -302,11 +302,15 @@ public void testHttpAggregatedMultiPartialInvalidCollectionTime() throws Excepti | |
jsonBody = jsonBody.replaceAll("%TENANT_ID_.%", TENANT_ID); | ||
|
||
HttpResponse response = httpPost(TENANT_ID, postAggregatedMultiPath, jsonBody ); | ||
String[] output = getBodyArray(response); | ||
ErrorResponse errorResponse = getErrorResponse(response); | ||
|
||
try { | ||
assertEquals("Should get status 207 from " + String.format(postAggregatedMultiPath, TENANT_ID), 207, response.getStatusLine().getStatusCode() ); | ||
assertEquals("", output[0]); | ||
for (int i = 0; i < 2; i++) { | ||
assertEquals("Invalid error source", "timestamp", errorResponse.getErrors().get(i).getSource()); | ||
assertEquals("Invalid error message", "Out of bounds. Cannot be more than " + BEFORE_CURRENT_COLLECTIONTIME_MS + " milliseconds into the past." + | ||
" Cannot be more than " + AFTER_CURRENT_COLLECTIONTIME_MS + " milliseconds into the future", errorResponse.getErrors().get(i).getMessage()); | ||
} | ||
} | ||
finally { | ||
EntityUtils.consume( response.getEntity() ); // Releases connection apparently | ||
|
@@ -472,7 +476,10 @@ public void testMultiTenantPartialFailureWithoutTenant() throws Exception { | |
|
||
try { | ||
assertEquals("Should get status 207 from " + String.format(postMultiPath, TENANT_ID), 207, response.getStatusLine().getStatusCode()); | ||
assertTrue("No errors found", errorResponse.getErrors().size() > 0); | ||
for (int i = 0; i < 2; i++) { | ||
assertEquals("Invalid error source", "tenantId", errorResponse.getErrors().get(i).getSource()); | ||
assertEquals("Invalid error message", "may not be empty", errorResponse.getErrors().get(i).getMessage()); | ||
} | ||
} | ||
finally { | ||
EntityUtils.consume( response.getEntity() ); // Releases connection apparently | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the first metricName in the list always relate to the current violation? If there isn't a metricName, does that mean that it couldn't be processed, and should be empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I tested this. Each "single" aggregatedPayload will have the metricName of the offending metric as the first element. And actually, it'll always be the case that each instance of AggregatedPayload will only contain one leaf "metric". Here's an example of the part of a payload this class represent:
Even if the metric above is part of a multi-metrics payload like this:
This is because if you look in the HttpAggregatedMultiIngestionHandler class, it first parse the entire json payload to each individual element (stored in bundleList:
https://github.com/rackerlabs/blueflood/blob/master/blueflood-http/src/main/java/com/rackspacecloud/blueflood/inputs/handlers/HttpAggregatedMultiIngestionHandler.java#L76
and
https://github.com/rackerlabs/blueflood/blob/master/blueflood-http/src/main/java/com/rackspacecloud/blueflood/inputs/handlers/HttpAggregatedMultiIngestionHandler.java#L176)
Then for each of the element in bundleList (an AggregatedPayload), it does the validation and create the error payload if there's violation: https://github.com/rackerlabs/blueflood/blob/master/blueflood-http/src/main/java/com/rackspacecloud/blueflood/inputs/handlers/HttpAggregatedMultiIngestionHandler.java#L85
In the majority of the cases, the metricName is set from the previous block in the AggregatedPayload.validate() here: https://github.com/rackerlabs/blueflood/blob/master/blueflood-core/src/main/java/com/rackspacecloud/blueflood/inputs/formats/AggregatedPayload.java#L105-L114
with the assumption that leafBean was created correctly from the json parser.
However, there were cases where the parser itself didn't create the AggregatedPayload element correctly (e.g. a missing "value" field that is required), resulting in the type of the element not being set and an empty metricName. In this case, the only way to retrieve the metricName is through the single json element payload itself.
Hope that make sense. But do know that I tried different cases during testing, including one with multiple aggregated payloads, with the first few being valid and the last one being invalid, and the error response has the correct metricName for the one failing the validation (and not ingested), not the first metricName in the request payload. You'll see a few of this cases in the system integration tests itself.