Skip to content

Commit

Permalink
worker result integrate metadata aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
zees-dev committed Jun 23, 2024
1 parent 5ae2c67 commit 2757eda
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions models/execute/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Result struct {
RequestID string `json:"request_id"`
Usage Usage `json:"usage,omitempty"`
Signature []byte `json:"signature,omitempty"`
Metadata interface{} `json:"metadata,omitempty"`
}

// Cluster represents the set of peers that executed the request.
Expand Down
6 changes: 6 additions & 0 deletions node/aggregate/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ type Result struct {
Frequency float64 `json:"frequency,omitempty"`
// Signature of this result
Signature []byte `json:"signature,omitempty"`
// Metadata is used to store additional information about the result.
Metadata interface{} `json:"metadata,omitempty"`
}

type resultStats struct {
seen uint
peers []peer.ID
signature []byte
metadata interface{}
}

func Aggregate(results execute.ResultMap) Results {
Expand All @@ -46,12 +49,14 @@ func Aggregate(results execute.ResultMap) Results {
seen: 0,
peers: make([]peer.ID, 0),
signature: res.Signature,
metadata: res.Metadata,
}
}

stat.seen++
stat.peers = append(stat.peers, executingPeer)
stat.signature = res.Signature
stat.metadata = res.Metadata

stats[output] = stat
}
Expand All @@ -65,6 +70,7 @@ func Aggregate(results execute.ResultMap) Results {
Peers: stat.peers,
Frequency: 100 * float64(stat.seen) / float64(total),
Signature: stat.signature,
Metadata: stat.metadata,
}

aggregated = append(aggregated, aggr)
Expand Down

0 comments on commit 2757eda

Please sign in to comment.