Skip to content

Commit a28edcf

Browse files
jagpreetsinghsasanpetermetz
authored andcommitted
fix(fabric): prometheus exporter metrics naming
Primary Change -------------- 1. Change the cactus_fabric_total_tx_count metric name to be fetched from a variable 2. Update the same in the test cases Signed-off-by: Jagpreet Singh Sasan <[email protected]>
1 parent 932d5a4 commit a28edcf

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Transactions } from "./response.type";
22

3-
import { totalTxCount } from "./metrics";
3+
import { totalTxCount, K_CACTUS_FABRIC_TOTAL_TX_COUNT } from "./metrics";
44

55
export async function collectMetrics(transactions: Transactions) {
6-
totalTxCount.labels("cactus_fabric_total_tx_count").set(transactions.counter);
6+
totalTxCount.labels(K_CACTUS_FABRIC_TOTAL_TX_COUNT).set(transactions.counter);
77
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Gauge } from "prom-client";
22

3+
export const K_CACTUS_FABRIC_TOTAL_TX_COUNT = "cactus_fabric_total_tx_count";
4+
35
export const totalTxCount = new Gauge({
4-
name: "cactus_fabric_total_tx_count",
6+
name: K_CACTUS_FABRIC_TOTAL_TX_COUNT,
57
help: "Total transactions executed",
68
labelNames: ["type"],
79
});

packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/prometheus-exporter/prometheus-exporter.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import promClient from "prom-client";
22
import { Transactions } from "./response.type";
3-
import { totalTxCount } from "./metrics";
4-
5-
export const K_CACTUS_FABRIC_TOTAL_TX_COUNT = "cactus_fabric_total_tx_count";
3+
import { totalTxCount, K_CACTUS_FABRIC_TOTAL_TX_COUNT } from "./metrics";
64

75
export interface IPrometheusExporterOptions {
86
pollingIntervalInMin?: number;
@@ -28,7 +26,7 @@ export class PrometheusExporter {
2826

2927
public async getPrometheusMetrics(): Promise<string> {
3028
const result = await promClient.register.getSingleMetricAsString(
31-
"cactus_fabric_total_tx_count",
29+
K_CACTUS_FABRIC_TOTAL_TX_COUNT,
3230
);
3331
return result;
3432
}

packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v1-4-x/run-transaction-endpoint-v1.test.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929

3030
import { IPluginLedgerConnectorFabricOptions } from "../../../../main/typescript/plugin-ledger-connector-fabric";
3131
import { DiscoveryOptions } from "fabric-network";
32+
import { K_CACTUS_FABRIC_TOTAL_TX_COUNT } from "../../../../main/typescript/prometheus-exporter/metrics";
3233

3334
/**
3435
* Use this to debug issues with the fabric node SDK
@@ -182,9 +183,16 @@ test("runs tx on a Fabric v1.4.8 ledger", async (t: Test) => {
182183
{
183184
const res = await apiClient.getPrometheusExporterMetricsV1();
184185
const promMetricsOutput =
185-
"# HELP cactus_fabric_total_tx_count Total transactions executed\n" +
186-
"# TYPE cactus_fabric_total_tx_count gauge\n" +
187-
'cactus_fabric_total_tx_count{type="cactus_fabric_total_tx_count"} 3';
186+
"# HELP " +
187+
K_CACTUS_FABRIC_TOTAL_TX_COUNT +
188+
" Total transactions executed\n" +
189+
"# TYPE " +
190+
K_CACTUS_FABRIC_TOTAL_TX_COUNT +
191+
" gauge\n" +
192+
K_CACTUS_FABRIC_TOTAL_TX_COUNT +
193+
'{type="' +
194+
K_CACTUS_FABRIC_TOTAL_TX_COUNT +
195+
'"} 3';
188196
t.ok(res);
189197
t.ok(res.data);
190198
t.equal(res.status, 200);

packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v2-2-x/run-transaction-endpoint-v1.test.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import {
3030
FabricSigningCredential,
3131
} from "../../../../main/typescript/public-api";
3232

33+
import { K_CACTUS_FABRIC_TOTAL_TX_COUNT } from "../../../../main/typescript/prometheus-exporter/metrics";
34+
3335
import { IPluginLedgerConnectorFabricOptions } from "../../../../main/typescript/plugin-ledger-connector-fabric";
3436
import { DiscoveryOptions } from "fabric-network";
3537

@@ -198,9 +200,16 @@ test("runs tx on a Fabric v2.2.0 ledger", async (t: Test) => {
198200
{
199201
const res = await apiClient.getPrometheusExporterMetricsV1();
200202
const promMetricsOutput =
201-
"# HELP cactus_fabric_total_tx_count Total transactions executed\n" +
202-
"# TYPE cactus_fabric_total_tx_count gauge\n" +
203-
'cactus_fabric_total_tx_count{type="cactus_fabric_total_tx_count"} 3';
203+
"# HELP " +
204+
K_CACTUS_FABRIC_TOTAL_TX_COUNT +
205+
" Total transactions executed\n" +
206+
"# TYPE " +
207+
K_CACTUS_FABRIC_TOTAL_TX_COUNT +
208+
" gauge\n" +
209+
K_CACTUS_FABRIC_TOTAL_TX_COUNT +
210+
'{type="' +
211+
K_CACTUS_FABRIC_TOTAL_TX_COUNT +
212+
'"} 3';
204213
t.ok(res);
205214
t.ok(res.data);
206215
t.equal(res.status, 200);

0 commit comments

Comments
 (0)