()
| 54 | } |
| 55 | |
| 56 | func ExampleAPI_queryRange() { |
| 57 | client, err := api.NewClient(api.Config{ |
| 58 | Address: DemoPrometheusURL, |
| 59 | }) |
| 60 | if err != nil { |
| 61 | fmt.Printf("Error creating client: %v\n", err) |
| 62 | os.Exit(1) |
| 63 | } |
| 64 | |
| 65 | v1api := v1.NewAPI(client) |
| 66 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
| 67 | defer cancel() |
| 68 | r := v1.Range{ |
| 69 | Start: time.Now().Add(-time.Hour), |
| 70 | End: time.Now(), |
| 71 | Step: time.Minute, |
| 72 | } |
| 73 | result, warnings, err := v1api.QueryRange(ctx, "rate(prometheus_tsdb_head_samples_appended_total[5m])", r, v1.WithTimeout(5*time.Second)) |
| 74 | if err != nil { |
| 75 | fmt.Printf("Error querying Prometheus: %v\n", err) |
| 76 | os.Exit(1) |
| 77 | } |
| 78 | if len(warnings) > 0 { |
| 79 | fmt.Printf("Warnings: %v\n", warnings) |
| 80 | } |
| 81 | fmt.Printf("Result:\n%v\n", result) |
| 82 | } |
| 83 | |
| 84 | type userAgentRoundTripper struct { |
| 85 | name string |
nothing calls this directly
no test coverage detected