@@ -24,15 +24,15 @@ type statsCollector interface {
24
24
Collect (ctx context.Context , networkStats map [netlogtype.Connection ]netlogtype.Counts ) * proto.Stats
25
25
}
26
26
27
- type statsDest interface {
27
+ type statsAPI interface {
28
28
GetExperiments (ctx context.Context , req * proto.GetExperimentsRequest ) (* proto.GetExperimentsResponse , error )
29
29
UpdateStats (ctx context.Context , req * proto.UpdateStatsRequest ) (* proto.UpdateStatsResponse , error )
30
30
}
31
31
32
32
// statsReporter is a subcomponent of the agent that handles registering the stats callback on the
33
33
// networkStatsSource (tailnet.Conn in prod), handling the callback, calling back to the
34
34
// statsCollector (agent in prod) to collect additional stats, then sending the update to the
35
- // statsDest (agent API in prod)
35
+ // statsAPI (agent API in prod)
36
36
type statsReporter struct {
37
37
* sync.Cond
38
38
networkStats * map [netlogtype.Connection ]netlogtype.Counts
@@ -70,12 +70,14 @@ func (s *statsReporter) callback(_, _ time.Time, virtual, _ map[netlogtype.Conne
70
70
// connection to the agent API, then passes that connection to go routines like
71
71
// this that use it. There is no retry and we fail on the first error since
72
72
// this will be inside a larger retry loop.
73
- func (s * statsReporter ) reportLoop (ctx context.Context , dest statsDest ) error {
73
+ func (s * statsReporter ) reportLoop (ctx context.Context , dest statsAPI ) error {
74
74
exp , err := dest .GetExperiments (ctx , & proto.GetExperimentsRequest {})
75
75
if err != nil {
76
76
return xerrors .Errorf ("get experiments: %w" , err )
77
77
}
78
+ s .L .Lock ()
78
79
s .experiments = agentsdk .ExperimentsFromProto (exp )
80
+ s .L .Unlock ()
79
81
80
82
// send an initial, blank report to get the interval
81
83
resp , err := dest .UpdateStats (ctx , & proto.UpdateStatsRequest {})
@@ -115,7 +117,7 @@ func (s *statsReporter) reportLoop(ctx context.Context, dest statsDest) error {
115
117
}
116
118
117
119
func (s * statsReporter ) reportLocked (
118
- ctx context.Context , dest statsDest , networkStats map [netlogtype.Connection ]netlogtype.Counts ,
120
+ ctx context.Context , dest statsAPI , networkStats map [netlogtype.Connection ]netlogtype.Counts ,
119
121
) error {
120
122
// here we want to do our collecting/reporting while it is unlocked, but then relock
121
123
// when we return to reportLoop.
0 commit comments