Skip to content

Commit ca31e0d

Browse files
Juan Pablo Diaz-VazJuan Pablo Diaz-Vaz
authored andcommitted
SUMOK-15 Modified the way throttling gets handled
1 parent a037f47 commit ca31e0d

5 files changed

Lines changed: 30 additions & 49 deletions

File tree

src/main/java/com/mcplusa/kinesis/KinesisConnectorExecutor.java

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -128,34 +128,4 @@ private void setupInputStream() {
128128
private static boolean parseBoolean(String property, boolean defaultValue, Properties properties) {
129129
return Boolean.parseBoolean(properties.getProperty(property, Boolean.toString(defaultValue)));
130130
}
131-
132-
/**
133-
* Helper method used to parse long properties.
134-
*
135-
* @param property
136-
* The String key for the property
137-
* @param defaultValue
138-
* The default value for the long property
139-
* @param properties
140-
* The properties file to get property from
141-
* @return property from property file, or if it is not specified, the default value
142-
*/
143-
private static long parseLong(String property, long defaultValue, Properties properties) {
144-
return Long.parseLong(properties.getProperty(property, Long.toString(defaultValue)));
145-
}
146-
147-
/**
148-
* Helper method used to parse integer properties.
149-
*
150-
* @param property
151-
* The String key for the property
152-
* @param defaultValue
153-
* The default value for the integer property
154-
* @param properties
155-
* The properties file to get property from
156-
* @return property from property file, or if it is not specified, the default value
157-
*/
158-
private static int parseInt(String property, int defaultValue, Properties properties) {
159-
return Integer.parseInt(properties.getProperty(property, Integer.toString(defaultValue)));
160-
}
161-
}
131+
}

src/main/java/com/mcplusa/kinesis/KinesisConnectorExecutorBase.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public abstract class KinesisConnectorExecutorBase<T, U> implements Runnable {
3636
* @param kinesisConnectorConfiguration Amazon Kinesis connector configuration
3737
*/
3838
protected void initialize(KinesisConnectorConfiguration kinesisConnectorConfiguration) {
39-
initialize(kinesisConnectorConfiguration, null);
39+
initialize(kinesisConnectorConfiguration, new NullMetricsFactory());
4040
}
4141

4242
/**
@@ -77,8 +77,6 @@ protected void initialize(KinesisConnectorConfiguration kinesisConnectorConfigur
7777
if (kinesisConnectorConfiguration.IDLE_TIME_BETWEEN_READS > kinesisConnectorConfiguration.BUFFER_MILLISECONDS_LIMIT) {
7878
LOG.warn("idleTimeBetweenReads is greater than bufferTimeMillisecondsLimit. For best results, ensure that bufferTimeMillisecondsLimit is more than or equal to idleTimeBetweenReads ");
7979
}
80-
81-
metricFactory = new NullMetricsFactory(); // TODO move higher in the hierarchy
8280

8381
// If a metrics factory was specified, use it.
8482
if (metricFactory != null) {

src/main/java/com/mcplusa/sumologic/KinesisMessageModelSumologicTransformer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class KinesisMessageModelSumologicTransformer extends
1515
SumologicTransformer<KinesisMessageModel> {
1616

1717
/**
18-
* Creates a new KinesisMessageModelDynamoDBTransformer.
18+
* Creates a new KinesisMessageModelSumologicTransformer.
1919
*/
2020
public KinesisMessageModelSumologicTransformer() {
2121
super(KinesisMessageModel.class);

src/main/java/com/mcplusa/sumologic/SumologicExecutor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public SumologicExecutor(String configFile) {
2727

2828
/**
2929
* Main method starts and runs the SumologicExecutor.
30-
*
3130
* @param args
3231
*/
3332
public static void main(String[] args) {

src/main/java/com/mcplusa/sumologic/SumologicSender.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.apache.http.protocol.HTTP;
1515
import org.apache.http.util.EntityUtils;
1616
import org.apache.http.impl.client.DefaultHttpClient;
17-
1817
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
1918

2019
public class SumologicSender {
@@ -25,7 +24,9 @@ public class SumologicSender {
2524

2625
private int connectionTimeout = 1000;
2726
private int socketTimeout = 60000;
28-
27+
private static final int RETRIES = 3;
28+
private static final int SLEEP_TIME = 1000;
29+
2930

3031
public SumologicSender(String url) {
3132
this.url = url;
@@ -37,18 +38,31 @@ public SumologicSender(String url) {
3738
}
3839

3940
public boolean sendToSumologic(String data) throws IOException{
40-
HttpPost post = null;
41-
post = new HttpPost(url);
42-
post.setEntity(new StringEntity(data, HTTP.PLAIN_TEXT_TYPE, HTTP.UTF_8));
43-
HttpResponse response = httpClient.execute(post);
44-
int statusCode = response.getStatusLine().getStatusCode();
41+
int retries = RETRIES;
42+
int sleep_time = SLEEP_TIME;
43+
int statusCode;
44+
45+
do {
46+
HttpPost post = null;
47+
post = new HttpPost(url);
48+
post.setEntity(new StringEntity(data, HTTP.PLAIN_TEXT_TYPE, HTTP.UTF_8));
49+
HttpResponse response = httpClient.execute(post);
50+
statusCode = response.getStatusLine().getStatusCode();
51+
52+
//need to consume the body if you want to re-use the connection.
53+
EntityUtils.consume(response.getEntity());
54+
try {
55+
post.abort();
56+
} catch (Exception ignore) {}
57+
if (statusCode == 429) {
58+
LOG.warn("Got TOO MANY REQUESTS from Sumologic");
59+
retries--;
60+
try {
61+
Thread.sleep(sleep_time);
62+
} catch (InterruptedException ignore) {}
63+
}
64+
} while (statusCode == 429 && retries > 0);
4565

46-
//need to consume the body if you want to re-use the connection.
47-
EntityUtils.consume(response.getEntity());
48-
try {
49-
post.abort();
50-
} catch (Exception ignore) {}
51-
5266
// Check if the request was successful;
5367
if (statusCode != 200) {
5468
LOG.warn(String.format("Received HTTP error from Sumo Service: %d", statusCode));

0 commit comments

Comments
 (0)