(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestExampleApp(t *testing.T) { |
| 20 | // Start a new Docker environment. |
| 21 | e, err := e2e.New() |
| 22 | // Make sure resources are cleaned up. |
| 23 | t.Cleanup(e.Close) |
| 24 | testutil.Ok(t, err) |
| 25 | |
| 26 | fmt.Println("=== Start example application...") |
| 27 | app := e2emon.AsInstrumented(e.Runnable("example_app"). |
| 28 | WithPorts(map[string]int{"http": 8080}). |
| 29 | Init(e2e.StartOptions{ |
| 30 | Image: "quay.io/brancz/prometheus-example-app:v0.3.0", |
| 31 | }), "http") |
| 32 | |
| 33 | testutil.Ok(t, e2e.StartAndWaitReady(app)) |
| 34 | |
| 35 | config := fmt.Sprintf(` |
| 36 | global: |
| 37 | external_labels: |
| 38 | prometheus: prometheus-example-app |
| 39 | scrape_configs: |
| 40 | - job_name: 'example-app' |
| 41 | scrape_interval: 1s |
| 42 | scrape_timeout: 1s |
| 43 | static_configs: |
| 44 | - targets: [%s] |
| 45 | relabel_configs: |
| 46 | - source_labels: ['__address__'] |
| 47 | regex: '^.+:80$' |
| 48 | action: drop |
| 49 | `, app.InternalEndpoint("http")) |
| 50 | |
| 51 | fmt.Println("=== Start Prometheus") |
| 52 | // Create Prometheus instance and wait for it to be ready. |
| 53 | p1 := e2edb.NewPrometheus(e, "prometheus-1") |
| 54 | testutil.Ok(t, p1.SetConfigEncoded([]byte(config))) |
| 55 | testutil.Ok(t, e2e.StartAndWaitReady(p1)) |
| 56 | |
| 57 | fmt.Println("=== Ensure that Prometheus already scraped something") |
| 58 | // Ensure that Prometheus already scraped something. |
| 59 | testutil.Ok(t, p1.WaitSumMetrics(e2emon.Greater(50), "prometheus_tsdb_head_samples_appended_total")) |
| 60 | |
| 61 | // Open example in browser. |
| 62 | exampleAppURL := fmt.Sprintf("http://%s", app.Endpoint("http")) |
| 63 | fmt.Printf("=== Example application URL: %s\n", exampleAppURL) |
| 64 | testutil.Ok(t, e2einteractive.OpenInBrowser(exampleAppURL)) |
| 65 | |
| 66 | fmt.Println("=== I need at least 5 requests!") |
| 67 | testutil.Ok(t, app.WaitSumMetricsWithOptions( |
| 68 | e2emon.GreaterOrEqual(5), |
| 69 | []string{"http_requests_total"}, |
| 70 | e2emon.WithWaitBackoff( |
| 71 | &backoff.Config{ |
| 72 | Min: 1 * time.Second, |
| 73 | Max: 10 * time.Second, |
| 74 | MaxRetries: 100, |
| 75 | }), |
| 76 | e2emon.WaitMissingMetrics()), |
nothing calls this directly
no test coverage detected
searching dependent graphs…