Skip to content

Commit

Permalink
feat(cc-tx-viz): add methods to fabric connector
Browse files Browse the repository at this point in the history
Signed-off-by: Iulia Mihaiu <maramih.2007@yahoo.com>
  • Loading branch information
maramih committed Sep 22, 2021
1 parent 7e90a1a commit 994b1e2
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 8 deletions.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"caio",
"cccs",
"ccid",
"cctx",
"cids",
"Corda",
"Cordapp",
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
"test:plugin-ledger-connector-quorum": "tap --ts --jobs=1 --timeout=60 \"packages/cactus-*-quorum/src/test/typescript/{unit,integration}/\"",
"test:plugin-ledger-connector-iroha": "tap --ts --jobs=1 --timeout=600 \"packages/cactus-*-iroha/src/test/typescript/{unit,integration}/\"",
"test:plugin-htlc-besu": "tap --jobs=1 --timeout=600 \"packages/*htlc-eth-besu/src/test/typescript/{integration}/\"",
"build:dev:plugin-consortium-manual": "lerna exec --stream --scope '*/*manual-consortium' -- 'del-cli dist/** && tsc --project ./tsconfig.json && webpack --env=dev --target=node --config ../../webpack.config.js'",
"build:dev:plugin-cc-tx-visualization": "lerna exec --stream --scope '*/*cc-tx-visualization' -- 'del-cli dist/** && tsc --project ./tsconfig.json && webpack --env=dev --target=node --config ../../webpack.config.js'",
"build:dev:example-supply-chain-backend": "lerna exec --stream --scope '*/*example-supply-chain-b*' -- 'del-cli dist/** && tsc --project ./tsconfig.json && webpack --display-modules --env=dev --target=node --config ../../webpack.config.js'",
"build:dev:example-carbon-accounting-backend": "lerna exec --stream --scope '*/*carbon-accounting-b*' -- 'del-cli dist/** && tsc --project ./tsconfig.json && webpack --display-modules --env=dev --target=node --config ../../webpack.config.js' && cp -r examples/cactus-example-carbon-accounting-backend/src/utility-emissions-channel/ examples/cactus-example-carbon-accounting-backend/dist/lib/",
"build:dev:sdk": "lerna exec --stream --scope '*/*sdk' -- 'del-cli dist/** && tsc --project ./tsconfig.json && webpack --env=dev --target=node --config ../../webpack.config.js'",
"build:dev:plugin-ledger-connector-corda": "lerna exec --stream --scope '*/*connector-corda' -- 'del-cli dist/** && npm run tsc && webpack --env=dev --target=node --config ../../webpack.config.js'",
"test:plugin-ledger-connector-corda": "tap --ts --jobs=1 --timeout=600 \"packages/cactus-*-corda/src/test/typescript/{unit,integration}/\"",
"webpack": "npm-run-all webpack:dev webpack:prod",
"webpack:dev": "lerna run webpack:dev",
Expand Down
2 changes: 2 additions & 0 deletions packages/cactus-plugin-cc-tx-visualization/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cactus-openapi-spec-plugin-consortium-manual.json
src/main/typescript/generated/openapi/typescript-axios/.npmignore
173 changes: 173 additions & 0 deletions packages/cactus-plugin-cc-tx-visualization/src/main/json/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
{
"openapi": "3.0.3",
"info": {
"title": "Hyperledger Cactus Plugin - Consortium Web Service",
"description": "Manage a Cactus consortium through the APIs. Needs administrative privileges.",
"version": "0.0.1",
"license": {
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"servers": [
{
"url": "https://www.cactus.stream/{basePath}",
"description": "Public test instance",
"variables": {
"basePath": {
"default": ""
}
}
},
{
"url": "http://localhost:4000/{basePath}",
"description": "Local test instance",
"variables": {
"basePath": {
"default": ""
}
}
}
],
"components": {
"schemas": {
"GetNodeJwsResponse": {
"type": "object",
"required": [
"jws"
],
"properties": {
"jws": {
"description": "The JSON Web Signature of the Cactus node.",
"$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/schemas/JWSGeneral",
"nullable": false
}
}
},
"GetConsortiumJwsResponse": {
"type": "object",
"required": [
"jws"
],
"properties": {
"jws": {
"description": "The JSON Web Signature of the Cactus consortium.",
"$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/schemas/JWSGeneral",
"nullable": false,
"format": "The general format which is a JSON object, not a string."
}
}
},
"PrometheusExporterMetricsResponse": {
"type": "string",
"nullable": false
},
"GetNodeJwsRequest": {
"type": "object",
"properties": {
}
},
"GetConsortiumJwsRequest": {
"type": "object",
"properties": {
}
}
}
},
"paths": {
"/api/v1/plugins/@hyperledger/cactus-plugin-consortium-manual/consortium/jws": {
"post": {
"x-hyperledger-cactus": {
"http": {
"verbLowerCase": "post",
"path": "/api/v1/plugins/@hyperledger/cactus-plugin-consortium-manual/consortium/jws"
}
},
"operationId": "getConsortiumJwsV1",
"summary": "Retrieves a consortium JWS",
"description": "The JWS asserting the consortium metadata (pub keys and hosts of nodes)",
"parameters": [],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetConsortiumJwsRequest"
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetConsortiumJwsResponse"
}
}
}
}
}
}
},
"/api/v1/plugins/@hyperledger/cactus-plugin-consortium-manual/node/jws": {
"post": {
"x-hyperledger-cactus": {
"http": {
"verbLowerCase": "post",
"path": "/api/v1/plugins/@hyperledger/cactus-plugin-consortium-manual/node/jws"
}
},
"operationId": "getNodeJwsV1",
"summary": "Retrieves the JWT of a Cactus Node",
"parameters": [],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetNodeJwsRequest"
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetNodeJwsResponse"
}
}
}
}
}
}
},
"/api/v1/plugins/@hyperledger/cactus-plugin-consortium-manual/get-prometheus-exporter-metrics": {
"get": {
"x-hyperledger-cactus": {
"http": {
"verbLowerCase": "get",
"path": "/api/v1/plugins/@hyperledger/cactus-plugin-consortium-manual/get-prometheus-exporter-metrics"
}
},
"operationId": "getPrometheusMetricsV1",
"summary": "Get the Prometheus Metrics",
"parameters": [],
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/PrometheusExporterMetricsResponse"
}
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
wwwroot/*.js
node_modules
typings
dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

git_push.sh
.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface IWebAppOptions {

export interface IPluginCcTxVisualizationOptions extends ICactusPluginOptions {
prometheusExporter?: PrometheusExporter;
connectorRegistry?: PluginRegistry;
connectorRegistry: PluginRegistry;
logLevel?: LogLevelDesc;
webAppOptions?: IWebAppOptions;
}
Expand Down Expand Up @@ -65,9 +65,7 @@ export class PluginCcTxVisualization
options.connectorRegistry,
`${fnTag} options.connectorRegistry`,
);
if (options.connectorRegistry)
this.connectorRegistry = options.connectorRegistry;
else this.connectorRegistry = new PluginRegistry();
this.connectorRegistry = options.connectorRegistry;
// this.prometheusExporter.setNodeCount(this.getNodeCount());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,60 @@
/* eslint-disable prettier/prettier */
import { PluginRegistry } from "@hyperledger/cactus-core";
import test, { Test } from "tape";
import { v4 as uuidv4 } from "uuid";
import {
IPluginCcTxVisualizationOptions,
PluginCcTxVisualization,
} from "../../../main/typescript/plugin-cc-tx-visualization";
import { ICactusPlugin } from "@hyperledger/cactus-core-api";

test("Instantiation", (t: Test) => {
test("Basic Instantiation", (t: Test) => {
const options: IPluginCcTxVisualizationOptions = {
instanceId: uuidv4(),
connectorRegistry: new PluginRegistry(),
};

const pluginCcTxVisualization: PluginCcTxVisualization = new PluginCcTxVisualization(
options,
);

t.ok(pluginCcTxVisualization, "Instantiated");
t.end();
});

test("Dummy Connector Instantiaton", (t: Test) => {
class DummyPlugin implements ICactusPlugin{
private readonly instanceId: string;

constructor(){
this.instanceId = "CCTX_DUMMY_" + uuidv4();
}
public getInstanceId(): string {
return this.instanceId;
}
public getPackageName(): string {
return "DummyPlugin";
}
public async onPluginInit(): Promise<unknown> {
return;
}

}


//add connector reference to the registry
const connectorRegistryTest = new PluginRegistry();
connectorRegistryTest.add(new DummyPlugin());

const options: IPluginCcTxVisualizationOptions = {
instanceId: uuidv4(),
connectorRegistry: connectorRegistryTest,
};

const pluginCcTxVisualization: PluginCcTxVisualization = new PluginCcTxVisualization(
options,
);

t.ok(pluginCcTxVisualization, "Instantiated with a dummy connector");
t.end();
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prettier/prettier */
import fs from "fs";
import path from "path";
import { Server } from "http";
Expand Down Expand Up @@ -105,6 +106,7 @@ import {
CertDatastore,
IIdentityData,
} from "./identity/internal/cert-datastore";
import {performance} from "perf_hooks";
/**
* Constant value holding the default $GOPATH in the Fabric CLI container as
* observed on fabric deployments that are produced by the official examples
Expand Down Expand Up @@ -940,6 +942,10 @@ export class PluginLedgerConnectorFabric
public async transact(
req: RunTransactionRequest,
): Promise<RunTransactionResponse> {
//start transaction time
const startTx = performance.now();

//start tx
const fnTag = `${this.className}#transact()`;

const {
Expand Down Expand Up @@ -1043,14 +1049,22 @@ export class PluginLedgerConnectorFabric
throw new Error(`${fnTag} unknown ${message}`);
}
}
//end of Tx
const endTx = performance.now();
const txTimer = endTx - startTx;
this.prometheusExporter.addTimerOfCurrentTransaction(txTimer);

//logging the transaction
const outUtf8 = out.toString("utf-8");
const res: RunTransactionResponse = {
functionOutput: outUtf8,
success,
};
gateway.disconnect();
this.log.debug(`transact() response: %o`, res);
this.prometheusExporter.addCurrentTransaction();

// wouldn't add this anymore because i can call it in the above method as i need the no of tx before the timer
//this.prometheusExporter.addCurrentTransaction();

return res;
} catch (ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ import { Gauge } from "prom-client";

export const K_CACTUS_FABRIC_TOTAL_TX_COUNT = "cactus_fabric_total_tx_count";

export const K_CACTUS_FABRIC_TX_LATENCY = "cactus_fabric_tx_latency";

export const totalTxCount = new Gauge({
name: K_CACTUS_FABRIC_TOTAL_TX_COUNT,
help: "Total transactions executed",
labelNames: ["type"],
});

export const txLatency = new Gauge({
name: K_CACTUS_FABRIC_TX_LATENCY,
help: "Transaction latency",
labelNames: ["type"],
});
Loading

0 comments on commit 994b1e2

Please sign in to comment.