mirror of https://github.com/hyperledger/besu
PIE-1858: Infrastructure for exposing PoA metrics for plugins. (#37)
[PIE-1858] Added functionality to register custom metrics categories and exposed some PoA data for metrics. Signed-off-by: Mark Terry <mark.terry@consensys.net>pull/66/head
parent
f68a1cdb81
commit
e1e720d905
@ -0,0 +1,19 @@ |
|||||||
|
/* |
||||||
|
* Copyright 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. |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: Apache-2.0 |
||||||
|
*/ |
||||||
|
package org.hyperledger.besu.consensus.common; |
||||||
|
|
||||||
|
public interface PoAContext { |
||||||
|
BlockInterface getBlockInterface(); |
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
/* |
||||||
|
* 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. |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: Apache-2.0 |
||||||
|
*/ |
||||||
|
package org.hyperledger.besu.consensus.common; |
||||||
|
|
||||||
|
import org.hyperledger.besu.ethereum.chain.Blockchain; |
||||||
|
import org.hyperledger.besu.plugin.data.Address; |
||||||
|
import org.hyperledger.besu.plugin.data.BlockHeader; |
||||||
|
import org.hyperledger.besu.plugin.services.metrics.PoAMetricsService; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collection; |
||||||
|
|
||||||
|
public class PoAMetricServiceImpl implements PoAMetricsService { |
||||||
|
|
||||||
|
private final BlockInterface blockInterface; |
||||||
|
private final Blockchain blockchain; |
||||||
|
|
||||||
|
public PoAMetricServiceImpl(final BlockInterface blockInterface, final Blockchain blockchain) { |
||||||
|
this.blockInterface = blockInterface; |
||||||
|
this.blockchain = blockchain; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Collection<Address> getValidatorsForLatestBlock() { |
||||||
|
return new ArrayList<>(blockInterface.validatorsInBlock(blockchain.getChainHeadHeader())); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Address getProposerOfBlock(final BlockHeader header) { |
||||||
|
return this.blockInterface.getProposerOfBlock(header); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
/* |
||||||
|
* 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. |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: Apache-2.0 |
||||||
|
*/ |
||||||
|
package org.hyperledger.besu.metrics; |
||||||
|
|
||||||
|
import org.hyperledger.besu.plugin.services.metrics.MetricCategory; |
||||||
|
import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public class MetricCategoryRegistryImpl implements MetricCategoryRegistry { |
||||||
|
|
||||||
|
private final List<MetricCategory> metricCategories = new ArrayList<>(); |
||||||
|
|
||||||
|
public List<MetricCategory> getMetricCategories() { |
||||||
|
return metricCategories; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void addMetricCategory(final MetricCategory newMetricCategory) { |
||||||
|
metricCategories.add(newMetricCategory); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
/* |
||||||
|
* 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. |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: Apache-2.0 |
||||||
|
*/ |
||||||
|
package org.hyperledger.besu.plugin.services.metrics; |
||||||
|
|
||||||
|
import org.hyperledger.besu.plugin.data.Address; |
||||||
|
import org.hyperledger.besu.plugin.data.BlockHeader; |
||||||
|
|
||||||
|
import java.util.Collection; |
||||||
|
|
||||||
|
/** |
||||||
|
* Provides relevant data for producing metrics on the status of a Proof of Authority (PoA) node. |
||||||
|
*/ |
||||||
|
public interface PoAMetricsService { |
||||||
|
|
||||||
|
/** |
||||||
|
* Retrieves the validators who have signed the latest block from the canonical chain. |
||||||
|
* |
||||||
|
* @return Identities of the validators who formed quorum on the latest block. |
||||||
|
*/ |
||||||
|
Collection<Address> getValidatorsForLatestBlock(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Retrieves the {@link Address} for the proposer of a block on the canonical chain. |
||||||
|
* |
||||||
|
* @param header The {@link BlockHeader} for which the proposer will be found. |
||||||
|
* @return The identity of the proposer for the given block. |
||||||
|
*/ |
||||||
|
Address getProposerOfBlock(final BlockHeader header); |
||||||
|
} |
Loading…
Reference in new issue