Skip to content

Commit

Permalink
Make profitability histogram metric buckets configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
fab-10 committed Oct 31, 2024
1 parent 1564c77 commit 644c543
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public class LineaProfitabilityCliOptions implements LineaCliOptions {
"--plugin-linea-extra-data-set-min-gas-price-enabled";
public static final boolean DEFAULT_EXTRA_DATA_SET_MIN_GAS_PRICE_ENABLED = true;

public static final String PROFITABILITY_METRICS_BUCKETS =
"--plugin-linea-profitability-metrics-buckets";
public static final double[] DEFAULT_PROFITABILITY_METRICS_BUCKETS = {
0.9, 1.0, 1.2, 2, 5, 10, 100, 1000
};

@Positive
@CommandLine.Option(
names = {FIXED_GAS_COST_WEI},
Expand Down Expand Up @@ -135,6 +141,16 @@ public class LineaProfitabilityCliOptions implements LineaCliOptions {
"Enable setting min gas price runtime value via extra data field (default: ${DEFAULT-VALUE})")
private boolean extraDataSetMinGasPriceEnabled = DEFAULT_EXTRA_DATA_SET_MIN_GAS_PRICE_ENABLED;

@CommandLine.Option(
names = {PROFITABILITY_METRICS_BUCKETS},
arity = "1..*",
split = ",",
hidden = true,
paramLabel = "<FLOAT[]>",
description =
"List of buckets to use to create the histogram for profitability metrics (default: ${DEFAULT-VALUE})")
private double[] profitabilityMetricsBuckets = DEFAULT_PROFITABILITY_METRICS_BUCKETS;

private LineaProfitabilityCliOptions() {}

/**
Expand Down Expand Up @@ -164,6 +180,7 @@ public static LineaProfitabilityCliOptions fromConfig(
options.txPoolCheckP2pEnabled = config.txPoolCheckP2pEnabled();
options.extraDataPricingEnabled = config.extraDataPricingEnabled();
options.extraDataSetMinGasPriceEnabled = config.extraDataSetMinGasPriceEnabled();
options.profitabilityMetricsBuckets = config.profitabilityMetricsBuckets();
return options;
}

Expand All @@ -184,6 +201,7 @@ public LineaProfitabilityConfiguration toDomainObject() {
.txPoolCheckP2pEnabled(txPoolCheckP2pEnabled)
.extraDataPricingEnabled(extraDataPricingEnabled)
.extraDataSetMinGasPriceEnabled(extraDataSetMinGasPriceEnabled)
.profitabilityMetricsBuckets(profitabilityMetricsBuckets)
.build();
}

Expand All @@ -199,6 +217,7 @@ public String toString() {
.add(TX_POOL_ENABLE_CHECK_P2P, txPoolCheckP2pEnabled)
.add(EXTRA_DATA_PRICING_ENABLED, extraDataPricingEnabled)
.add(EXTRA_DATA_SET_MIN_GAS_PRICE_ENABLED, extraDataSetMinGasPriceEnabled)
.add(PROFITABILITY_METRICS_BUCKETS, profitabilityMetricsBuckets)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class LineaProfitabilityConfiguration implements LineaOptionsConfiguratio
/** It is safe to keep this as long, since it will store value <= max_int * 1000 */
private long variableCostWei;

/** It is safe to keep this as long, since it will store value <= max_int * 1000 */
private long ethGasPriceWei;

private double minMargin;
Expand All @@ -42,6 +43,7 @@ public class LineaProfitabilityConfiguration implements LineaOptionsConfiguratio
private boolean txPoolCheckP2pEnabled;
private boolean extraDataPricingEnabled;
private boolean extraDataSetMinGasPriceEnabled;
private double[] profitabilityMetricsBuckets;

/**
* These 2 parameters must be atomically updated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public interface LabelValue {
String value();
}

private static final double[] DEFAULT_HISTOGRAM_BUCKETS = {0.9, 1.0, 1.2, 2, 5, 10, 100, 1000};
private static final String LABEL_VALUES_SEPARATOR = "\u2060";
private final LabelledMetric<Histogram> histogram;
private final Map<String, Double> mins;
Expand All @@ -49,6 +48,7 @@ public HistogramMetrics(
final LineaMetricCategory category,
final String name,
final String help,
final double[] buckets,
final Class<? extends LabelValue>... labels) {

final var labelNames = getLabelNames(labels);
Expand All @@ -72,11 +72,7 @@ public HistogramMetrics(

this.histogram =
metricsSystem.createLabelledHistogram(
category,
name,
StringUtils.capitalize(help) + " buckets",
DEFAULT_HISTOGRAM_BUCKETS,
labelNames);
category, name, StringUtils.capitalize(help) + " buckets", buckets, labelNames);
}

@SafeVarargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ public TransactionPoolProfitabilityMetrics(
this.blockchainService = blockchainService;
this.histogramMetrics =
new HistogramMetrics(
metricsSystem, TX_POOL_PROFITABILITY, "ratio", "transaction pool profitability ratio");
metricsSystem,
TX_POOL_PROFITABILITY,
"ratio",
"transaction pool profitability ratio",
profitabilityConf.profitabilityMetricsBuckets());
}

public void update() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public ProfitableTransactionSelector(
SEQUENCER_PROFITABILITY,
"ratio",
"sequencer profitability ratio",
profitabilityConf.profitabilityMetricsBuckets(),
Phase.class))
: Optional.empty();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.hyperledger.besu.plugin.data.TransactionSelectionResult;
import org.hyperledger.besu.plugin.services.BlockchainService;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelector;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -65,9 +66,11 @@ public class ProfitableTransactionSelectorTest {
.build();
private TestableProfitableTransactionSelector transactionSelector;
private MetricsSystem metricsSystem = new NoOpMetricsSystem();
private MetricCategoryRegistry metricCategoryRegistry;

@BeforeEach
public void initialize() {
metricCategoryRegistry = mock(MetricCategoryRegistry.class);
transactionSelector = newSelectorForNewBlock();
transactionSelector.reset();
}
Expand All @@ -76,7 +79,11 @@ private TestableProfitableTransactionSelector newSelectorForNewBlock() {
final var blockchainService = mock(BlockchainService.class);
when(blockchainService.getNextBlockBaseFee()).thenReturn(Optional.of(BASE_FEE));
return new TestableProfitableTransactionSelector(
blockchainService, txSelectorConf, profitabilityConf, metricsSystem);
blockchainService,
txSelectorConf,
profitabilityConf,
metricsSystem,
metricCategoryRegistry);
}

@Test
Expand Down Expand Up @@ -414,7 +421,8 @@ private static class TestableProfitableTransactionSelector extends ProfitableTra
final BlockchainService blockchainService,
final LineaTransactionSelectorConfiguration txSelectorConf,
final LineaProfitabilityConfiguration profitabilityConf,
final MetricsSystem metricsSystem) {
final MetricsSystem metricsSystem,
final MetricCategoryRegistry metricCategoryRegistry) {
super(
blockchainService,
txSelectorConf,
Expand Down

0 comments on commit 644c543

Please sign in to comment.