MCPcopy Create free account
hub / github.com/efficientgo/e2e / AsInstrumented

Function AsInstrumented

monitoring/instrumented.go:87–120  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
87func 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
122func (r *InstrumentedRunnable) MetricTargets() []Target {
123 return []Target{{Scheme: r.scheme, MetricPath: r.metricPath, InternalEndpoint: r.InternalEndpoint(r.metricPortName)}}

Callers 4

NewPrometheusFunction · 0.85
newCadvisorFunction · 0.85
TestWaitSumMetricFunction · 0.85
TestWaitSumMetric_NanFunction · 0.85

Calls 6

NewFailedRunnableFunction · 0.92
InstrumentedInterface · 0.85
IsRunningMethod · 0.65
InternalEndpointMethod · 0.65
NameMethod · 0.65
SetMetadataMethod · 0.65

Tested by 2

TestWaitSumMetricFunction · 0.68
TestWaitSumMetric_NanFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…