Skip to content
Merged
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
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