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