mirror of https://github.com/hyperledger/besu
Fix metrics breakages (#1185)
* Number of metrics labels need to match up with constructor * Number of labels must be consistant, so I split it into two metrics * Also, naming best practices say that sum() and avg() of a metric should be meaningful, separating into two metrics fixes that. * fix style issues (finals, intellij warnings) * Change NoOpMetrics to check label count. * Cascading changes to support this in many support classes. Mostly places we presumed all NoOpMetrics were equals. Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>pull/2/head
parent
cdefb330be
commit
74e2b5a632
@ -0,0 +1,71 @@ |
||||
/* |
||||
* Copyright 2019 ConsenSys AG. |
||||
* |
||||
* 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 tech.pegasys.pantheon.metrics.noop; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
||||
|
||||
import tech.pegasys.pantheon.metrics.Counter; |
||||
import tech.pegasys.pantheon.metrics.LabelledMetric; |
||||
import tech.pegasys.pantheon.metrics.MetricCategory; |
||||
import tech.pegasys.pantheon.metrics.MetricsSystem; |
||||
import tech.pegasys.pantheon.metrics.OperationTimer; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
public class NoOpMetricsSystemTest { |
||||
|
||||
private final MetricsSystem metricsSystem = new NoOpMetricsSystem(); |
||||
|
||||
@Test |
||||
public void labelCountsMatchOnCounter() { |
||||
final LabelledMetric<Counter> labeledCounter = |
||||
metricsSystem.createLabelledCounter(MetricCategory.PROCESS, "name", "help", "label1"); |
||||
assertThat(labeledCounter.labels("one")).isSameAs(NoOpMetricsSystem.NO_OP_COUNTER); |
||||
} |
||||
|
||||
@Test |
||||
public void failsWheLabelCountsDoNotMatchOnCounter() { |
||||
final LabelledMetric<Counter> labeledCounter = |
||||
metricsSystem.createLabelledCounter( |
||||
MetricCategory.PROCESS, "name", "help", "label1", "label2"); |
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) |
||||
.isThrownBy(() -> labeledCounter.labels("one")) |
||||
.withMessage("The count of labels used must match the count of labels expected."); |
||||
assertThatExceptionOfType(IllegalArgumentException.class) |
||||
.isThrownBy(() -> labeledCounter.labels("one", "two", "three")) |
||||
.withMessage("The count of labels used must match the count of labels expected."); |
||||
} |
||||
|
||||
@Test |
||||
public void labelCountsMatchOnTimer() { |
||||
final LabelledMetric<OperationTimer> labeledTimer = |
||||
metricsSystem.createLabelledTimer(MetricCategory.PROCESS, "name", "help", "label1"); |
||||
assertThat(labeledTimer.labels("one")).isSameAs(NoOpMetricsSystem.NO_OP_OPERATION_TIMER); |
||||
} |
||||
|
||||
@Test |
||||
public void failsWheLabelCountsDoNotMatchOnTimer() { |
||||
final LabelledMetric<OperationTimer> labeledTimer = |
||||
metricsSystem.createLabelledTimer( |
||||
MetricCategory.PROCESS, "name", "help", "label1", "label2"); |
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) |
||||
.isThrownBy(() -> labeledTimer.labels("one")) |
||||
.withMessage("The count of labels used must match the count of labels expected."); |
||||
assertThatExceptionOfType(IllegalArgumentException.class) |
||||
.isThrownBy(() -> labeledTimer.labels("one", "two", "three")) |
||||
.withMessage("The count of labels used must match the count of labels expected."); |
||||
} |
||||
} |
Loading…
Reference in new issue