Skip to content

Commit

Permalink
[#3219] Remove gauges when collecting transaction counts
Browse files Browse the repository at this point in the history
  • Loading branch information
Xylus authored and koo-taejin committed Aug 11, 2017
1 parent cb0ddae commit 4beaecc
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 107 deletions.
Expand Up @@ -18,6 +18,7 @@

import com.google.inject.Inject;
import com.navercorp.pinpoint.profiler.monitor.metric.transaction.TransactionMetric;
import com.navercorp.pinpoint.profiler.monitor.metric.transaction.TransactionMetricSnapshot;
import com.navercorp.pinpoint.thrift.dto.TTransaction;

/**
Expand All @@ -35,10 +36,11 @@ public DefaultTransactionMetricCollector(TransactionMetric transactionMetric) {
@Override
public TTransaction collect() {
TTransaction transaction = new TTransaction();
transaction.setSampledNewCount(transactionMetric.sampledNew());
transaction.setSampledContinuationCount(transactionMetric.sampledContinuation());
transaction.setUnsampledNewCount(transactionMetric.unsampledNew());
transaction.setUnsampledContinuationCount(transactionMetric.unsampledContinuation());
TransactionMetricSnapshot transactionMetricSnapshot = transactionMetric.getSnapshot();
transaction.setSampledNewCount(transactionMetricSnapshot.getSampledNewCount());
transaction.setSampledContinuationCount(transactionMetricSnapshot.getSampledContinuationCount());
transaction.setUnsampledNewCount(transactionMetricSnapshot.getUnsampledNewCount());
transaction.setUnsampledContinuationCount(transactionMetricSnapshot.getUnsampledContinuationCount());
return transaction;
}

Expand Down
Expand Up @@ -16,100 +16,87 @@

package com.navercorp.pinpoint.profiler.monitor.metric.transaction;

import com.codahale.metrics.Gauge;
import com.navercorp.pinpoint.profiler.context.id.TransactionCounter;

/**
* @author HyunGil Jeong
*/
public class DefaultTransactionMetric implements TransactionMetric {

private final Gauge<Long> sampledNewGauge;
private final Gauge<Long> sampledContinuationGauge;
private final Gauge<Long> unsampledNewGauge;
private final Gauge<Long> unsampledContinuationGauge;
private final TransactionGauge sampledNewGauge;
private final TransactionGauge sampledContinuationGauge;
private final TransactionGauge unsampledNewGauge;
private final TransactionGauge unsampledContinuationGauge;

public DefaultTransactionMetric(final TransactionCounter transactionCounter) {
if (transactionCounter == null) {
throw new NullPointerException("transactionCounter must not be null");
}
sampledNewGauge = TransactionGauge.wrap(new LongGauge() {
sampledNewGauge = TransactionGauge.from(new LongCounter() {
@Override
public long getValue() {
public long getCount() {
return transactionCounter.getSampledNewCount();
}
});
sampledContinuationGauge = TransactionGauge.wrap(new LongGauge() {
sampledContinuationGauge = TransactionGauge.from(new LongCounter() {
@Override
public long getValue() {
public long getCount() {
return transactionCounter.getSampledContinuationCount();
}
});
unsampledNewGauge = TransactionGauge.wrap(new LongGauge() {
unsampledNewGauge = TransactionGauge.from(new LongCounter() {
@Override
public long getValue() {
public long getCount() {
return transactionCounter.getUnSampledNewCount();
}
});
unsampledContinuationGauge = TransactionGauge.wrap(new LongGauge() {
unsampledContinuationGauge = TransactionGauge.from(new LongCounter() {
@Override
public long getValue() {
public long getCount() {
return transactionCounter.getUnSampledContinuationCount();
}
});
}

@Override
public Long sampledNew() {
return sampledNewGauge.getValue();
}

@Override
public Long sampledContinuation() {
return sampledContinuationGauge.getValue();
}

@Override
public Long unsampledNew() {
return unsampledNewGauge.getValue();
}

@Override
public Long unsampledContinuation() {
return unsampledContinuationGauge.getValue();
public TransactionMetricSnapshot getSnapshot() {
long sampledNewCount = sampledNewGauge.getTransactionCount();
long sampledContinuationCount = sampledContinuationGauge.getTransactionCount();
long unsampledNewCount = unsampledNewGauge.getTransactionCount();
long unsampledContinuationCount = unsampledContinuationGauge.getTransactionCount();
return new TransactionMetricSnapshot(sampledNewCount, sampledContinuationCount, unsampledNewCount, unsampledContinuationCount);
}

@Override
public String toString() {
return "Default TransactionMetric";
}

private interface LongGauge {
long getValue();
private interface LongCounter {
long getCount();
}

private static class TransactionGauge implements Gauge<Long> {
private static class TransactionGauge {
private static final long UNINITIALIZED = -1L;

private long prevTransactionCount = UNINITIALIZED;
private final LongGauge longGauge;
private final LongCounter longCounter;

static TransactionGauge wrap(LongGauge longGauge) {
return new TransactionGauge(longGauge);
static TransactionGauge from(LongCounter longCounter) {
return new TransactionGauge(longCounter);
}

private TransactionGauge(LongGauge longGauge) {
if (longGauge == null) {
private TransactionGauge(LongCounter longCounter) {
if (longCounter == null) {
throw new NullPointerException("longGauge must not be null");
}
this.longGauge = longGauge;
this.longCounter = longCounter;
}

@Override
public final Long getValue() {
final long transactionCount = longGauge.getValue();
private final long getTransactionCount() {
final long transactionCount = longCounter.getCount();
if (transactionCount < 0) {
return 0L;
return UNCOLLECTED;
}
if (this.prevTransactionCount == UNINITIALIZED) {
this.prevTransactionCount = transactionCount;
Expand All @@ -119,6 +106,5 @@ public final Long getValue() {
this.prevTransactionCount = transactionCount;
return transactionCountDelta;
}

}
}
Expand Up @@ -16,31 +16,20 @@

package com.navercorp.pinpoint.profiler.monitor.metric.transaction;


/**
* @author HyunGil Jeong
*/
public interface TransactionMetric {

TransactionMetric UNSUPPORTED_TRANSACTION_METRIC = new TransactionMetric() {
@Override
public Long sampledNew() {
return null;
}
long UNCOLLECTED = -1L;

@Override
public Long sampledContinuation() {
return null;
}
TransactionMetric UNSUPPORTED_TRANSACTION_METRIC = new TransactionMetric() {

@Override
public Long unsampledNew() {
return null;
}
private final TransactionMetricSnapshot uncollectedSnaphot = new TransactionMetricSnapshot(UNCOLLECTED, UNCOLLECTED, UNCOLLECTED, UNCOLLECTED);

@Override
public Long unsampledContinuation() {
return null;
public TransactionMetricSnapshot getSnapshot() {
return uncollectedSnaphot;
}

@Override
Expand All @@ -49,11 +38,5 @@ public String toString() {
}
};

Long sampledNew();

Long sampledContinuation();

Long unsampledNew();

Long unsampledContinuation();
TransactionMetricSnapshot getSnapshot();
}
@@ -0,0 +1,54 @@
/*
* Copyright 2017 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.pinpoint.profiler.monitor.metric.transaction;

/**
* @author HyunGil Jeong
*/
public class TransactionMetricSnapshot {

private final long sampledNewCount;
private final long sampledContinuationCount;
private final long unsampledNewCount;
private final long unsampledContinuationCount;

public TransactionMetricSnapshot(long sampledNewCount,
long sampledContinuationCount,
long unsampledNewCount,
long unsampledContinuationCount) {
this.sampledNewCount = sampledNewCount;
this.sampledContinuationCount = sampledContinuationCount;
this.unsampledNewCount = unsampledNewCount;
this.unsampledContinuationCount = unsampledContinuationCount;
}

public long getSampledNewCount() {
return sampledNewCount;
}

public long getSampledContinuationCount() {
return sampledContinuationCount;
}

public long getUnsampledNewCount() {
return unsampledNewCount;
}

public long getUnsampledContinuationCount() {
return unsampledContinuationCount;
}
}

0 comments on commit 4beaecc

Please sign in to comment.