NewRunner makes a new Runner.
(cfg RunnerConfig)
| 80 | |
| 81 | // NewRunner makes a new Runner. |
| 82 | func NewRunner(cfg RunnerConfig) (*Runner, error) { |
| 83 | apiCfg := api.Config{ |
| 84 | Address: cfg.PrometheusAddr, |
| 85 | } |
| 86 | if cfg.UserID != "" { |
| 87 | apiCfg.RoundTripper = &nethttp.Transport{ |
| 88 | RoundTripper: promhttp.RoundTripperFunc(func(req *http.Request) (*http.Response, error) { |
| 89 | _ = user.InjectOrgIDIntoHTTPRequest(user.InjectOrgID(context.Background(), cfg.UserID), req) |
| 90 | return api.DefaultRoundTripper.RoundTrip(req) |
| 91 | }), |
| 92 | } |
| 93 | } else { |
| 94 | apiCfg.RoundTripper = &nethttp.Transport{} |
| 95 | } |
| 96 | |
| 97 | client, err := api.NewClient(apiCfg) |
| 98 | if err != nil { |
| 99 | return nil, err |
| 100 | } |
| 101 | |
| 102 | tc := &Runner{ |
| 103 | cfg: cfg, |
| 104 | quit: make(chan struct{}), |
| 105 | client: v1.NewAPI(tracingClient{client}), |
| 106 | } |
| 107 | |
| 108 | tc.wg.Add(1) |
| 109 | go tc.verifyLoop() |
| 110 | return tc, nil |
| 111 | } |
| 112 | |
| 113 | type tracingClient struct { |
| 114 | api.Client |
no test coverage detected