private void accountSuccessfulSending(long sendingStartMs) { successfulSendingTimeCounter.add((int) Math.max(System.currentTimeMillis() - sendingStartMs, 0)); }
private void emitTimeCounterMetrics(ServiceEmitter emitter, ConcurrentTimeCounter timeCounter, String metricNameBase) { long timeSumAndCount = timeCounter.getTimeSumAndCountAndReset(); int timeSum = ConcurrentTimeCounter.timeSum(timeSumAndCount); int count = ConcurrentTimeCounter.count(timeSumAndCount); if (count != 0) { emitter.emit(builder.build(metricNameBase + "timeMsSum", timeSum)); emitter.emit(builder.build(metricNameBase + "count", count)); } Integer maxTime = timeCounter.getAndResetMaxTime(); if (maxTime != null) { emitter.emit(builder.build(metricNameBase + "maxTimeMs", maxTime)); } Integer minTime = timeCounter.getAndResetMinTime(); if (minTime != null) { emitter.emit(builder.build(metricNameBase + "minTimeMs", minTime)); } }
emitter = manualFlushEmitterWithBatchSize(1024 * 1024); Assert.assertEquals(0, emitter.getTotalEmittedEvents()); Assert.assertEquals(0, emitter.getSuccessfulSendingTimeCounter().getTimeSumAndCount()); Assert.assertEquals(0, emitter.getFailedSendingTimeCounter().getTimeSumAndCount()); Assert.assertTrue(emitter.getSuccessfulSendingTimeCounter().getTimeSumAndCount() > 0); Assert.assertEquals(0, emitter.getFailedSendingTimeCounter().getTimeSumAndCount()); Assert.assertTrue(emitter.getSuccessfulSendingTimeCounter().getTimeSumAndCount() > 0); Assert.assertEquals(0, emitter.getFailedSendingTimeCounter().getTimeSumAndCount()); closeNoFlush(emitter); Assert.assertTrue(httpClient.succeeded());
emitter = sizeBasedEmitter(1); Assert.assertEquals(0, emitter.getTotalEmittedEvents()); Assert.assertEquals(0, emitter.getSuccessfulSendingTimeCounter().getTimeSumAndCount()); Assert.assertEquals(0, emitter.getFailedSendingTimeCounter().getTimeSumAndCount()); Assert.assertEquals(0, emitter.getSuccessfulSendingTimeCounter().getTimeSumAndCount()); Assert.assertTrue(emitter.getFailedSendingTimeCounter().getTimeSumAndCount() > 0); Assert.assertTrue(emitter.getSuccessfulSendingTimeCounter().getTimeSumAndCount() > 0); Assert.assertTrue(emitter.getFailedSendingTimeCounter().getTimeSumAndCount() > 0);
private void emitTimeCounterMetrics(ServiceEmitter emitter, ConcurrentTimeCounter timeCounter, String metricNameBase) { long timeSumAndCount = timeCounter.getTimeSumAndCountAndReset(); int timeSum = ConcurrentTimeCounter.timeSum(timeSumAndCount); int count = ConcurrentTimeCounter.count(timeSumAndCount); if (count != 0) { emitter.emit(builder.build(metricNameBase + "timeMsSum", timeSum)); emitter.emit(builder.build(metricNameBase + "count", count)); } Integer maxTime = timeCounter.getAndResetMaxTime(); if (maxTime != null) { emitter.emit(builder.build(metricNameBase + "maxTimeMs", maxTime)); } Integer minTime = timeCounter.getAndResetMinTime(); if (minTime != null) { emitter.emit(builder.build(metricNameBase + "minTimeMs", minTime)); } }
private void accountFailedSending(long sendingStartMs) { failedSendingTimeCounter.add((int) Math.max(System.currentTimeMillis() - sendingStartMs, 0)); }
private void doOnSealExclusive(Batch batch, long elapsedTimeMillis) { batchFillingTimeCounter.add((int) Math.max(elapsedTimeMillis, 0)); if (elapsedTimeMillis > 0) { // If elapsedTimeMillis is 0 or negative, it's likely because System.currentTimeMillis() is not monotonic, so not // accounting this time for determining batch sending timeout. lastBatchFillTimeMillis = elapsedTimeMillis; } addBatchToEmitQueue(batch); wakeUpEmittingThread(); if (!isTerminated()) { long nextBatchNumber = ConcurrentAwaitableCounter.nextCount(batch.batchNumber); byte[] newBuffer = acquireBuffer(); if (!concurrentBatch.compareAndSet(batch, new Batch(this, newBuffer, nextBatchNumber))) { buffersToReuse.add(newBuffer); // If compareAndSet failed, the service should be closed concurrently, i. e. we expect isTerminated() = true. // If we don't see this, there should be some bug in HttpPostEmitter. Preconditions.checkState(isTerminated()); } } }
private void accountFailedSending(long sendingStartMs) { failedSendingTimeCounter.add((int) Math.max(System.currentTimeMillis() - sendingStartMs, 0)); }
private void accountSuccessfulSending(long sendingStartMs) { successfulSendingTimeCounter.add((int) Math.max(System.currentTimeMillis() - sendingStartMs, 0)); }
private void doOnSealExclusive(Batch batch, long elapsedTimeMillis) { batchFillingTimeCounter.add((int) Math.max(elapsedTimeMillis, 0)); if (elapsedTimeMillis > 0) { // If elapsedTimeMillis is 0 or negative, it's likely because System.currentTimeMillis() is not monotonic, so not // accounting this time for determining batch sending timeout. lastFillTimeMillis = elapsedTimeMillis; } addBatchToEmitQueue(batch); wakeUpEmittingThread(); if (!isTerminated()) { long nextBatchNumber = ConcurrentAwaitableCounter.nextCount(batch.batchNumber); byte[] newBuffer = acquireBuffer(); if (!concurrentBatch.compareAndSet(batch, new Batch(this, newBuffer, nextBatchNumber))) { buffersToReuse.add(newBuffer); // If compareAndSet failed, the service should be closed concurrently, i. e. we expect isTerminated() = true. // If we don't see this, there should be some bug in HttpPostEmitter. Preconditions.checkState(isTerminated()); } } }