Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/caliper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: basicAssetWithCaliper
on:
pull_request:
push:
schedule:
- cron: '0 0 * * 5' # https://crontab.guru/#0_0_*_*_5
jobs:
basicAssetWithCaliper:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
with:
submodules: true
- uses: actions/setup-go@main
with:
go-version: 1.18
- name: install kind
run: go install sigs.k8s.io/kind@v0.12.0
- name: check version
run: kind version
- name: install kubectl
run: curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
- name: check version
run: kubectl version || true
- name: infra up
run: ./infra.sh up
- name: infra prometheus
run: ./infra.sh prometheus
- name: infra jaeger
run: ./infra.sh jaeger
- name: sleep as infra ready
run: sleep 60
- name: infra verify
run: ./infra.sh verify
- name: Fabric network up
run: cd ./SUT/fabric && ./network.sh up
- name: sleep as pod ready
run: sleep 60
- name: set up fabric channel
run: cd ./SUT/fabric && ./network.sh channel
- name: set up chaincode pod
run: cd ./SUT/fabric && ./network.sh chaincode deploy
- name: invoke chaincode for test
run: cd ./SUT/fabric && ./network.sh chaincode invoke '{"Args":["CreateAsset","5","blue","35","tom","1000"]}'
- name: query invoke result
run: cd ./SUT/fabric && ./network.sh chaincode query '{"Args":["ReadAsset","5"]}'
- name: run Caliper based traffic
run: cd ./Traffic/fabric && ./caliper.sh
- name: sleep a while
run: sleep 240
- name: verify pods
run: kubectl get po
- name: save pod status
run: kubectl get po | grep caliper > log.out
- name: verify caliper
run: kubectl describe po $(cat log.out|awk -F ' ' '{print $1}')
- name: verify caliper
run: kubectl logs $(cat log.out|awk -F ' ' '{print $1}') -c main
- name: cleanup
run: ./infra.sh down
67 changes: 67 additions & 0 deletions Traffic/fabric/caliper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0

set -o errexit
#set -x

NS=default

function main() {
#const caliper config sample
config_caliper_sample
#start caliper
rollout_caliper_sample
}

function extract_MSP_archives() {
# rm
rm -rf ./build/msp
mkdir -p ./build/msp

kubectl -n $NS exec deploy/org1-ecert-ca -- tar zcf - -C /var/hyperledger/fabric organizations/peerOrganizations/org1.example.com/msp | tar zxf - -C build/msp
kubectl -n $NS exec deploy/org2-ecert-ca -- tar zcf - -C /var/hyperledger/fabric organizations/peerOrganizations/org2.example.com/msp | tar zxf - -C build/msp
kubectl -n $NS exec deploy/org0-ecert-ca -- tar zcf - -C /var/hyperledger/fabric organizations/ordererOrganizations/org0.example.com/msp | tar zxf - -C build/msp
kubectl -n $NS exec deploy/org1-ecert-ca -- tar zcf - -C /var/hyperledger/fabric organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp | tar zxf - -C build/msp
kubectl -n $NS exec deploy/org2-ecert-ca -- tar zcf - -C /var/hyperledger/fabric organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp | tar zxf - -C build/msp
}

function config_caliper_sample() {
echo "Starting caliper configuration"
# rm
rm -rf ./build/caliper
# make dir
mkdir -p ./build/caliper

# construct_rest_sample_configmap
extract_MSP_archives

cat ./build/msp/organizations/peerOrganizations/org1.example.com/msp/tlscacerts/org1-tls-ca.pem > ./build/caliper/org1-tls-ca.pem
cat ./build/msp/organizations/peerOrganizations/org1.example.com/msp/cacerts/org1-ecert-ca.pem > ./build/caliper/org1-ecert-ca.pem
cat ./build/msp/organizations/peerOrganizations/org1.example.com/users/Admin\@org1.example.com/msp/signcerts/cert.pem > ./build/caliper/HLF_CERTIFICATE_ORG1
cat ./build/msp/organizations/peerOrganizations/org1.example.com/users/Admin\@org1.example.com/msp/keystore/server.key > ./build/caliper/HLF_PRIVATE_KEY_ORG1
# id
# tls cert
# config file
cp ./scripts/caliperconnection.yaml ./build/caliper/connection.yaml
cp ./scripts/readAsset.js ./build/caliper/readAsset.js
cp ./scripts/networkConfig.yaml ./build/caliper/networkConfig.yaml
cp ./scripts/myAssetBenchmark.yaml ./build/caliper/myAssetBenchmark.yaml

kubectl -n $NS delete configmap fabric-caliper-sample-config || true
kubectl -n $NS create configmap fabric-caliper-sample-config --from-file=./build/caliper/
# kube config
echo "Complete caliper configuration"
}

function rollout_caliper_sample() {
echo "Starting caliper for traffic"

# to do here, play as a job?
# to do here part2, play as a distributed job?
#kubectl -n $NS apply -f kube/fabric-tape-sample.yaml
kubectl delete -f ./kube/fabric-caliper-sample.yaml -n $NS || true
kubectl apply -f ./kube/fabric-caliper-sample.yaml -n $NS
echo "Complete caliper init"
}

main
41 changes: 41 additions & 0 deletions Traffic/fabric/kube/fabric-caliper-sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: caliper
annotations:
"sidecar.jaegertracing.io/inject": "true"
spec:
replicas: 1
selector:
matchLabels:
app: caliper
template:
metadata:
labels:
app: caliper
spec:
containers:
- name: main
image: hyperledger/caliper:0.5.0
env:
- name: CALIPER_BIND_SUT
value: fabric:2.2
- name: CALIPER_BENCHCONFIG
value: /tmp/myAssetBenchmark.yaml
- name: CALIPER_NETWORKCONFIG
value: /tmp/networkConfig.yaml
command:
#- ls
#- /tmp
- caliper
- launch
- manager
imagePullPolicy: IfNotPresent
volumeMounts:
- name: configmap-volume
mountPath: /tmp
volumes:
- name: configmap-volume
configMap:
name: fabric-caliper-sample-config
#restartPolicy: Always
29 changes: 29 additions & 0 deletions Traffic/fabric/scripts/caliperconnection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: test-network-org1
version: 1.0.0
client:
organization: Org1MSP
connection:
timeout:
peer:
endorser: '300'
organizations:
Org1MSP:
mspid: Org1MSP
peers:
- peer0.org1.example.com
certificateAuthorities:
- ca.org1.example.com
peers:
peer0.org1.example.com:
url: grpcs://org1-peer1:7051
tlsCACerts:
path: /tmp/org1-tls-ca.pem
certificateAuthorities:
ca.org1.example.com:
url: https://org1-ecert-ca:7054
caName: ca-org1-ecert-ca
tlsCACerts:
path: /tmp/org1-ecert-ca.pem
httpOptions:
verify: false
19 changes: 19 additions & 0 deletions Traffic/fabric/scripts/myAssetBenchmark.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
test:
name: basic-contract-benchmark
description: test benchmark
workers:
type: local
number: 2
rounds:
- label: readAsset
description: Read asset benchmark
txDuration: 30
rateControl:
type: fixed-load
opts:
transactionLoad: 2
workload:
module: /tmp/readAsset.js
arguments:
assets: 10
contractId: asset-transfer-basic
24 changes: 24 additions & 0 deletions Traffic/fabric/scripts/networkConfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Caliper test
version: "2.0.0"

caliper:
blockchain: fabric

channels:
- channelName: mychannel
contracts:
- id: asset-transfer-basic
contractID: asset-transfer-basic

organizations:
- mspid: Org1MSP
identities:
certificates:
- name: 'Admin'
clientPrivateKey:
path: '/tmp/HLF_PRIVATE_KEY_ORG1'
clientSignedCert:
path: '/tmp/HLF_CERTIFICATE_ORG1'
connectionProfile:
path: '/tmp/connection.yaml'
discover: true
62 changes: 62 additions & 0 deletions Traffic/fabric/scripts/readAsset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';

const { WorkloadModuleBase } = require('@hyperledger/caliper-core');

class MyWorkload extends WorkloadModuleBase {
constructor() {
super();
}

async initializeWorkloadModule(workerIndex, totalWorkers, roundIndex, roundArguments, sutAdapter, sutContext) {
await super.initializeWorkloadModule(workerIndex, totalWorkers, roundIndex, roundArguments, sutAdapter, sutContext);

for (let i=0; i<this.roundArguments.assets; i++) {
const assetID = `${this.workerIndex}_${i}`;
console.log(`Worker ${this.workerIndex}: Creating asset ${assetID}`);
const request = {
contractId: this.roundArguments.contractId,
contractFunction: 'CreateAsset',
invokerIdentity: 'Admin',
contractArguments: [assetID,'blue','20','penguin','500'],
readOnly: false
};

await this.sutAdapter.sendRequests(request);
}
}

async submitTransaction() {
const randomId = Math.floor(Math.random()*this.roundArguments.assets);
const myArgs = {
contractId: this.roundArguments.contractId,
contractFunction: 'ReadAsset',
invokerIdentity: 'Admin',
contractArguments: [`${this.workerIndex}_${randomId}`],
readOnly: true
};

await this.sutAdapter.sendRequests(myArgs);
}

async cleanupWorkloadModule() {
for (let i=0; i<this.roundArguments.assets; i++) {
const assetID = `${this.workerIndex}_${i}`;
console.log(`Worker ${this.workerIndex}: Deleting asset ${assetID}`);
const request = {
contractId: this.roundArguments.contractId,
contractFunction: 'DeleteAsset',
invokerIdentity: 'Admin',
contractArguments: [assetID],
readOnly: false
};

await this.sutAdapter.sendRequests(request);
}
}
}

function createWorkloadModule() {
return new MyWorkload();
}

module.exports.createWorkloadModule = createWorkloadModule;