Make StackdriverWriter#flush() return early when attempting to flush empty

timeseries

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=132359115
This commit is contained in:
shikhman 2016-09-06 14:01:43 -07:00 committed by Ben McIlwain
parent 0e8d9e3859
commit e5a0392994

View file

@ -193,6 +193,12 @@ public class StackdriverWriter implements MetricWriter {
public void flush() throws IOException { public void flush() throws IOException {
checkState(timeSeriesBuffer.size() <= 200, FLUSH_OVERFLOW_ERROR); checkState(timeSeriesBuffer.size() <= 200, FLUSH_OVERFLOW_ERROR);
// Return early; Stackdriver throws errors if we attempt to send empty requests.
if (timeSeriesBuffer.isEmpty()) {
logger.fine("Attempted to flush with no pending points, doing nothing");
return;
}
ImmutableList<TimeSeries> timeSeriesList = ImmutableList.copyOf(timeSeriesBuffer); ImmutableList<TimeSeries> timeSeriesList = ImmutableList.copyOf(timeSeriesBuffer);
timeSeriesBuffer.clear(); timeSeriesBuffer.clear();