mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-16 03:31:39 +00:00
net/tstun: rename statististics method (#5852)
Rename StatisticsEnable as SetStatisticsEnabled to be consistent with other similarly named methods. Rename StatisticsExtract as ExtractStatistics to follow the convention where methods start with a verb. It was originally named with Statistics as a prefix so that statistics related methods would sort well in godoc, but that property no longer holds. Signed-off-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
parent
dd045a3767
commit
84e8f25c21
@ -843,15 +843,15 @@ func (t *Wrapper) Unwrap() tun.Device {
|
|||||||
return t.tdev
|
return t.tdev
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatisticsEnable enables per-connections packet counters.
|
// SetStatisticsEnabled enables per-connections packet counters.
|
||||||
// StatisticsExtract must be called periodically to avoid unbounded memory use.
|
// ExtractStatistics must be called periodically to avoid unbounded memory use.
|
||||||
func (t *Wrapper) StatisticsEnable(enable bool) {
|
func (t *Wrapper) SetStatisticsEnabled(enable bool) {
|
||||||
t.stats.enabled.Store(enable)
|
t.stats.enabled.Store(enable)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatisticsExtract extracts and resets the counters for all active connections.
|
// ExtractStatistics extracts and resets the counters for all active connections.
|
||||||
// It must be called periodically otherwise the memory used is unbounded.
|
// It must be called periodically otherwise the memory used is unbounded.
|
||||||
func (t *Wrapper) StatisticsExtract() map[flowtrack.Tuple]tunstats.Counts {
|
func (t *Wrapper) ExtractStatistics() map[flowtrack.Tuple]tunstats.Counts {
|
||||||
return t.stats.Extract()
|
return t.stats.Extract()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,8 +286,8 @@ func TestWriteAndInject(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Statistics gathering is disabled by default.
|
// Statistics gathering is disabled by default.
|
||||||
if stats := tun.StatisticsExtract(); len(stats) > 0 {
|
if stats := tun.ExtractStatistics(); len(stats) > 0 {
|
||||||
t.Errorf("tun.StatisticsExtract = %v, want {}", stats)
|
t.Errorf("tun.ExtractStatistics = %v, want {}", stats)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,15 +337,15 @@ func TestFilter(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
var buf [MaxPacketSize]byte
|
var buf [MaxPacketSize]byte
|
||||||
tun.StatisticsEnable(true)
|
tun.SetStatisticsEnabled(true)
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
var n int
|
var n int
|
||||||
var err error
|
var err error
|
||||||
var filtered bool
|
var filtered bool
|
||||||
|
|
||||||
if stats := tun.StatisticsExtract(); len(stats) > 0 {
|
if stats := tun.ExtractStatistics(); len(stats) > 0 {
|
||||||
t.Errorf("tun.StatisticsExtract = %v, want {}", stats)
|
t.Errorf("tun.ExtractStatistics = %v, want {}", stats)
|
||||||
}
|
}
|
||||||
|
|
||||||
if tt.dir == in {
|
if tt.dir == in {
|
||||||
@ -378,7 +378,7 @@ func TestFilter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
got := tun.StatisticsExtract()
|
got := tun.ExtractStatistics()
|
||||||
want := map[flowtrack.Tuple]tunstats.Counts{}
|
want := map[flowtrack.Tuple]tunstats.Counts{}
|
||||||
if !tt.drop {
|
if !tt.drop {
|
||||||
var p packet.Parsed
|
var p packet.Parsed
|
||||||
@ -393,7 +393,7 @@ func TestFilter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(got, want) {
|
if !reflect.DeepEqual(got, want) {
|
||||||
t.Errorf("tun.StatisticsExtract = %v, want %v", got, want)
|
t.Errorf("tun.ExtractStatistics = %v, want %v", got, want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user