-
Notifications
You must be signed in to change notification settings - Fork 4
refactor: unify upstream label to use config name #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,7 +110,7 @@ func (s *Server) writePrometheusMetrics(w io.Writer, now time.Time) { | |
| snapshot := conn.snapshot() | ||
| key := prometheusConnectionGroup{ | ||
| module: prometheusLabelValueOrUnknown(snapshot.Module), | ||
| upstream: prometheusLabelValueOrUnknown(snapshot.UpstreamAddr), | ||
| upstream: prometheusLabelValueOrUnknown(snapshot.Upstream), | ||
| } | ||
|
Comment on lines
110
to
114
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documented in the PR description: this is intentionally a breaking change to the per-connection metrics ( |
||
| connectionCounts[key]++ | ||
| } | ||
|
|
@@ -138,21 +138,21 @@ func (s *Server) writePrometheusMetrics(w io.Writer, now time.Time) { | |
| _, _ = fmt.Fprintln(w, "# TYPE rsync_proxy_connection_sent_bytes gauge") | ||
| for _, conn := range connections { | ||
| snapshot := conn.snapshot() | ||
| _, _ = fmt.Fprintf(w, "rsync_proxy_connection_sent_bytes{%s} %d\n", prometheusLabels(snapshot.Index, snapshot.Module, snapshot.UpstreamAddr), snapshot.SentBytes) | ||
| _, _ = fmt.Fprintf(w, "rsync_proxy_connection_sent_bytes{%s} %d\n", prometheusLabels(snapshot.Index, snapshot.Module, snapshot.Upstream), snapshot.SentBytes) | ||
| } | ||
|
|
||
| _, _ = fmt.Fprintln(w, "# HELP rsync_proxy_connection_received_bytes Bytes received from clients for active connections.") | ||
| _, _ = fmt.Fprintln(w, "# TYPE rsync_proxy_connection_received_bytes gauge") | ||
| for _, conn := range connections { | ||
| snapshot := conn.snapshot() | ||
| _, _ = fmt.Fprintf(w, "rsync_proxy_connection_received_bytes{%s} %d\n", prometheusLabels(snapshot.Index, snapshot.Module, snapshot.UpstreamAddr), snapshot.ReceivedBytes) | ||
| _, _ = fmt.Fprintf(w, "rsync_proxy_connection_received_bytes{%s} %d\n", prometheusLabels(snapshot.Index, snapshot.Module, snapshot.Upstream), snapshot.ReceivedBytes) | ||
| } | ||
|
|
||
| _, _ = fmt.Fprintln(w, "# HELP rsync_proxy_connection_connected_timestamp_seconds Unix timestamp when active connections were established.") | ||
| _, _ = fmt.Fprintln(w, "# TYPE rsync_proxy_connection_connected_timestamp_seconds gauge") | ||
| for _, conn := range connections { | ||
| snapshot := conn.snapshot() | ||
| _, _ = fmt.Fprintf(w, "rsync_proxy_connection_connected_timestamp_seconds{%s} %d\n", prometheusLabels(snapshot.Index, snapshot.Module, snapshot.UpstreamAddr), snapshot.ConnectedAt.Unix()) | ||
| _, _ = fmt.Fprintf(w, "rsync_proxy_connection_connected_timestamp_seconds{%s} %d\n", prometheusLabels(snapshot.Index, snapshot.Module, snapshot.Upstream), snapshot.ConnectedAt.Unix()) | ||
| } | ||
|
|
||
| _, _ = fmt.Fprintln(w, "# HELP rsync_proxy_connection_duration_seconds Current duration of active connections.") | ||
|
|
@@ -163,7 +163,7 @@ func (s *Server) writePrometheusMetrics(w io.Writer, now time.Time) { | |
| if duration < 0 { | ||
| duration = 0 | ||
| } | ||
| _, _ = fmt.Fprintf(w, "rsync_proxy_connection_duration_seconds{%s} %.3f\n", prometheusLabels(snapshot.Index, snapshot.Module, snapshot.UpstreamAddr), duration) | ||
| _, _ = fmt.Fprintf(w, "rsync_proxy_connection_duration_seconds{%s} %.3f\n", prometheusLabels(snapshot.Index, snapshot.Module, snapshot.Upstream), duration) | ||
| } | ||
|
|
||
| _, _ = fmt.Fprintln(w, "# HELP rsync_proxy_accepted_connections_total Total accepted connections since start.") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,7 +59,7 @@ type ConnInfo struct { | |
| RemoteAddr string | ||
| ConnectedAt time.Time | ||
| Module string | ||
| UpstreamAddr string | ||
| Upstream string | ||
| SentBytes atomic.Int64 | ||
|
Comment on lines
59
to
63
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The field name |
||
| ReceivedBytes atomic.Int64 | ||
| } | ||
|
|
@@ -70,7 +70,7 @@ type connInfoSnapshot struct { | |
| RemoteAddr string `json:"remote"` | ||
| ConnectedAt time.Time `json:"connected"` | ||
| Module string `json:"module"` | ||
| UpstreamAddr string `json:"upstream"` | ||
| Upstream string `json:"upstream"` | ||
| SentBytes int64 `json:"sentBytes"` | ||
| ReceivedBytes int64 `json:"receivedBytes"` | ||
| } | ||
|
|
@@ -81,10 +81,10 @@ func (c *ConnInfo) SetModule(module string) { | |
| c.Module = module | ||
| } | ||
|
|
||
| func (c *ConnInfo) SetUpstreamAddr(upstreamAddr string) { | ||
| func (c *ConnInfo) SetUpstream(upstream string) { | ||
| c.mu.Lock() | ||
| defer c.mu.Unlock() | ||
| c.UpstreamAddr = upstreamAddr | ||
| c.Upstream = upstream | ||
| } | ||
|
|
||
| func (c *ConnInfo) snapshot() connInfoSnapshot { | ||
|
|
@@ -96,7 +96,7 @@ func (c *ConnInfo) snapshot() connInfoSnapshot { | |
| RemoteAddr: c.RemoteAddr, | ||
| ConnectedAt: c.ConnectedAt, | ||
| Module: c.Module, | ||
| UpstreamAddr: c.UpstreamAddr, | ||
| Upstream: c.Upstream, | ||
| SentBytes: c.SentBytes.Load(), | ||
| ReceivedBytes: c.ReceivedBytes.Load(), | ||
| } | ||
|
|
@@ -606,7 +606,7 @@ func (s *Server) relay(ctx context.Context, index uint32, downConn net.Conn) err | |
| target := targets[chooseTargetByClientIP(net.ParseIP(ip), len(targets))] | ||
| upstreamAddr := target.Addr | ||
| useProxyProtocol := target.UseProxyProtocol | ||
| info.SetUpstreamAddr(upstreamAddr) | ||
| info.SetUpstream(target.Upstream) | ||
|
|
||
| upstreamQueue, ok := s.getQueueForUpstream(target.Upstream) | ||
| if !ok { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -375,7 +375,7 @@ func TestStatusIncludesSelectedUpstream(t *testing.T) { | |
| if len(infos) != 1 { | ||
| return false | ||
| } | ||
| return infos[0].snapshot().UpstreamAddr == upstreamAddr | ||
| return infos[0].snapshot().Upstream == "u1" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The literal |
||
| }, time.Second, 10*time.Millisecond) | ||
|
|
||
| wg.Done() | ||
|
|
@@ -445,7 +445,7 @@ func TestMetricsIncludesActiveConnections(t *testing.T) { | |
| if len(infos) != 1 { | ||
| return false | ||
| } | ||
| return infos[0].snapshot().UpstreamAddr == upstreamAddr | ||
| return infos[0].snapshot().Upstream == "u1" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as the comment on line 378 — sticking with the existing |
||
| }, time.Second, 10*time.Millisecond) | ||
|
|
||
| resp, err := testHTTPClient().Get("http://" + srv.HTTPListener.Addr().String() + "/metrics") | ||
|
|
@@ -458,14 +458,15 @@ func TestMetricsIncludesActiveConnections(t *testing.T) { | |
|
|
||
| assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
| assert.Contains(t, text, "rsync_proxy_active_connections 1\n") | ||
| assert.Contains(t, text, fmt.Sprintf("rsync_proxy_active_connections_by_module{module=\"fake\",upstream=%q} 1\n", upstreamAddr)) | ||
| assert.Contains(t, text, "rsync_proxy_active_connections_by_module{module=\"fake\",upstream=\"u1\"} 1\n") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as the comment on line 378 — sticking with the existing |
||
| assert.Contains(t, text, "rsync_proxy_connection_sent_bytes{index=\"") | ||
| assert.Contains(t, text, "module=\"fake\"") | ||
| assert.Contains(t, text, fmt.Sprintf("upstream=%q", upstreamAddr)) | ||
| assert.Contains(t, text, "upstream=\"u1\"") | ||
| assert.Contains(t, text, "rsync_proxy_connection_received_bytes{index=\"") | ||
| assert.Contains(t, text, "rsync_proxy_connection_connected_timestamp_seconds{index=\"") | ||
| assert.Contains(t, text, "rsync_proxy_connection_duration_seconds{index=\"") | ||
| assert.NotContains(t, text, rawConn.LocalAddr().String()) | ||
| assert.NotContains(t, text, upstreamAddr) | ||
|
|
||
| wg.Done() | ||
| } | ||
|
|
@@ -655,12 +656,12 @@ func TestPrometheusConnectionGroupingUsesStructuredKey(t *testing.T) { | |
|
|
||
| first := &ConnInfo{Index: 1, ConnectedAt: time.Unix(100, 0)} | ||
| first.Module = "a\xffb" | ||
| first.UpstreamAddr = "c" | ||
| first.Upstream = "c" | ||
| srv.connInfo.Store(first.Index, first) | ||
|
|
||
| second := &ConnInfo{Index: 2, ConnectedAt: time.Unix(100, 0)} | ||
| second.Module = "a" | ||
| second.UpstreamAddr = "b\xffc" | ||
| second.Upstream = "b\xffc" | ||
| srv.connInfo.Store(second.Index, second) | ||
|
|
||
| var buf bytes.Buffer | ||
|
|
@@ -676,7 +677,7 @@ func TestPrometheusDurationIncludesFractionalSeconds(t *testing.T) { | |
| srv := New() | ||
| conn := &ConnInfo{Index: 1, ConnectedAt: time.Unix(100, 0)} | ||
| conn.Module = "fake" | ||
| conn.UpstreamAddr = "127.0.0.1:873" | ||
| conn.Upstream = "127.0.0.1:873" | ||
| srv.connInfo.Store(conn.Index, conn) | ||
|
|
||
| var buf bytes.Buffer | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个看起来会改变 rsync-proxy connections 输出的表格内容,虽然我觉得问题不大
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个其实挺好的,我一直都想这么做