AsInstrumented wraps e2e.Runnable with InstrumentedRunnable. If runnable is running during invocation AsInstrumented panics. NOTE(bwplotka): Caller is expected to discard passed `r` runnable and use returned InstrumentedRunnable.Runnable instead.
(r e2e.Runnable, instrumentedPortName string, opts ...InstrumentedOption)
| 85 | // If runnable is running during invocation AsInstrumented panics. |
| 86 | // NOTE(bwplotka): Caller is expected to discard passed `r` runnable and use returned InstrumentedRunnable.Runnable instead. |
| 87 | func AsInstrumented(r e2e.Runnable, instrumentedPortName string, opts ...InstrumentedOption) *InstrumentedRunnable { |
| 88 | if r.IsRunning() { |
| 89 | panic("can't use AsInstrumented with running runnable") |
| 90 | } |
| 91 | |
| 92 | opt := rOpt{ |
| 93 | metricPath: "/metrics", |
| 94 | scheme: "http", |
| 95 | waitBackoff: backoff.New(context.Background(), backoff.Config{ |
| 96 | Min: 300 * time.Millisecond, |
| 97 | Max: 600 * time.Millisecond, |
| 98 | MaxRetries: 50, // Sometimes the CI is slow ¯\_(ツ)_/¯ |
| 99 | })} |
| 100 | for _, o := range opts { |
| 101 | o(&opt) |
| 102 | } |
| 103 | |
| 104 | if r.InternalEndpoint(instrumentedPortName) == "" { |
| 105 | return &InstrumentedRunnable{Runnable: e2e.NewFailedRunnable( |
| 106 | r.Name(), |
| 107 | errors.Newf("metric port name %v does not exists in given runnable ports", instrumentedPortName)), |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | instr := &InstrumentedRunnable{ |
| 112 | Runnable: r, |
| 113 | metricPortName: instrumentedPortName, |
| 114 | metricPath: opt.metricPath, |
| 115 | scheme: opt.scheme, |
| 116 | waitBackoff: opt.waitBackoff, |
| 117 | } |
| 118 | r.SetMetadata(metaKey, Instrumented(instr)) |
| 119 | return instr |
| 120 | } |
| 121 | |
| 122 | func (r *InstrumentedRunnable) MetricTargets() []Target { |
| 123 | return []Target{{Scheme: r.scheme, MetricPath: r.metricPath, InternalEndpoint: r.InternalEndpoint(r.metricPortName)}} |
searching dependent graphs…