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