Skip to content

Commit

Permalink
feat(keychain-memory): add prometheus exporter
Browse files Browse the repository at this point in the history
	Primary Change
	--------------

	1. The keychain-memory 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. IPluginKeychainMemoryOptions interface in PluginKeychainMemory class now has a prometheusExporter optional field
	5. The PluginKeychainMemory 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 #537

Signed-off-by: Jagpreet Singh Sasan <jagpreet.singh.sasan@accenture.com>
  • Loading branch information
jagpreetsinghsasan authored and petermetz committed Mar 30, 2021
1 parent bcc574d commit a5affc5
Show file tree
Hide file tree
Showing 19 changed files with 1,418 additions and 19 deletions.
40 changes: 36 additions & 4 deletions packages/cactus-plugin-keychain-memory/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
# `@hyperledger/cactus-plugin-keychain-memory`

> TODO: description
## Prometheus Exporter

## Usage
This class creates a prometheus exporter, which scrapes the transactions (total transaction count) for the use cases incorporating the use of Keychain memory plugin.


### Usage
The prometheus exporter object is initialized in the `PluginKeychainMemory` class constructor itself, so instantiating the object of the `PluginKeychainMemory` class, gives access to the exporter object.
You can also initialize the prometheus exporter object seperately and then pass it to the `IPluginKeychainMemoryOptions` interface for `PluginKeychainMemory` constructor.

`getPrometheusExporterMetricsV1` function returns the prometheus exporter metrics, currently displaying the total key count, which currently updates everytime a new key is added/removed from the list of total keys.

### 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: 'keychain_memory_exporter'
metrics_path: api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/get-prometheus-exporter-metrics
scrape_interval: 5s
static_configs:
- targets: ['{host}:{port}']
```
// TODO: DEMONSTRATE API
```

Here the `host:port` is where the prometheus exporter metrics are exposed. The test cases (For example, packages/cactus-plugin-keychain-memory/src/test/typescript/unit/plugin-keychain-memory.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-keychain-plugin/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_keychain_memory_total_key_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.

0 comments on commit a5affc5

Please sign in to comment.