develop: 补齐 agent 上报 HTTP 常量并修复测试编译
This commit is contained in:
parent
fb9ff25563
commit
26e56fb2e8
@ -35,9 +35,7 @@ type Reporter struct {
|
||||
// NewReporter 创建上报客户端。
|
||||
func NewReporter(gatewayURL, agentToken, hostID, agentVersion string) *Reporter {
|
||||
return &Reporter{
|
||||
client: &http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
},
|
||||
client: &http.Client{Timeout: 10 * time.Second},
|
||||
gatewayURL: gatewayURL,
|
||||
agentToken: agentToken,
|
||||
hostID: hostID,
|
||||
@ -49,11 +47,7 @@ func NewReporter(gatewayURL, agentToken, hostID, agentVersion string) *Reporter
|
||||
|
||||
// Heartbeat 发送心跳,返回服务端时间与下发配置。
|
||||
func (r *Reporter) Heartbeat(ctx context.Context, configVersion int64) (*collectorpb.HeartbeatResponse, error) {
|
||||
req := &collectorpb.HeartbeatRequest{
|
||||
HostId: r.hostID,
|
||||
AgentVersion: r.agentVersion,
|
||||
ConfigVersion: configVersion,
|
||||
}
|
||||
req := &collectorpb.HeartbeatRequest{HostId: r.hostID, AgentVersion: r.agentVersion, ConfigVersion: configVersion}
|
||||
out := &collectorpb.HeartbeatResponse{}
|
||||
if err := r.sendWithRetry(ctx, "/v1/agent/heartbeat", req, out); err != nil {
|
||||
return nil, err
|
||||
@ -93,7 +87,6 @@ func (r *Reporter) sendWithRetry(ctx context.Context, path string, req proto.Mes
|
||||
case <-time.After(backoff):
|
||||
}
|
||||
}
|
||||
|
||||
err := r.post(ctx, path, req, out)
|
||||
if err == nil {
|
||||
if ack, ok := out.(*collectorpb.Ack); ok && !ack.Ok {
|
||||
@ -112,7 +105,6 @@ func (r *Reporter) post(ctx context.Context, path string, req proto.Message, out
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal request: %w", err)
|
||||
}
|
||||
|
||||
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, r.gatewayURL+path, bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return fmt.Errorf("new request: %w", err)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user