From fb9ff2556336366422d69ad296e651017864ce74 Mon Sep 17 00:00:00 2001 From: Pipeline Agent Date: Sat, 15 Aug 2026 11:32:02 +0800 Subject: [PATCH] =?UTF-8?q?develop:=20=E8=A1=A5=E9=BD=90=20agent=20?= =?UTF-8?q?=E4=B8=8A=E6=8A=A5=20HTTP=20=E5=B8=B8=E9=87=8F=E5=B9=B6?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/agent/reporter.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/agent/reporter.go b/internal/agent/reporter.go index f1b71a1..05285e5 100644 --- a/internal/agent/reporter.go +++ b/internal/agent/reporter.go @@ -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 {