From 04ffefb6637bb42f3a2e007f4a3ae0999444cc70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?RickyLau=28=E5=88=98=E5=B8=85=29?= Date: Thu, 28 Mar 2024 14:36:48 +0800 Subject: [PATCH] =?UTF-8?q?[Feat]=20=E4=B8=BAelasticsearch=20exporter=20?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=AF=B7=E6=B1=82=E6=96=B0=E5=A2=9E=E6=BA=90?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E8=AF=B7=E6=B1=82=E5=A4=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 1 + go.sum | 2 ++ main.go | 18 ++++++++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index c6c22577..0079fa8a 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/sts v1.28.4 github.com/blang/semver/v4 v4.0.0 github.com/go-kit/log v0.2.1 + github.com/google/uuid v1.6.0 github.com/imdario/mergo v0.3.13 github.com/prometheus/client_golang v1.18.0 github.com/prometheus/common v0.46.0 diff --git a/go.sum b/go.sum index 49adcf43..f6625a8d 100644 --- a/go.sum +++ b/go.sum @@ -50,6 +50,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= diff --git a/main.go b/main.go index 5e4c6da0..bb15dc54 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ import ( "github.com/alecthomas/kingpin/v2" "github.com/go-kit/log/level" + "github.com/google/uuid" "github.com/prometheus-community/elasticsearch_exporter/collector" "github.com/prometheus-community/elasticsearch_exporter/pkg/clusterinfo" "github.com/prometheus-community/elasticsearch_exporter/pkg/roundtripper" @@ -37,6 +38,17 @@ import ( const name = "elasticsearch_exporter" +type withDefaultHeader struct { + rt http.RoundTripper +} + +func (h *withDefaultHeader) RoundTrip(req *http.Request) (*http.Response, error) { + req.Header.Add("X-Opaque-Id", uuid.New().String()) + req.Header.Add("x-request-path", "/o11y/prometheus/es_exporter") + req.Header.Add("x-request-from-head-app-name", "elasticsearch_exporter") + return h.rt.RoundTrip(req) +} + type transportWithAPIKey struct { underlyingTransport http.RoundTripper apiKey string @@ -163,8 +175,10 @@ func main() { } httpClient := &http.Client{ - Timeout: *esTimeout, - Transport: httpTransport, + Timeout: *esTimeout, + Transport: &withDefaultHeader{ + rt: httpTransport, + }, } if *awsRegion != "" {