MCPcopy Index your code
hub / github.com/coder/coder / ExtractDERPLatency

Function ExtractDERPLatency

tailnet/derpmap.go:176–199  ·  view source on GitHub ↗

ExtractDERPLatency extracts a map of derp region names to their latencies

(node *Node, derpMap *tailcfg.DERPMap)

Source from the content-addressed store, hash-verified

174
175// ExtractDERPLatency extracts a map of derp region names to their latencies
176func ExtractDERPLatency(node *Node, derpMap *tailcfg.DERPMap) map[string]time.Duration {
177 latencyMs := make(map[string]time.Duration)
178
179 // Convert DERP region IDs to friendly names for display in the UI.
180 for rawRegion, latency := range node.DERPLatency {
181 regionParts := strings.SplitN(rawRegion, "-", 2)
182 regionID, err := strconv.Atoi(regionParts[0])
183 if err != nil {
184 continue
185 }
186 region, found := derpMap.Regions[regionID]
187 if !found {
188 // It's possible that a workspace agent is using an old DERPMap
189 // and reports regions that do not exist. If that's the case,
190 // report the region as unknown!
191 region = &tailcfg.DERPRegion{
192 RegionID: regionID,
193 RegionName: fmt.Sprintf("Unnamed %d", regionID),
194 }
195 }
196 latencyMs[region.RegionName] = time.Duration(latency * float64(time.Second))
197 }
198 return latencyMs
199}
200
201// CompareDERPMaps returns true if the given DERPMaps are equivalent. Ordering
202// of slices is ignored.

Callers 3

recordLatenciesMethod · 0.92
collectNetworkStatsFunction · 0.92
TestExtractDERPLatencyFunction · 0.92

Calls 1

DurationMethod · 0.80

Tested by 1

TestExtractDERPLatencyFunction · 0.74