forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(quorum): add prometheus exporter
Primary Change -------------- 1. The quorum ledger connector plugin now includes the prometheus metrics exporter integration 2. OpenAPI spec now has api endpoint for the getting the prometheus metrics Refactorings that were also necessary to accomodate 1) and 2) ------------------------------------------------------------ 3. GetPrometheusMetricsV1 class is created to handle the corresponding api endpoint 4. IPluginLedgerConnectorQuorumOptions interface in PluginLedgerConnectorQuorum class now has a prometheusExporter optional field 5. The PluginLedgerConnectorQuorum class has relevant functions and codes to incorporate prometheus exporter 6. deploy-contract-from-json.test.ts is changed to incorporate the prometheus exporter 7. Added Readme.md on the prometheus exporter usage Fixes hyperledger-cacti#534 Signed-off-by: Jagpreet Singh Sasan <[email protected]>
- Loading branch information
1 parent
24d593d
commit dea8eeb
Showing
12 changed files
with
479 additions
and
4 deletions.
There are no files selected for viewing
135 changes: 133 additions & 2 deletions
135
packages/cactus-plugin-ledger-connector-quorum/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,140 @@ | ||
# `@hyperledger/cactus-plugin-ledger-connector-quorum` | ||
|
||
> TODO: description | ||
This plugin provides `Cactus` a way to interact with Quorum networks. Using this we can perform: | ||
* Deploy Smart-contracts through bytecode. | ||
* Build and sign transactions using different keystores. | ||
* Invoke smart-contract functions that we have deployed on the network. | ||
|
||
## Summary | ||
|
||
- [Getting Started](#getting-started) | ||
- [Usage](#usage) | ||
- [Prometheus Exporter](#prometheus-exporter) | ||
- [Runing the tests](#running-the-tests) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
- [Acknowledgments](#acknowledgments) | ||
|
||
## Getting Started | ||
|
||
Clone the git repository on your local machine. Follow these instructions that will get you a copy of the project up and running on | ||
your local machine for development and testing purposes. | ||
|
||
### Prerequisites | ||
|
||
In the root of the project to install the dependencies execute the command: | ||
```sh | ||
npm run comfigure | ||
``` | ||
|
||
### Compiling | ||
|
||
In the projects root folder, run this command to compile the plugin and create the dist directory: | ||
```sh | ||
npm run tsc | ||
``` | ||
|
||
## Usage | ||
|
||
To use this import public-api and create new **PluginLedgerConnectorQuorum**. | ||
```typescript | ||
const connector: PluginLedgerConnectorQuorum = new PluginLedgerConnectorQuorum({ | ||
instanceId: uuidV4(), | ||
rpcApiHttpHost, | ||
pluginRegistry: new PluginRegistry(), | ||
}); | ||
``` | ||
// TODO: DEMONSTRATE API | ||
You can make calls through the connector to the plugin API: | ||
|
||
```typescript | ||
async invokeContract(req: InvokeContractV1Request):Promise<InvokeContractV1Response>; | ||
async transactSigned(rawTransaction: string): Promise<RunTransactionResponse>; | ||
async transactPrivateKey(req: RunTransactionRequest): Promise<RunTransactionResponse>; | ||
async transactCactusKeychainRef(req: RunTransactionRequest):Promise<RunTransactionResponse>; | ||
async deployContract(req: DeployContractSolidityBytecodeV1Request):Promise<RunTransactionResponse>; | ||
async signTransaction(req: SignTransactionRequest):Promise<Optional<SignTransactionResponse>>; | ||
``` | ||
|
||
Call example to deploy a contract: | ||
```typescript | ||
const deployOut = await connector.deployContract({ | ||
web3SigningCredential: { | ||
ethAccount: firstHighNetWorthAccount, | ||
secret: "", | ||
type: Web3SigningCredentialType.GETHKEYCHAINPASSWORD, | ||
}, | ||
bytecode: ContractJson.bytecode, | ||
gas: 1000000, | ||
}); | ||
``` | ||
The field "type" can have the following values: | ||
```typescript | ||
enum Web3SigningCredentialType { | ||
CACTUSKEYCHAINREF = 'CACTUS_KEYCHAIN_REF', | ||
GETHKEYCHAINPASSWORD = 'GETH_KEYCHAIN_PASSWORD', | ||
PRIVATEKEYHEX = 'PRIVATE_KEY_HEX', | ||
NONE = 'NONE' | ||
} | ||
``` | ||
> Extensive documentation and examples in the [readthedocs](https://readthedocs.org/projects/hyperledger-cactus/) (WIP) | ||
## Prometheus Exporter | ||
|
||
This class creates a prometheus exporter, which scraps the transactions (total transaction count) for the use cases incorporating the use of Quorum connector plugin. | ||
|
||
### Prometheus Exporter Usage | ||
The prometheus exporter object is initialized in the `PluginLedgerConnectorQuorum` class constructor itself, so instantiating the object of the `PluginLedgerConnectorQuorum` class, gives access to the exporter object. | ||
You can also initialize the prometheus exporter object seperately and then pass it to the `IPluginLedgerConnectorQuorumOptions` interface for `PluginLedgerConnectoQuorum` constructor. | ||
|
||
`getPrometheusExporterMetricsEndpointV1` function returns the prometheus exporter metrics, currently displaying the total transaction count, which currently increments everytime the `transact()` method of the `PluginLedgerConnectorQuorum` class is called. | ||
|
||
### Prometheus Integration | ||
To use Prometheus with this exporter make sure to install [Prometheus main component](https://prometheus.io/download/). | ||
Once Prometheus is setup, the corresponding scrape_config needs to be added to the prometheus.yml | ||
|
||
```(yaml) | ||
- job_name: 'quorum_ledger_connector_exporter' | ||
metrics_path: api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-quorum/get-prometheus-exporter-metrics | ||
scrape_interval: 5s | ||
static_configs: | ||
- targets: ['{host}:{port}'] | ||
``` | ||
|
||
Here the `host:port` is where the prometheus exporter metrics are exposed. The test cases (For example, packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-from-json.test.ts) exposes it over `0.0.0.0` and a random port(). The random port can be found in the running logs of the test case and looks like (42379 in the below mentioned URL) | ||
`Metrics URL: http://0.0.0.0:42379/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-quorum/get-prometheus-exporter-metrics` | ||
|
||
Once edited, you can start the prometheus service by referencing the above edited prometheus.yml file. | ||
On the prometheus graphical interface (defaulted to http://localhost:9090), choose **Graph** from the menu bar, then select the **Console** tab. From the **Insert metric at cursor** drop down, select **cactus_quorum_total_tx_count** and click **execute** | ||
|
||
### Helper code | ||
|
||
###### response.type.ts | ||
This file contains the various responses of the metrics. | ||
|
||
###### data-fetcher.ts | ||
This file contains functions encasing the logic to process the data points | ||
|
||
###### metrics.ts | ||
This file lists all the prometheus metrics and what they are used for. | ||
|
||
## Running the tests | ||
|
||
To check that all has been installed correctly and that the pugin has no errors, there are two options to run the tests: | ||
|
||
* Run this command at the project's root: | ||
```sh | ||
npm run test:plugin-ledger-connector-quorum | ||
``` | ||
|
||
## Contributing | ||
|
||
We welcome contributions to Hyperledger Cactus in many forms, and there’s always plenty to do! | ||
|
||
Please review [CONTIRBUTING.md](../../CONTRIBUTING.md) to get started. | ||
|
||
## License | ||
|
||
This distribution is published under the Apache License Version 2.0 found in the [LICENSE](../../LICENSE) file. | ||
|
||
## Acknowledgments | ||
``` |
21 changes: 21 additions & 0 deletions
21
packages/cactus-plugin-ledger-connector-quorum/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.