Skip to content

Commit dcc729e

Browse files
committed
Cache engines in query.remoteEndpoints to preserve evaluated MinT / MaxT / LabelSets between .Engines() calls
Signed-off-by: Aleksandr Krivoshchekov <SuperPaintmanDeveloper@gmail.com>
1 parent 5a0cbf8 commit dcc729e

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

pkg/query/remote_engine.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,30 @@ type remoteEndpoints struct {
9595
logger log.Logger
9696
getClients func() []Client
9797
opts Opts
98+
99+
enginesOnce sync.Once
100+
engines []api.RemoteEngine
98101
}
99102

100103
func NewRemoteEndpoints(logger log.Logger, getClients func() []Client, opts Opts) api.RemoteEndpoints {
101-
return remoteEndpoints{
104+
return &remoteEndpoints{
102105
logger: logger,
103106
getClients: getClients,
104107
opts: opts,
105108
}
106109
}
107110

108-
func (r remoteEndpoints) Engines() []api.RemoteEngine {
109-
clients := r.getClients()
110-
engines := make([]api.RemoteEngine, len(clients))
111-
for i := range clients {
112-
engines[i] = NewRemoteEngine(r.logger, clients[i], r.opts)
113-
}
114-
return engines
111+
func (r *remoteEndpoints) Engines() []api.RemoteEngine {
112+
r.enginesOnce.Do(func() {
113+
clients := r.getClients()
114+
engines := make([]api.RemoteEngine, len(clients))
115+
for i := range clients {
116+
engines[i] = NewRemoteEngine(r.logger, clients[i], r.opts)
117+
}
118+
119+
r.engines = engines
120+
})
121+
return r.engines
115122
}
116123

117124
type remoteEngine struct {

0 commit comments

Comments
 (0)