Skip to content

Commit fea547f

Browse files
jagpreetsinghsasanpetermetz
authored andcommitted
feat(keychain-vault): add prometheus exporter
Primary Change -------------- 1. The keychain-vault 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. IPluginKeychainVaultOptions interface in PluginKeychainVault class now has a prometheusExporter optional field 5. The PluginKeychainMemory class has relevant functions and codes to incorporate prometheus exporter 6. Added Readme.md on the prometheus exporter usage Fixes hyperledger-cacti#536 Signed-off-by: Jagpreet Singh Sasan <[email protected]>
1 parent edb8eac commit fea547f

File tree

12 files changed

+845
-135
lines changed

12 files changed

+845
-135
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
11
# `@hyperledger/cactus-plugin-keychain-vault`
22

3-
> TODO: description
3+
## Prometheus Exporter
44

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

7+
8+
### Usage
9+
The prometheus exporter object is initialized in the `PluginKeychainVault` class constructor itself, so instantiating the object of the `PluginKeychainVault` class, gives access to the exporter object.
10+
You can also initialize the prometheus exporter object seperately and then pass it to the `IPluginKeychainVaultOptions` interface for `PluginKeychainVault` constructor.
11+
12+
`getPrometheusExporterMetricsV1` function returns the prometheus exporter metrics, currently displaying the total key count, which currently increments everytime the `set()` and `delete()` method of the `PluginKeychainVault` class is called.
13+
14+
### Prometheus Integration
15+
To use Prometheus with this exporter make sure to install [Prometheus main component](https://prometheus.io/download/).
16+
Once Prometheus is setup, the corresponding scrape_config needs to be added to the prometheus.yml
17+
18+
```(yaml)
19+
- job_name: 'keychain_vault_exporter'
20+
metrics_path: api/v1/plugins/@hyperledger/cactus-plugin-keychain-vault/get-prometheus-exporter-metrics
21+
scrape_interval: 5s
22+
static_configs:
23+
- targets: ['{host}:{port}']
724
```
8-
// TODO: DEMONSTRATE API
9-
```
25+
26+
Here the `host:port` is where the prometheus exporter metrics are exposed. The test cases (For example, packages/cactus-plugin-keychain-vault/src/test/typescript/integration/plugin-keychain-vault.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)
27+
`Metrics URL: http://0.0.0.0:42379/api/v1/plugins/@hyperledger/cactus-plugin-keychain-plugin/get-prometheus-exporter-metrics`
28+
29+
Once edited, you can start the prometheus service by referencing the above edited prometheus.yml file.
30+
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_vault_total_key_count** and click **execute**
31+
32+
### Helper code
33+
34+
###### response.type.ts
35+
This file contains the various responses of the metrics.
36+
37+
###### data-fetcher.ts
38+
This file contains functions encasing the logic to process the data points
39+
40+
###### metrics.ts
41+
This file lists all the prometheus metrics and what they are used for.

packages/cactus-plugin-keychain-vault/package-lock.json

+210
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)