MCPcopy Index your code
hub / github.com/ContentSquare/chproxy / newScope

Function newScope

scope.go:60–93  ·  view source on GitHub ↗
(req *http.Request, u *user, c *cluster, cu *clusterUser, sessionId string, sessionTimeout int)

Source from the content-addressed store, hash-verified

58}
59
60func newScope(req *http.Request, u *user, c *cluster, cu *clusterUser, sessionId string, sessionTimeout int) *scope {
61 h := c.getHost()
62 if sessionId != "" {
63 h = c.getHostSticky(sessionId)
64 }
65 var localAddr string
66 if addr, ok := req.Context().Value(http.LocalAddrContextKey).(net.Addr); ok {
67 localAddr = addr.String()
68 }
69 s := &scope{
70 startTime: time.Now(),
71 id: newScopeID(),
72 host: h,
73 cluster: c,
74 user: u,
75 clusterUser: cu,
76 sessionId: sessionId,
77 sessionTimeout: sessionTimeout,
78
79 remoteAddr: req.RemoteAddr,
80 localAddr: localAddr,
81
82 labels: prometheus.Labels{
83 "user": u.name,
84 "cluster": c.name,
85 "cluster_user": cu.name,
86 "replica": h.ReplicaName(),
87 "cluster_node": h.Host(),
88 },
89
90 requestPacketSize: max(0, int(req.ContentLength)),
91 }
92 return s
93}
94
95func (s *scope) String() string {
96 return fmt.Sprintf("[ Id: %s; User %q(%d) proxying as %q(%d) to %q(%d); RemoteAddr: %q; LocalAddr: %q; Duration: %d μs]",

Callers 1

getScopeMethod · 0.85

Calls 6

newScopeIDFunction · 0.85
ReplicaNameMethod · 0.80
HostMethod · 0.80
getHostMethod · 0.45
getHostStickyMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected