From 8804f4580242de8a3c689b87a55ab0d696720c47 Mon Sep 17 00:00:00 2001 From: ameanasad Date: Tue, 19 Sep 2023 10:49:53 -0400 Subject: [PATCH] feat: add core attr to trace span --- fetcher.go | 6 +++++- node.go | 2 ++ node_ring.go | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/fetcher.go b/fetcher.go index 728fd37..b7b3c80 100644 --- a/fetcher.go +++ b/fetcher.go @@ -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() diff --git a/node.go b/node.go index 8936ec9..f21f1b2 100644 --- a/node.go +++ b/node.go @@ -17,6 +17,7 @@ const ( type Node struct { URL string ComplianceCid string + Core bool PredictedLatency float64 PredictedThroughput float64 @@ -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](), } } diff --git a/node_ring.go b/node_ring.go index dfe6b31..eafbbf3 100644 --- a/node_ring.go +++ b/node_ring.go @@ -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()