Skip to content

Commit

Permalink
test add headers round tripper
Browse files Browse the repository at this point in the history
Signed-off-by: manask322 <[email protected]>
Signed-off-by: Shivanth <[email protected]>
  • Loading branch information
Manask322 authored and shivanthzen committed Nov 3, 2024
1 parent 6641349 commit 6817e54
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions api/prometheus/v1/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,45 @@ func ExampleAPI_queryRangeWithAuthBearerToken() {
fmt.Printf("Result:\n%v\n", result)
}

func ExampleAPI_queryRangeWithAuthBearerTokenHeadersRoundTripper() {
client, err := api.NewClient(api.Config{
Address: "http://demo.robustperception.io:9090",
// We can use amazing github.com/prometheus/common/config helper!
RoundTripper: config.NewHeadersRoundTripper(
&config.Headers{
Headers: map[string]config.Header{
"Authorization": {
Values: []string{"Bearer secret"},
},
},
},
api.DefaultRoundTripper,
),
})
if err != nil {
fmt.Printf("Error creating client: %v\n", err)
os.Exit(1)
}

v1api := v1.NewAPI(client)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
r := v1.Range{
Start: time.Now().Add(-time.Hour),
End: time.Now(),
Step: time.Minute,
}
result, warnings, err := v1api.QueryRange(ctx, "rate(prometheus_tsdb_head_samples_appended_total[5m])", r)
if err != nil {
fmt.Printf("Error querying Prometheus: %v\n", err)
os.Exit(1)
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
}
fmt.Printf("Result:\n%v\n", result)
}

func ExampleAPI_series() {
client, err := api.NewClient(api.Config{
Address: "http://demo.robustperception.io:9090",
Expand Down

0 comments on commit 6817e54

Please sign in to comment.