Skip to content

Commit

Permalink
Handle exceptions at sampling runnable level.
Browse files Browse the repository at this point in the history
Closes #92.

Signed-off-by: Łukasz Dywicki <[email protected]>
  • Loading branch information
splatch committed Aug 25, 2024
1 parent 1941bd2 commit 6999c4f
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,26 @@ static class SamplerRunnable implements Runnable {
private final Logger logger = LoggerFactory.getLogger(SamplerRunnable.class);

private final Sampler sampler;
private int failureCount = 0;

SamplerRunnable(Sampler sampler) {
this.sampler = sampler;
}

@Override
public void run() {
logger.trace("Executing operation {}", sampler);
sampler.fetch();
try {
logger.trace("Executing operation {}", sampler);
sampler.fetch();
} catch (Exception e) {
if (failureCount++ == 0) {
logger.warn("Failed to collect sample", e);
} else if (failureCount < 1000 && failureCount % 100 == 0) {
logger.warn("Failed to collect sample. This is {} failure of this task", failureCount, e);
} else if (failureCount >= 1000 && failureCount % 1000 == 0) {
logger.warn("Failed to collect sample. This is {} failure of this task, possible permanent communication error", failureCount, e);
}
}
}
}
}

0 comments on commit 6999c4f

Please sign in to comment.