Skip to content

Commit 4e2c9d9

Browse files
committed
Implementing IOStatisticsSource in DelegationTokenSecretStorageMetrics
1 parent 373b7db commit 4e2c9d9

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/AbstractDelegationTokenSecretManager.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636

3737
import org.apache.hadoop.classification.InterfaceAudience;
3838
import org.apache.hadoop.classification.InterfaceStability;
39+
import org.apache.hadoop.fs.statistics.IOStatistics;
40+
import org.apache.hadoop.fs.statistics.IOStatisticsSource;
41+
import org.apache.hadoop.fs.statistics.impl.IOStatisticsStore;
3942
import org.apache.hadoop.io.Text;
4043
import org.apache.hadoop.metrics2.annotation.Metric;
4144
import org.apache.hadoop.metrics2.annotation.Metrics;
@@ -55,6 +58,9 @@
5558
import org.slf4j.Logger;
5659
import org.slf4j.LoggerFactory;
5760

61+
import static org.apache.hadoop.fs.statistics.impl.IOStatisticsBinding.*;
62+
63+
5864
@InterfaceAudience.Public
5965
@InterfaceStability.Evolving
6066
public abstract
@@ -854,14 +860,19 @@ protected void syncTokenOwnerStats() {
854860
addTokenForOwnerStats(id);
855861
}
856862
}
857-
863+
858864
/**
859865
* DelegationTokenSecretManagerMetrics tracks token management operations
860866
* and publishes them through the metrics interfaces.
861867
*/
862868
@Metrics(about="Delegation token secret manager metrics", context="token")
863-
static class DelegationTokenSecretManagerMetrics {
869+
static class DelegationTokenSecretManagerMetrics implements IOStatisticsSource {
870+
final static String STORE_TOKEN_STAT = "storeToken";
871+
final static String UPDATE_TOKEN_STAT = "updateToken";
872+
final static String REMOVE_TOKEN_STAT = "removeToken";
873+
864874
final MetricsRegistry registry = new MetricsRegistry("DelegationTokenSecretManagerMetrics");
875+
final IOStatisticsStore ioStatistics;
865876

866877
@Metric("Rate of storage of delegation tokens and latency (milliseconds)")
867878
MutableRate storeToken;
@@ -873,5 +884,31 @@ static class DelegationTokenSecretManagerMetrics {
873884
static DelegationTokenSecretManagerMetrics create() {
874885
return DefaultMetricsSystem.instance().register(new DelegationTokenSecretManagerMetrics());
875886
}
887+
888+
public DelegationTokenSecretManagerMetrics() {
889+
ioStatistics = iostatisticsStore()
890+
.withDurationTracking(STORE_TOKEN_STAT, UPDATE_TOKEN_STAT, REMOVE_TOKEN_STAT)
891+
.build();
892+
}
893+
894+
public void addStoreToken(long value) {
895+
storeToken.add(value);
896+
ioStatistics.addTimedOperation(STORE_TOKEN_STAT, value);
897+
}
898+
899+
public void addUpdateToken(long value) {
900+
updateToken.add(value);
901+
ioStatistics.addTimedOperation(UPDATE_TOKEN_STAT, value);
902+
}
903+
904+
public void addRemoveToken(long value) {
905+
removeToken.add(value);
906+
ioStatistics.addTimedOperation(REMOVE_TOKEN_STAT, value);
907+
}
908+
909+
@Override
910+
public IOStatistics getIOStatistics() {
911+
return ioStatistics;
912+
}
876913
}
877914
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestDelegationToken.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ public void testDelegationTokenSecretManagerMetrics() throws Exception {
587587
10*1000,1*1000,3600000);
588588
try {
589589
dtSecretManager.startThreads();
590-
590+
591591
Assert.assertEquals(0, dtSecretManager.metrics.storeToken.lastStat().numSamples());
592592
final Token<TestDelegationTokenIdentifier> token =
593593
generateDelegationToken(dtSecretManager, "SomeUser", "JobTracker");

0 commit comments

Comments
 (0)