@@ -38,24 +38,36 @@ var bufferPool = sync.Pool{New: func() interface{} {
38
38
39
39
type ApmServerTransportStatusType string
40
40
41
+ // Constants for the state of the transport used in
42
+ // the backoff implementation.
41
43
const (
42
44
Failing ApmServerTransportStatusType = "Failing"
43
45
Pending ApmServerTransportStatusType = "Pending"
44
46
Healthy ApmServerTransportStatusType = "Healthy"
45
47
)
46
48
49
+ // A struct to track the state and status of sending
50
+ // to the APM server. Used in the backoff implementation.
47
51
type ApmServerTransportStateType struct {
48
52
sync.Mutex
49
53
Status ApmServerTransportStatusType
50
54
ReconnectionCount int
51
55
GracePeriodTimer * time.Timer
52
56
}
53
57
58
+ // The status of transport to the APM server.
59
+ //
60
+ // This instance of the ApmServerTransportStateType is public for use in tests.
54
61
var ApmServerTransportState = ApmServerTransportStateType {
55
62
Status : Healthy ,
56
63
ReconnectionCount : - 1 ,
57
64
}
58
65
66
+ // PostToApmServer takes a chunk of APM agent data and posts it to the APM server.
67
+ //
68
+ // The function compresses the APM agent data, if it's not already compressed.
69
+ // It sets the APM transport status to failing upon errors, as part of the backoff
70
+ // strategy.
59
71
func PostToApmServer (client * http.Client , agentData AgentData , config * extensionConfig , ctx context.Context ) error {
60
72
// todo: can this be a streaming or streaming style call that keeps the
61
73
// connection open across invocations?
@@ -123,10 +135,21 @@ func PostToApmServer(client *http.Client, agentData AgentData, config *extension
123
135
return nil
124
136
}
125
137
138
+ // IsTransportStatusHealthyOrPending returns true if the APM server transport status is
139
+ // healthy or pending, and false otherwise.
140
+ //
141
+ // This function is public for use in tests.
126
142
func IsTransportStatusHealthyOrPending () bool {
127
143
return ApmServerTransportState .Status != Failing
128
144
}
129
145
146
+ // SetApmServerTransportState takes a state of the APM server transport and updates
147
+ // the current state of the transport. For a change to a failing state, the grace period
148
+ // is calculated and a go routine is started that waits for that period to complete
149
+ // before changing the status to "pending". This would allow a subsequent send attempt
150
+ // to the APM server.
151
+ //
152
+ // This function is public for use in tests.
130
153
func SetApmServerTransportState (status ApmServerTransportStatusType , ctx context.Context ) {
131
154
switch status {
132
155
case Healthy :
@@ -165,6 +188,8 @@ func computeGracePeriod() time.Duration {
165
188
return time .Duration ((gracePeriodWithoutJitter + jitter * gracePeriodWithoutJitter ) * float64 (time .Second ))
166
189
}
167
190
191
+ // EnqueueAPMData adds a AgentData struct to the agent data channel, effectively queueing for a send
192
+ // to the APM server.
168
193
func EnqueueAPMData (agentDataChannel chan AgentData , agentData AgentData ) {
169
194
select {
170
195
case agentDataChannel <- agentData :
0 commit comments