Search in sources :

Example 1 with StreamKpiData

use of org.zalando.nakadi.metrics.StreamKpiData in project nakadi by zalando.

the class StreamingState method onEnter.

@Override
public void onEnter() {
    final String kafkaFlushedBytesMetricName = MetricUtils.metricNameForHiLAStream(this.getContext().getParameters().getConsumingClient().getClientId(), this.getContext().getSubscription().getId());
    bytesSentMeterPerSubscription = this.getContext().getMetricRegistry().meter(kafkaFlushedBytesMetricName);
    lastKpiEventSent = System.currentTimeMillis();
    kpiDataPerEventType = this.getContext().getSubscription().getEventTypes().stream().collect(Collectors.toMap(et -> et, et -> new StreamKpiData()));
    idleStreamWatcher = new IdleStreamWatcher(getParameters().commitTimeoutMillis * 2);
    this.eventConsumer = getContext().getTimelineService().createEventConsumer(null);
    recreateTopologySubscription();
    addTask(this::recheckTopology);
    addTask(this::pollDataFromKafka);
    scheduleTask(this::checkBatchTimeouts, getParameters().batchTimeoutMillis, TimeUnit.MILLISECONDS);
    scheduleTask(() -> {
        final String debugMessage = "Stream timeout reached";
        this.sendMetadata(debugMessage);
        this.shutdownGracefully(debugMessage);
    }, getParameters().streamTimeoutMillis, TimeUnit.MILLISECONDS);
    this.lastCommitMillis = System.currentTimeMillis();
    scheduleTask(this::checkCommitTimeout, getParameters().commitTimeoutMillis, TimeUnit.MILLISECONDS);
    cursorResetSubscription = getZk().subscribeForCursorsReset(() -> addTask(this::resetSubscriptionCursorsCallback));
}
Also used : IdleStreamWatcher(org.zalando.nakadi.service.subscription.IdleStreamWatcher) StreamKpiData(org.zalando.nakadi.metrics.StreamKpiData)

Example 2 with StreamKpiData

use of org.zalando.nakadi.metrics.StreamKpiData in project nakadi by zalando.

the class StreamingState method flushData.

private void flushData(final EventTypePartition pk, final List<ConsumedEvent> data, final Optional<String> metadata) {
    try {
        final NakadiCursor sentOffset = offsets.get(pk).getSentOffset();
        final SubscriptionCursor cursor = getContext().getCursorConverter().convert(sentOffset, getContext().getCursorTokenService().generateToken());
        final int batchSize = getContext().getWriter().writeSubscriptionBatch(getOut().getOutputStream(), cursor, data, metadata);
        bytesSentMeterPerSubscription.mark(batchSize);
        final StreamKpiData kpiData = kpiDataPerEventType.get(pk.getEventType());
        kpiData.addBytesSent(batchSize);
        kpiData.addNumberOfEventsSent(data.size());
        batchesSent++;
    } catch (final IOException e) {
        getLog().error("Failed to write data to output.", e);
        shutdownGracefully("Failed to write data to output");
    }
}
Also used : SubscriptionCursor(org.zalando.nakadi.view.SubscriptionCursor) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) IOException(java.io.IOException) StreamKpiData(org.zalando.nakadi.metrics.StreamKpiData)

Aggregations

StreamKpiData (org.zalando.nakadi.metrics.StreamKpiData)2 IOException (java.io.IOException)1 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)1 IdleStreamWatcher (org.zalando.nakadi.service.subscription.IdleStreamWatcher)1 SubscriptionCursor (org.zalando.nakadi.view.SubscriptionCursor)1