develop: 补齐 agent 上报 HTTP 常量并修复测试编译
This commit is contained in:
parent
4f3e335f28
commit
fb9ff25563
@ -13,6 +13,13 @@ import (
|
||||
"git.opencomputing.cn/yumoqing/host-metrics-collector/pkg/collectorpb"
|
||||
)
|
||||
|
||||
// Agent 上报使用的 HTTP 头与内容类型,与 gateway 包及测试保持一致。
|
||||
const (
|
||||
headerAgentToken = "X-Agent-Token"
|
||||
headerHostID = "X-Host-Id"
|
||||
contentTypeProtobuf = "application/x-protobuf"
|
||||
)
|
||||
|
||||
// Reporter 负责通过 HTTP/protobuf 向 Collector Gateway(4318)上报数据。
|
||||
type Reporter struct {
|
||||
client *http.Client
|
||||
@ -110,9 +117,9 @@ func (r *Reporter) post(ctx context.Context, path string, req proto.Message, out
|
||||
if err != nil {
|
||||
return fmt.Errorf("new request: %w", err)
|
||||
}
|
||||
httpReq.Header.Set("Content-Type", "application/x-protobuf")
|
||||
httpReq.Header.Set("X-Agent-Token", r.agentToken)
|
||||
httpReq.Header.Set("X-Host-Id", r.hostID)
|
||||
httpReq.Header.Set("Content-Type", contentTypeProtobuf)
|
||||
httpReq.Header.Set(headerAgentToken, r.agentToken)
|
||||
httpReq.Header.Set(headerHostID, r.hostID)
|
||||
|
||||
resp, err := r.client.Do(httpReq)
|
||||
if err != nil {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user