mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Wire in MetricReporter into the backend servlet to publish metrics
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=130468842
This commit is contained in:
parent
4a34807b1d
commit
b45c2ca2ee
11 changed files with 214 additions and 25 deletions
|
@ -18,6 +18,10 @@ import com.google.common.base.Optional;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.util.concurrent.AbstractExecutionThreadService;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Background service to asynchronously push bundles of {@link MetricPoint} instances to a {@link
|
||||
|
@ -25,17 +29,24 @@ import java.util.concurrent.BlockingQueue;
|
|||
*/
|
||||
class MetricExporter extends AbstractExecutionThreadService {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(MetricReporter.class.getName());
|
||||
|
||||
private final BlockingQueue<Optional<ImmutableList<MetricPoint<?>>>> writeQueue;
|
||||
private final MetricWriter writer;
|
||||
private final ThreadFactory threadFactory;
|
||||
|
||||
MetricExporter(
|
||||
BlockingQueue<Optional<ImmutableList<MetricPoint<?>>>> writeQueue, MetricWriter writer) {
|
||||
BlockingQueue<Optional<ImmutableList<MetricPoint<?>>>> writeQueue,
|
||||
MetricWriter writer,
|
||||
ThreadFactory threadFactory) {
|
||||
this.writeQueue = writeQueue;
|
||||
this.writer = writer;
|
||||
this.threadFactory = threadFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run() throws Exception {
|
||||
logger.info("Started up MetricExporter");
|
||||
while (isRunning()) {
|
||||
Optional<ImmutableList<MetricPoint<?>>> batch = writeQueue.take();
|
||||
if (batch.isPresent()) {
|
||||
|
@ -44,9 +55,15 @@ class MetricExporter extends AbstractExecutionThreadService {
|
|||
}
|
||||
writer.flush();
|
||||
} else {
|
||||
logger.info("Received a poison pill, stopping now");
|
||||
// An absent optional indicates that the Reporter wants this service to shut down.
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Executor executor() {
|
||||
return Executors.newSingleThreadExecutor(threadFactory);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue