Skip to content

Commit

Permalink
prom-to-sd: Fix not respecting --api-override
Browse files Browse the repository at this point in the history
  • Loading branch information
linxiulei committed Oct 17, 2024
1 parent 04cb65c commit 1419b31
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions prometheus-to-sd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,28 @@ func main() {
options = append(options, option.WithTokenSource(ts))
}

if *apioverride != "" {
// option.WithEndpoint() only works with "host:port"
u, err := url.Parse(*apioverride)
if err != nil {
glog.Fatalf("Failed to parse api override: %v", err)
}
port := u.Port()
if port == "" {
switch u.Scheme {
case "https":
port = "443"
case "http":
port = "80"
case "":
port = "80"
default:
glog.Fatalf("Unrecognized scheme: %s in --api-override", u.Scheme)
}
}
options = append(options, option.WithEndpoint(fmt.Sprintf("%s:%s", u.Host, port)))
}

ctx := context.Background()
client, err := monitoring.NewMetricClient(ctx, options...)
if err != nil {
Expand Down

0 comments on commit 1419b31

Please sign in to comment.