Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.

Commit e59bf8a

Browse files
committed
Fix PR #206
1 parent 9b9730a commit e59bf8a

3 files changed

Lines changed: 32 additions & 12 deletions

File tree

src/main/java/com/wavefront/sdk/Main.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.wavefront.sdk.common.Pair;
44
import com.wavefront.sdk.common.WavefrontSender;
5+
import com.wavefront.sdk.common.clients.WavefrontClient;
56
import com.wavefront.sdk.common.clients.WavefrontClientFactory;
67
import com.wavefront.sdk.direct.ingestion.WavefrontDirectIngestionClient;
78
import com.wavefront.sdk.entities.histograms.HistogramGranularity;
@@ -119,8 +120,11 @@ public static void main(String[] args) throws InterruptedException, IOException
119120
token + "@" + wavefrontServer.substring(wavefrontServer.indexOf("://")+3);
120121
System.out.println("wavefrontServerWithToken = " + wavefrontServerWithToken);
121122

123+
WavefrontClient.Builder wfClientBuilder = new WavefrontClient.Builder(wavefrontServer, token);
124+
WavefrontSender wavefrontSender = wfClientBuilder.build();
125+
122126
WavefrontClientFactory wavefrontClientFactory = new WavefrontClientFactory();
123-
wavefrontClientFactory.addClient(wavefrontServerWithToken);
127+
wavefrontClientFactory.addClient(wavefrontSender);
124128

125129
// DEPRECATED Client: Direct Data Ingestion
126130
// WavefrontDirectIngestionClient wavefrontDirectIngestionClient =

src/main/java/com/wavefront/sdk/common/clients/WavefrontClient.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public static class Builder {
146146
private int tracesPort = -1;
147147
private int maxQueueSize = 500000;
148148
private int batchSize = 10000;
149+
private long reportingServiceLogSuppressTimeSeconds = 300;
149150
private long flushInterval = 1;
150151
private TimeUnit flushIntervalTimeUnit = TimeUnit.SECONDS;
151152
private int messageSizeBytes = Integer.MAX_VALUE;
@@ -198,6 +199,17 @@ public Builder batchSize(int batchSize) {
198199
return this;
199200
}
200201

202+
/**
203+
* Set the reportingService log suppression time in seconds. The logs will be suppressed until this time elapses.
204+
*
205+
* @param reportingServiceLogSuppressTimeSeconds
206+
* @return {@code this}
207+
*/
208+
public Builder reportingServiceLogSuppressTimeSeconds(long reportingServiceLogSuppressTimeSeconds) {
209+
this.reportingServiceLogSuppressTimeSeconds = reportingServiceLogSuppressTimeSeconds;
210+
return this;
211+
}
212+
201213
/**
202214
* Set interval at which you want to flush points to Wavefront cluster.
203215
*
@@ -354,8 +366,8 @@ private WavefrontClient(Builder builder) {
354366
spanLogsBuffer = new LinkedBlockingQueue<>(builder.maxQueueSize);
355367
eventsBuffer = new LinkedBlockingQueue<>(builder.maxQueueSize);
356368
logsBuffer = new LinkedBlockingQueue<>(builder.maxQueueSize);
357-
metricsReportingService = new ReportingService(builder.metricsUri, builder.token);
358-
tracesReportingService = new ReportingService(builder.tracesUri, builder.token);
369+
metricsReportingService = new ReportingService(builder.metricsUri, builder.token, builder.reportingServiceLogSuppressTimeSeconds);
370+
tracesReportingService = new ReportingService(builder.tracesUri, builder.token, builder.reportingServiceLogSuppressTimeSeconds);
359371
scheduler = Executors.newScheduledThreadPool(1,
360372
new NamedThreadFactory("wavefrontClientSender").setDaemon(true));
361373
scheduler.scheduleAtFixedRate(this, 1, builder.flushInterval, builder.flushIntervalTimeUnit);

src/main/java/com/wavefront/sdk/common/clients/service/ReportingService.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
*/
2525
public class ReportingService implements ReportAPI {
2626

27-
private static final MessageSuppressingLogger MESSAGE_SUPPRESSING_LOGGER =
28-
new MessageSuppressingLogger(Logger.getLogger(ReportingService.class.getCanonicalName()),
29-
5, TimeUnit.MINUTES);
30-
27+
// This logger is intended to be configurable in the WavefrontClient.Builder. Given that the invoker controls the
28+
// configuration, this is not a static logger.
29+
private final MessageSuppressingLogger messageSuppressingLogger;
3130
private final String token;
3231
private final URI uri;
3332

@@ -36,9 +35,14 @@ public class ReportingService implements ReportAPI {
3635
private static final int BUFFER_SIZE = 4096;
3736
private static final int NO_HTTP_RESPONSE = -1;
3837

39-
public ReportingService(URI uri, @Nullable String token) {
38+
public ReportingService(URI uri, @Nullable String token, long reportingServiceLogSuppressTimeSeconds) {
4039
this.uri = uri;
4140
this.token = token;
41+
// Setting suppress time to 0 invalidates the cache used by the message suppressing logger and doesn't log anything.
42+
// So defaulting to the minimum of 1 second.
43+
reportingServiceLogSuppressTimeSeconds = reportingServiceLogSuppressTimeSeconds <= 0 ? 1 : reportingServiceLogSuppressTimeSeconds;
44+
this.messageSuppressingLogger = new MessageSuppressingLogger(Logger.getLogger(
45+
ReportingService.class.getCanonicalName()), reportingServiceLogSuppressTimeSeconds, TimeUnit.SECONDS);
4246
}
4347

4448
@Override
@@ -67,7 +71,7 @@ public int send(String format, InputStream stream) {
6771
}
6872
statusCode = urlConn.getResponseCode();
6973
readAndClose(urlConn.getInputStream());
70-
MESSAGE_SUPPRESSING_LOGGER.reset(urlConn.getURL().toString());
74+
messageSuppressingLogger.reset(urlConn.getURL().toString());
7175
} catch (IOException ex) {
7276
if (urlConn != null) {
7377
return safeGetResponseCodeAndClose(urlConn);
@@ -117,7 +121,7 @@ public int sendEvent(InputStream stream) {
117121

118122
statusCode = urlConn.getResponseCode();
119123
readAndClose(urlConn.getInputStream());
120-
MESSAGE_SUPPRESSING_LOGGER.reset(urlConn.getURL().toString());
124+
messageSuppressingLogger.reset(urlConn.getURL().toString());
121125
} catch (IOException ex) {
122126
if (urlConn != null) {
123127
return safeGetResponseCodeAndClose(urlConn);
@@ -131,7 +135,7 @@ private int safeGetResponseCodeAndClose(HttpURLConnection urlConn) {
131135
try {
132136
statusCode = urlConn.getResponseCode();
133137
} catch (IOException ex) {
134-
MESSAGE_SUPPRESSING_LOGGER.log(urlConn.getURL().toString(), Level.SEVERE,
138+
messageSuppressingLogger.log(urlConn.getURL().toString(), Level.SEVERE,
135139
"Unable to obtain status code from the Wavefront service at "
136140
+ urlConn.getURL().toString() + " due to: " + ex);
137141
statusCode = NO_HTTP_RESPONSE;
@@ -140,7 +144,7 @@ private int safeGetResponseCodeAndClose(HttpURLConnection urlConn) {
140144
try {
141145
readAndClose(urlConn.getErrorStream());
142146
} catch (IOException ex) {
143-
MESSAGE_SUPPRESSING_LOGGER.log(urlConn.getURL().toString(), Level.SEVERE,
147+
messageSuppressingLogger.log(urlConn.getURL().toString(), Level.SEVERE,
144148
"Unable to read and close error stream from the Wavefront service at "
145149
+ urlConn.getURL().toString() + " due to: " + ex);
146150
}

0 commit comments

Comments
 (0)