Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Commit 3e2972b

Browse files
Send a metric field in assets (#114)
* Add a duration metric to every object-like output - Replace simple map for key with outputKey struc - Time the invoke duration and add it as a field when possible. It excludes list of object for now. * Add log and comment * Force duration 0 in generated examples * Put duration in a metric struct * Use a function compatible with go 1.12 * Fix from review
1 parent 2b5278c commit 3e2972b

25 files changed

+201
-112
lines changed

EXAMPLES.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ peer chaincode invoke -n mycc -c '{"Args":["registerNode"]}' -C myc
88
##### Command output:
99
```json
1010
{
11+
"__metrics__": {
12+
"duration": 0
13+
},
1114
"id": "SampleOrg"
1215
}
1316
```
@@ -39,6 +42,9 @@ peer chaincode invoke -n mycc -c '{"Args":["registerDataManager","{\"name\":\"li
3942
##### Command output:
4043
```json
4144
{
45+
"__metrics__": {
46+
"duration": 0
47+
},
4248
"key": "da1bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482dcc"
4349
}
4450
```
@@ -58,6 +64,9 @@ peer chaincode invoke -n mycc -c '{"Args":["queryDataManager","{\"key\":\"da1bb7
5864
##### Command output:
5965
```json
6066
{
67+
"__metrics__": {
68+
"duration": 0
69+
},
6170
"description": {
6271
"hash": "8d4bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482eee",
6372
"storageAddress": "https://toto/dataManager/42234/description"
@@ -97,6 +106,9 @@ peer chaincode invoke -n mycc -c '{"Args":["registerDataSample","{\"hashes\":[\"
97106
##### Command output:
98107
```json
99108
{
109+
"__metrics__": {
110+
"duration": 0
111+
},
100112
"keys": [
101113
"bb1bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482dcc",
102114
"bb2bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482dcc"
@@ -134,6 +146,9 @@ peer chaincode invoke -n mycc -c '{"Args":["registerObjective","{\"name\":\"MSI
134146
##### Command output:
135147
```json
136148
{
149+
"__metrics__": {
150+
"duration": 0
151+
},
137152
"key": "5c1d9cd1c2c1082dde0921b56d11030c81f62fbb51932758b58ac2569dd0b379"
138153
}
139154
```
@@ -163,6 +178,9 @@ peer chaincode invoke -n mycc -c '{"Args":["registerAlgo","{\"name\":\"hog + svm
163178
##### Command output:
164179
```json
165180
{
181+
"__metrics__": {
182+
"duration": 0
183+
},
166184
"key": "fd1bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482dcc"
167185
}
168186
```
@@ -184,6 +202,9 @@ peer chaincode invoke -n mycc -c '{"Args":["registerDataSample","{\"hashes\":[\"
184202
##### Command output:
185203
```json
186204
{
205+
"__metrics__": {
206+
"duration": 0
207+
},
187208
"keys": [
188209
"aa1bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482dcc",
189210
"aa2bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482dcc"
@@ -319,6 +340,9 @@ peer chaincode invoke -n mycc -c '{"Args":["createTraintuple","{\"algoKey\":\"fd
319340
##### Command output:
320341
```json
321342
{
343+
"__metrics__": {
344+
"duration": 0
345+
},
322346
"key": "9da043ddc233996d2e62c196471290de4726fc59d65dbbd2b32a920326e8adf3"
323347
}
324348
```
@@ -344,12 +368,18 @@ peer chaincode invoke -n mycc -c '{"Args":["createTraintuple","{\"algoKey\":\"fd
344368
##### Command output:
345369
```json
346370
{
371+
"__metrics__": {
372+
"duration": 0
373+
},
347374
"key": "720f778397fa07e24c2f314599725bf97727ded07ff65a51fa1a97b24d11ecab"
348375
}
349376
```
350377
##### Command output:
351378
```json
352379
{
380+
"__metrics__": {
381+
"duration": 0
382+
},
353383
"key": "720f778397fa07e24c2f314599725bf97727ded07ff65a51fa1a97b24d11ecab"
354384
}
355385
```
@@ -418,6 +448,9 @@ peer chaincode invoke -n mycc -c '{"Args":["logStartTrain","{\"key\":\"9da043ddc
418448
##### Command output:
419449
```json
420450
{
451+
"__metrics__": {
452+
"duration": 0
453+
},
421454
"algo": {
422455
"hash": "fd1bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482dcc",
423456
"name": "hog + svm",
@@ -469,6 +502,9 @@ peer chaincode invoke -n mycc -c '{"Args":["logSuccessTrain","{\"key\":\"9da043d
469502
##### Command output:
470503
```json
471504
{
505+
"__metrics__": {
506+
"duration": 0
507+
},
472508
"algo": {
473509
"hash": "fd1bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482dcc",
474510
"name": "hog + svm",
@@ -518,6 +554,9 @@ peer chaincode invoke -n mycc -c '{"Args":["queryTraintuple","{\"key\":\"9da043d
518554
##### Command output:
519555
```json
520556
{
557+
"__metrics__": {
558+
"duration": 0
559+
},
521560
"algo": {
522561
"hash": "fd1bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482dcc",
523562
"name": "hog + svm",
@@ -571,6 +610,9 @@ peer chaincode invoke -n mycc -c '{"Args":["createTesttuple","{\"dataManagerKey\
571610
##### Command output:
572611
```json
573612
{
613+
"__metrics__": {
614+
"duration": 0
615+
},
574616
"key": "3b807eb0bcd6b0798dc8f6eb415d2e58fb4d3515d2b00d4b888be1ca8145b7d8"
575617
}
576618
```
@@ -594,6 +636,9 @@ peer chaincode invoke -n mycc -c '{"Args":["createTesttuple","{\"dataManagerKey\
594636
##### Command output:
595637
```json
596638
{
639+
"__metrics__": {
640+
"duration": 0
641+
},
597642
"key": "4d49bf9147bf391f9610d830aae6630290e128dacd7c3540e82178a0e002951e"
598643
}
599644
```
@@ -617,6 +662,9 @@ peer chaincode invoke -n mycc -c '{"Args":["createTesttuple","{\"dataManagerKey\
617662
##### Command output:
618663
```json
619664
{
665+
"__metrics__": {
666+
"duration": 0
667+
},
620668
"key": "76d4a5908359eb6ba9c8fc89254c4b08e23aa20471ea3ddeee9a2835825dbd72"
621669
}
622670
```
@@ -721,6 +769,9 @@ peer chaincode invoke -n mycc -c '{"Args":["logStartTest","{\"key\":\"4d49bf9147
721769
##### Command output:
722770
```json
723771
{
772+
"__metrics__": {
773+
"duration": 0
774+
},
724775
"algo": {
725776
"hash": "fd1bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482dcc",
726777
"name": "hog + svm",
@@ -772,6 +823,9 @@ peer chaincode invoke -n mycc -c '{"Args":["logSuccessTest","{\"key\":\"4d49bf91
772823
##### Command output:
773824
```json
774825
{
826+
"__metrics__": {
827+
"duration": 0
828+
},
775829
"algo": {
776830
"hash": "fd1bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482dcc",
777831
"name": "hog + svm",
@@ -821,6 +875,9 @@ peer chaincode query -n mycc -c '{"Args":["queryTesttuple","{\"key\":\"4d49bf914
821875
##### Command output:
822876
```json
823877
{
878+
"__metrics__": {
879+
"duration": 0
880+
},
824881
"algo": {
825882
"hash": "fd1bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482dcc",
826883
"name": "hog + svm",
@@ -979,6 +1036,9 @@ peer chaincode query -n mycc -c '{"Args":["queryModelDetails","{\"key\":\"9da043
9791036
##### Command output:
9801037
```json
9811038
{
1039+
"__metrics__": {
1040+
"duration": 0
1041+
},
9821042
"nonCertifiedTesttuples": [
9831043
{
9841044
"algo": {
@@ -1181,6 +1241,9 @@ peer chaincode query -n mycc -c '{"Args":["queryModelPermissions","{\"key\":\"ee
11811241
##### Command output:
11821242
```json
11831243
{
1244+
"__metrics__": {
1245+
"duration": 0
1246+
},
11841247
"process": {
11851248
"authorizedIDs": [],
11861249
"public": true
@@ -1203,6 +1266,9 @@ peer chaincode query -n mycc -c '{"Args":["queryDataset","{\"key\":\"da1bb7c31f6
12031266
##### Command output:
12041267
```json
12051268
{
1269+
"__metrics__": {
1270+
"duration": 0
1271+
},
12061272
"description": {
12071273
"hash": "8d4bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482eee",
12081274
"storageAddress": "https://toto/dataManager/42234/description"
@@ -1262,6 +1328,9 @@ peer chaincode invoke -n mycc -c '{"Args":["updateDataSample","{\"hashes\":[\"aa
12621328
##### Command output:
12631329
```json
12641330
{
1331+
"__metrics__": {
1332+
"duration": 0
1333+
},
12651334
"key": "{\"keys\": [\"aa1bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482dcc\"]}"
12661335
}
12671336
```
@@ -1281,6 +1350,9 @@ peer chaincode query -n mycc -c '{"Args":["queryDataset","{\"key\":\"38a320b2a67
12811350
##### Command output:
12821351
```json
12831352
{
1353+
"__metrics__": {
1354+
"duration": 0
1355+
},
12841356
"description": {
12851357
"hash": "8d4bb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482eee",
12861358
"storageAddress": "https://toto/dataManager/42234/description"
@@ -1363,6 +1435,9 @@ peer chaincode invoke -n mycc -c '{"Args":["createComputePlan","{\"cleanModels\"
13631435
"firstTraintupleID": "432fcffdf68892f5e4adeeed8bb618beaeaecf709f840671eca724a3e3109369",
13641436
"secondTraintupleID": "d23f8cf290b902417ae698d68e2c6835483521d54fcbece31208517759b7c299"
13651437
},
1438+
"__metrics__": {
1439+
"duration": 0
1440+
},
13661441
"aggregatetupleKeys": null,
13671442
"cleanModels": false,
13681443
"compositeTraintupleKeys": null,
@@ -1436,6 +1511,9 @@ peer chaincode invoke -n mycc -c '{"Args":["updateComputePlan","{\"computePlanID
14361511
"IDToKey": {
14371512
"thirdTraintupleID": "c163663889566a4c51fad3765107774891f8ed456dcc859a9a1a7fcd17b11386"
14381513
},
1514+
"__metrics__": {
1515+
"duration": 0
1516+
},
14391517
"aggregatetupleKeys": null,
14401518
"cleanModels": false,
14411519
"compositeTraintupleKeys": null,
@@ -1472,6 +1550,9 @@ peer chaincode invoke -n mycc -c '{"Args":["queryObjectiveLeaderboard","{\"objec
14721550
##### Command output:
14731551
```json
14741552
{
1553+
"__metrics__": {
1554+
"duration": 0
1555+
},
14751556
"objective": {
14761557
"description": {
14771558
"hash": "5c1d9cd1c2c1082dde0921b56d11030c81f62fbb51932758b58ac2569dd0b379",
@@ -1533,6 +1614,9 @@ peer chaincode invoke -n mycc -c '{"Args":["queryComputePlan","{\"key\":\"7dd808
15331614
```json
15341615
{
15351616
"IDToKey": {},
1617+
"__metrics__": {
1618+
"duration": 0
1619+
},
15361620
"aggregatetupleKeys": null,
15371621
"cleanModels": false,
15381622
"compositeTraintupleKeys": null,
@@ -1598,6 +1682,9 @@ peer chaincode invoke -n mycc -c '{"Args":["cancelComputePlan","{\"key\":\"7dd80
15981682
```json
15991683
{
16001684
"IDToKey": {},
1685+
"__metrics__": {
1686+
"duration": 0
1687+
},
16011688
"aggregatetupleKeys": null,
16021689
"cleanModels": false,
16031690
"compositeTraintupleKeys": null,

chaincode/algo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (algo *Algo) Set(db *LedgerDB, inp inputAlgo) (algoKey string, err error) {
5050
// -------------------------------------------------------------------------------------------
5151
// registerAlgo stores a new algo in the ledger.
5252
// If the key exists, it will override the value with the new one
53-
func registerAlgo(db *LedgerDB, args []string) (resp map[string]string, err error) {
53+
func registerAlgo(db *LedgerDB, args []string) (resp outputKey, err error) {
5454
inp := inputAlgo{}
5555
err = AssetFromJSON(args, &inp)
5656
if err != nil {
@@ -72,7 +72,7 @@ func registerAlgo(db *LedgerDB, args []string) (resp map[string]string, err erro
7272
if err != nil {
7373
return
7474
}
75-
return map[string]string{"key": algoKey}, nil
75+
return outputKey{Key: algoKey}, nil
7676
}
7777

7878
// queryAlgo returns an algo of the ledger given its key

chaincode/algo_aggregate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (algo *AggregateAlgo) Set(db *LedgerDB, inp inputAggregateAlgo) (algoKey st
5050
// -------------------------------------------------------------------------------------------
5151
// registerAggregateAlgo stores a new algo in the ledger.
5252
// If the key exists, it will override the value with the new one
53-
func registerAggregateAlgo(db *LedgerDB, args []string) (resp map[string]string, err error) {
53+
func registerAggregateAlgo(db *LedgerDB, args []string) (resp outputKey, err error) {
5454
inp := inputAggregateAlgo{}
5555
err = AssetFromJSON(args, &inp)
5656
if err != nil {
@@ -72,7 +72,7 @@ func registerAggregateAlgo(db *LedgerDB, args []string) (resp map[string]string,
7272
if err != nil {
7373
return
7474
}
75-
return map[string]string{"key": algoKey}, nil
75+
return outputKey{Key: algoKey}, nil
7676
}
7777

7878
// queryAggregateAlgo returns an algo of the ledger given its key

chaincode/algo_aggregate_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ func TestAggregateAlgo(t *testing.T) {
3939
resp, tt := registerItem(t, *mockStub, "aggregateAlgo")
4040

4141
inpAlgo = tt.(inputAggregateAlgo)
42-
res := map[string]string{}
42+
res := outputKey{}
4343
err := json.Unmarshal(resp.Payload, &res)
4444
assert.NoError(t, err, "should unmarshal without problem")
45-
assert.Contains(t, res, "key")
46-
algoKey := res["key"]
45+
algoKey := res.Key
4746
assert.Equalf(t, inpAlgo.Hash, algoKey, "when adding aggregate algo, key does not corresponds to its hash - key: %s and hash %s", algoKey, inpAlgo.Hash)
4847

4948
// Query algo from key and check the consistency of returned arguments

chaincode/algo_composite.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (algo *CompositeAlgo) Set(db *LedgerDB, inp inputCompositeAlgo) (algoKey st
5050
// -------------------------------------------------------------------------------------------
5151
// registerCompositeAlgo stores a new algo in the ledger.
5252
// If the key exists, it will override the value with the new one
53-
func registerCompositeAlgo(db *LedgerDB, args []string) (resp map[string]string, err error) {
53+
func registerCompositeAlgo(db *LedgerDB, args []string) (resp outputKey, err error) {
5454
inp := inputCompositeAlgo{}
5555
err = AssetFromJSON(args, &inp)
5656
if err != nil {
@@ -72,7 +72,7 @@ func registerCompositeAlgo(db *LedgerDB, args []string) (resp map[string]string,
7272
if err != nil {
7373
return
7474
}
75-
return map[string]string{"key": algoKey}, nil
75+
return outputKey{Key: algoKey}, nil
7676
}
7777

7878
// queryCompositeAlgo returns an algo of the ledger given its key

chaincode/algo_composite_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ func TestCompositeAlgo(t *testing.T) {
3939
resp, tt := registerItem(t, *mockStub, "compositeAlgo")
4040

4141
inpAlgo = tt.(inputCompositeAlgo)
42-
res := map[string]string{}
42+
res := outputKey{}
4343
err := json.Unmarshal(resp.Payload, &res)
4444
assert.NoError(t, err, "should unmarshal without problem")
45-
assert.Contains(t, res, "key")
46-
algoKey := res["key"]
45+
algoKey := res.Key
4746
assert.Equalf(t, inpAlgo.Hash, algoKey, "when adding composite algo, key does not corresponds to its hash - key: %s and hash %s", algoKey, inpAlgo.Hash)
4847

4948
// Query algo from key and check the consistency of returned arguments

chaincode/algo_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ func TestAlgo(t *testing.T) {
3737
resp, tt := registerItem(t, *mockStub, "algo")
3838

3939
inpAlgo = tt.(inputAlgo)
40-
res := map[string]string{}
40+
res := outputKey{}
4141
err := json.Unmarshal(resp.Payload, &res)
4242
assert.NoError(t, err, "should unmarshal without problem")
43-
assert.Contains(t, res, "key")
44-
algoKey := res["key"]
43+
algoKey := res.Key
4544
assert.Equalf(t, inpAlgo.Hash, algoKey, "when adding algo, key does not corresponds to its hash - key: %s and hash %s", algoKey, inpAlgo.Hash)
4645

4746
// Query algo from key and check the consistency of returned arguments

0 commit comments

Comments
 (0)