This repository was archived by the owner on Apr 22, 2024. It is now read-only.
forked from mParticle/firehose-iterable
-
Notifications
You must be signed in to change notification settings - Fork 3
[PIR-23] Increase maximum allowed data age for event replay #20
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
iterable-extension/src/main/java/com/mparticle/ext/iterable/ErrorResponse.java
This file contains hidden or 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,36 @@ | ||
| package com.mparticle.ext.iterable; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class ErrorResponse { | ||
| @JsonProperty(value="statusCode", required=true) | ||
| public int statusCode; | ||
|
|
||
| @JsonProperty(value="body", required=true) | ||
| public Map<String, String> body; | ||
|
|
||
| public ErrorResponse() {} | ||
|
|
||
| public ErrorResponse(int statusCode, Map<String, String> body) { | ||
| this.statusCode = statusCode; | ||
| this.body = body; | ||
| } | ||
|
|
||
| public int getStatusCode() { | ||
| return statusCode; | ||
| } | ||
|
|
||
| public void setStatusCode(int statusCode) { | ||
| this.statusCode = statusCode; | ||
| } | ||
|
|
||
| public Map<String, String> getBody() { | ||
| return body; | ||
| } | ||
|
|
||
| public void setBody(Map<String, String> body) { | ||
| this.body = body; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,14 +1,15 @@ | ||
| package com.mparticle.ext.iterable; | ||
|
|
||
| import com.amazonaws.services.lambda.runtime.Context; | ||
| import com.amazonaws.services.lambda.runtime.LambdaLogger; | ||
| import com.amazonaws.services.lambda.runtime.RequestStreamHandler; | ||
| import com.mparticle.sdk.model.Message; | ||
| import com.mparticle.sdk.model.MessageSerializer; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.OutputStream; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
|
|
||
| public class IterableLambdaEndpoint implements RequestStreamHandler { | ||
|
|
@@ -19,7 +20,21 @@ public class IterableLambdaEndpoint implements RequestStreamHandler { | |
| @Override | ||
| public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException { | ||
| Message request = serializer.deserialize(input, Message.class); | ||
| Message response = processor.processMessage(request); | ||
| serializer.serialize(output, response); | ||
|
|
||
| try { | ||
| Message message = processor.processMessage(request); | ||
| SuccessResponse success = new SuccessResponse(200, message); | ||
| serializer.serialize(output, success); | ||
| } catch (TooManyRequestsException e) { | ||
| Map<String, String> body = new HashMap<>(); | ||
| body.put("message", "Iterable rate limit exceeded"); | ||
| ErrorResponse error = new ErrorResponse(429, body); | ||
| serializer.serialize(output, error); | ||
| } catch (IOException e) { | ||
| Map<String, String> body = new HashMap<>(); | ||
| body.put("message", e.getMessage()); | ||
| ErrorResponse error = new ErrorResponse(500, body); | ||
|
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. I think if we return this, Lambda metrics will start showing those requests as successful because they don't throw exceptions. It may be better to let the exception through for monitoring unless we know we can track them downstream.
Author
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. That's a good call. I'll stop catching those exceptions unless we get another form of monitoring setup. |
||
| serializer.serialize(output, error); | ||
| } | ||
| } | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
iterable-extension/src/main/java/com/mparticle/ext/iterable/SuccessResponse.java
This file contains hidden or 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,35 @@ | ||
| package com.mparticle.ext.iterable; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.mparticle.sdk.model.Message; | ||
|
|
||
| public class SuccessResponse { | ||
| @JsonProperty(value="statusCode", required=true) | ||
| public int statusCode; | ||
|
|
||
| @JsonProperty(value="body", required=true) | ||
| public Message body; | ||
|
|
||
| public SuccessResponse() {} | ||
|
|
||
| public SuccessResponse(int statusCode, Message body) { | ||
| this.statusCode = statusCode; | ||
| this.body = body; | ||
| } | ||
|
|
||
| public int getStatusCode() { | ||
| return statusCode; | ||
| } | ||
|
|
||
| public void setStatusCode(int statusCode) { | ||
| this.statusCode = statusCode; | ||
| } | ||
|
|
||
| public Message getBody() { | ||
| return body; | ||
| } | ||
|
|
||
| public void setBody(Message body) { | ||
| this.body = body; | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
iterable-extension/src/main/java/com/mparticle/ext/iterable/TooManyRequestsException.java
This file contains hidden or 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,10 @@ | ||
| package com.mparticle.ext.iterable; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class TooManyRequestsException extends IOException { | ||
|
|
||
| public TooManyRequestsException() { | ||
| super(); | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
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.
Is
getId()nullable? If so, I'd add a null check.