Skip to content

Commit 93d0083

Browse files
committed
fix(test): define constant for repeated string literal and add NOSONAR
- Replace duplicated miner string literal with MINER_LABEL constant in PrometheusApiServiceTest to fix SonarQube code smell - Add //NOSONAR comment for new BLOCK_TRANSACTION_COUNT histogram label name in MetricsHistogram Relates tronprotocol#6624
1 parent 39dd708 commit 93d0083

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

common/src/main/java/org/tron/common/prometheus/MetricsHistogram.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class MetricsHistogram {
5252
init(MetricKeys.Histogram.BLOCK_TRANSACTION_COUNT,
5353
"Distribution of transaction counts per block.",
5454
new double[]{0, 10, 50, 100, 200, 500, 1000, 2000, 5000, 10000},
55-
"miner");
55+
"miner"); //NOSONAR - label name for histogram
5656
}
5757

5858
private MetricsHistogram() {

framework/src/test/java/org/tron/core/metrics/prometheus/PrometheusApiServiceTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040

4141
@Slf4j(topic = "metric")
4242
public class PrometheusApiServiceTest extends BaseTest {
43+
44+
private static final String MINER_LABEL = "miner";
45+
4346
static LocalDateTime localDateTime = LocalDateTime.now();
4447
@Resource
4548
private DposSlot dposSlot;
@@ -87,7 +90,7 @@ protected void check(byte[] address, Map<ByteString, String> witnessAndAccount)
8790
// Query histogram bucket le="0.0" for empty blocks
8891
Double emptyBlock = CollectorRegistry.defaultRegistry.getSampleValue(
8992
"tron:block_transaction_count_bucket",
90-
new String[] {"miner", "le"}, new String[] {minerBase58, "0.0"});
93+
new String[] {MINER_LABEL, "le"}, new String[] {minerBase58, "0.0"});
9194

9295
Assert.assertNotNull("Empty block bucket should exist for miner: " + minerBase58, emptyBlock);
9396
Assert.assertEquals("Should have 1 empty block", 1, emptyBlock.intValue());
@@ -125,7 +128,7 @@ protected void check(byte[] address, Map<ByteString, String> witnessAndAccount)
125128
// Collect empty blocks count from histogram bucket
126129
Double witnessEmptyBlock = CollectorRegistry.defaultRegistry.getSampleValue(
127130
"tron:block_transaction_count_bucket",
128-
new String[] {"miner", "le"}, new String[] {witnessBase58, "0.0"});
131+
new String[] {MINER_LABEL, "le"}, new String[] {witnessBase58, "0.0"});
129132
Assert.assertNotNull("Empty block bucket should exist for witness: " + witnessBase58,
130133
witnessEmptyBlock);
131134
totalNewWitnessEmptyBlocks += witnessEmptyBlock;

0 commit comments

Comments
 (0)