use of io.mantisrx.common.metrics.Metrics in project mantis by Netflix.
the class SchedulingService method setupSchedulingServiceWatcherMetric.
private void setupSchedulingServiceWatcherMetric() {
logger.info("Setting up SchedulingServiceWatcher metrics");
lastSchedulingResultCallback.set(System.currentTimeMillis());
final String metricGroup = "SchedulingServiceWatcher";
final GaugeCallback timeSinceLastSchedulingRunGauge = new GaugeCallback(new MetricId(metricGroup, "timeSinceLastSchedulingRunMs"), () -> (double) (System.currentTimeMillis() - lastSchedulingResultCallback.get()), SpectatorRegistryFactory.getRegistry());
final Metrics schedulingServiceWatcherMetrics = new Metrics.Builder().id(metricGroup).addGauge(timeSinceLastSchedulingRunGauge).build();
MetricsRegistry.getInstance().registerAndGet(schedulingServiceWatcherMetrics);
}
use of io.mantisrx.common.metrics.Metrics in project mantis by Netflix.
the class SseWorkerConnectionTest method testStreamContentDrops.
@Test
public void testStreamContentDrops() throws Exception {
SpectatorRegistryFactory.setRegistry(new DefaultRegistry());
String metricGroupString = "testmetric";
MetricGroupId metricGroupId = new MetricGroupId(metricGroupString);
SseWorkerConnection workerConnection = new SseWorkerConnection("connection_type", "hostname", 80, b -> {
}, b -> {
}, t -> {
}, 600, false, new CopyOnWriteArraySet<>(), 1, null, true, metricGroupId);
HttpClientResponse<ServerSentEvent> response = mock(HttpClientResponse.class);
TestScheduler testScheduler = Schedulers.test();
// Events are just "0", "1", "2", ...
Observable<ServerSentEvent> contentObs = Observable.interval(1, TimeUnit.SECONDS, testScheduler).map(t -> new ServerSentEvent(Unpooled.copiedBuffer(Long.toString(t), Charset.defaultCharset())));
when(response.getContent()).thenReturn(contentObs);
TestSubscriber<MantisServerSentEvent> subscriber = new TestSubscriber<>(1);
workerConnection.streamContent(response, b -> {
}, 600, "delimiter").subscribeOn(testScheduler).subscribe(subscriber);
testScheduler.advanceTimeBy(100, TimeUnit.SECONDS);
subscriber.assertValueCount(1);
List<MantisServerSentEvent> events = subscriber.getOnNextEvents();
assertEquals("0", events.get(0).getEventAsString());
Metrics metrics = MetricsRegistry.getInstance().getMetric(metricGroupId);
Counter onNextCounter = metrics.getCounter(DropOperator.Counters.onNext.toString());
Counter droppedCounter = metrics.getCounter(DropOperator.Counters.dropped.toString());
logger.info("next: {}", onNextCounter.value());
logger.info("drop: {}", droppedCounter.value());
assertTrue(onNextCounter.value() < 10);
assertTrue(droppedCounter.value() > 90);
}
use of io.mantisrx.common.metrics.Metrics in project mantis by Netflix.
the class ObservableTrigger method groupTrigger.
private static <K, V> PushTrigger<KeyValuePair<K, V>> groupTrigger(final String name, final Observable<GroupedObservable<K, V>> o, final Action0 doOnComplete, final Action1<Throwable> doOnError, final long groupExpirySeconds, final Func1<K, byte[]> keyEncoder, final HashFunction hashFunction) {
final AtomicReference<Subscription> subRef = new AtomicReference<>();
final Gauge subscriptionActive;
Metrics metrics = new Metrics.Builder().name("ObservableTrigger_" + name).addGauge("subscriptionActive").build();
subscriptionActive = metrics.getGauge("subscriptionActive");
Action1<MonitoredQueue<KeyValuePair<K, V>>> doOnStart = new Action1<MonitoredQueue<KeyValuePair<K, V>>>() {
@Override
public void call(final MonitoredQueue<KeyValuePair<K, V>> queue) {
subRef.set(o.observeOn(Schedulers.computation()).doOnSubscribe(() -> {
logger.info("Subscription is ACTIVE for observable trigger with name: " + name);
subscriptionActive.set(1);
}).doOnUnsubscribe(() -> {
logger.info("Subscription is INACTIVE for observable trigger with name: " + name);
subscriptionActive.set(0);
}).flatMap((final GroupedObservable<K, V> group) -> {
final byte[] keyBytes = keyEncoder.call(group.getKey());
final long keyBytesHashed = hashFunction.computeHash(keyBytes);
return group.timeout(groupExpirySeconds, TimeUnit.SECONDS, (Observable<? extends V>) Observable.empty()).lift(new DisableBackPressureOperator<V>()).buffer(250, TimeUnit.MILLISECONDS).filter((List<V> t1) -> t1 != null && !t1.isEmpty()).map((List<V> list) -> {
List<KeyValuePair<K, V>> keyPairList = new ArrayList<>(list.size());
for (V data : list) {
keyPairList.add(new KeyValuePair<K, V>(keyBytesHashed, keyBytes, data));
}
return keyPairList;
});
}).subscribe((List<KeyValuePair<K, V>> list) -> {
for (KeyValuePair<K, V> data : list) {
queue.write(data);
}
}, (Throwable e) -> {
logger.warn("Observable used to push data errored, on server with name: " + name, e);
if (doOnError != null) {
doOnError.call(e);
}
}, () -> {
logger.info("Observable used to push data completed, on server with name: " + name);
if (doOnComplete != null) {
doOnComplete.call();
}
}));
}
};
Action1<MonitoredQueue<KeyValuePair<K, V>>> doOnStop = new Action1<MonitoredQueue<KeyValuePair<K, V>>>() {
@Override
public void call(MonitoredQueue<KeyValuePair<K, V>> t1) {
if (subRef.get() != null) {
logger.warn("Connections from next stage has dropped to 0. Do not propagate unsubscribe");
// subRef.get().unsubscribe();
}
}
};
return new PushTrigger<>(doOnStart, doOnStop, metrics);
}
use of io.mantisrx.common.metrics.Metrics in project mantis by Netflix.
the class ObservableTrigger method ssetrigger.
private static <T> PushTrigger<T> ssetrigger(final String name, final Observable<T> o, final Action0 doOnComplete, final Action1<Throwable> doOnError) {
final AtomicReference<Subscription> subRef = new AtomicReference<>();
final Gauge subscriptionActive;
Metrics metrics = new Metrics.Builder().name("ObservableTrigger_" + name).addGauge("subscriptionActive").build();
subscriptionActive = metrics.getGauge("subscriptionActive");
Action1<MonitoredQueue<T>> doOnStart = new Action1<MonitoredQueue<T>>() {
@Override
public void call(final MonitoredQueue<T> queue) {
subRef.set(o.filter((T t1) -> t1 != null).doOnSubscribe(() -> {
logger.info("Subscription is ACTIVE for observable trigger with name: " + name);
subscriptionActive.set(1);
}).doOnUnsubscribe(() -> {
logger.info("Subscription is INACTIVE for observable trigger with name: " + name);
subscriptionActive.set(0);
}).subscribe((T data) -> queue.write(data), (Throwable e) -> {
logger.warn("Observable used to push data errored, on server with name: " + name, e);
if (doOnError != null) {
doOnError.call(e);
}
}, () -> {
logger.info("Observable used to push data completed, on server with name: " + name);
if (doOnComplete != null) {
doOnComplete.call();
}
}));
}
};
Action1<MonitoredQueue<T>> doOnStop = new Action1<MonitoredQueue<T>>() {
@Override
public void call(MonitoredQueue<T> t1) {
if (subRef.get() != null) {
logger.warn("Connections from next stage has dropped to 0 for SSE stage. propagate unsubscribe");
subRef.get().unsubscribe();
}
}
};
return new PushTrigger<>(doOnStart, doOnStop, metrics);
}
use of io.mantisrx.common.metrics.Metrics in project mantis by Netflix.
the class ObservableTrigger method trigger.
private static <T> PushTrigger<T> trigger(final String name, final Observable<T> o, final Action0 doOnComplete, final Action1<Throwable> doOnError) {
final AtomicReference<Subscription> subRef = new AtomicReference<>();
final Gauge subscriptionActive;
Metrics metrics = new Metrics.Builder().name("ObservableTrigger_" + name).addGauge("subscriptionActive").build();
subscriptionActive = metrics.getGauge("subscriptionActive");
Action1<MonitoredQueue<T>> doOnStart = new Action1<MonitoredQueue<T>>() {
@Override
public void call(final MonitoredQueue<T> queue) {
subRef.set(o.filter((T t1) -> t1 != null).doOnSubscribe(() -> {
logger.info("Subscription is ACTIVE for observable trigger with name: " + name);
subscriptionActive.set(1);
}).doOnUnsubscribe(() -> {
logger.info("Subscription is INACTIVE for observable trigger with name: " + name);
subscriptionActive.set(0);
}).subscribe((T data) -> queue.write(data), (Throwable e) -> {
logger.warn("Observable used to push data errored, on server with name: " + name, e);
if (doOnError != null) {
doOnError.call(e);
}
}, () -> {
logger.info("Observable used to push data completed, on server with name: " + name);
if (doOnComplete != null) {
doOnComplete.call();
}
}));
}
};
Action1<MonitoredQueue<T>> doOnStop = new Action1<MonitoredQueue<T>>() {
@Override
public void call(MonitoredQueue<T> t1) {
if (subRef.get() != null) {
logger.warn("Connections from next stage has dropped to 0. Do not propagate unsubscribe");
// subRef.get().unsubscribe();
}
}
};
return new PushTrigger<>(doOnStart, doOnStop, metrics);
}
Aggregations