Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
feat: add core attr to trace span
Browse files Browse the repository at this point in the history
  • Loading branch information
AmeanAsad committed Sep 19, 2023
1 parent 310c079 commit 8804f45
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func (p *pool) fetchResource(ctx context.Context, from *Node, resource string, m
return ce
}

ctx, span := spanTrace(ctx, "Pool.FetchResource", trace.WithAttributes(attribute.String("from", from.URL), attribute.String("of", resource), attribute.String("mime", mime)))
p.ActiveNodes.lk.RLock()
isCore := p.ActiveNodes.IsCore(from)
p.ActiveNodes.lk.RUnlock()

ctx, span := spanTrace(ctx, "Pool.FetchResource", trace.WithAttributes(attribute.String("from", from.URL), attribute.String("of", resource), attribute.String("mime", mime), attribute.Bool("core", isCore)))
defer span.End()

requestId := uuid.NewString()
Expand Down
2 changes: 2 additions & 0 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
type Node struct {
URL string
ComplianceCid string
Core bool

PredictedLatency float64
PredictedThroughput float64
Expand All @@ -31,6 +32,7 @@ func NewNode(info state.NodeInfo) *Node {
return &Node{
URL: info.IP,
ComplianceCid: info.ComplianceCid,
Core: info.Core,
Samples: queue.New[NodeSample](),
}
}
Expand Down
11 changes: 11 additions & 0 deletions node_ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ func (nr *NodeRing) Contains(n *Node) bool {
return ok
}

func (nr *NodeRing) IsCore(n *Node) bool {
nr.lk.RLock()
defer nr.lk.RUnlock()

nd, ok := nr.Nodes[n.URL]
if !ok {
return false
}
return nd.Core
}

func (nr *NodeRing) GetNodes(key string, number int) ([]*Node, error) {
nr.lk.RLock()
defer nr.lk.RUnlock()
Expand Down

0 comments on commit 8804f45

Please sign in to comment.