Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Add http request meta information to elasticsearch exporter for service management. #877

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
18 changes: 16 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -163,8 +175,10 @@ func main() {
}

httpClient := &http.Client{
Timeout: *esTimeout,
Transport: httpTransport,
Timeout: *esTimeout,
Transport: &withDefaultHeader{
rt: httpTransport,
},
}

if *awsRegion != "" {
Expand Down