Skip to content

Commit

Permalink
Merge branch 'main' into dbstatscollectorexample
Browse files Browse the repository at this point in the history
  • Loading branch information
Manask322 authored Oct 21, 2024
2 parents 7158b92 + aef8aed commit e83e3b0
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 e83e3b0

Please sign in to comment.