mirror of
https://github.com/grafana/grafana.git
synced 2025-07-28 10:52:17 +08:00
Caching: Consolidate resource cache checking and updating in plugin middleware (#67002)
* Update the HandleResourceRequest function to mimic the HandleQueryRequest function * Remove CacheResourceResponse function from interface * revert additional thing I missed
This commit is contained in:
@ -15,7 +15,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/util/proxyutil"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@ -130,7 +129,7 @@ func (hs *HTTPServer) makePluginResourceRequest(w http.ResponseWriter, req *http
|
||||
|
||||
var flushStreamErr error
|
||||
go func() {
|
||||
flushStreamErr = hs.flushStream(req.Context(), crReq, stream, w)
|
||||
flushStreamErr = hs.flushStream(stream, w)
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
@ -141,10 +140,8 @@ func (hs *HTTPServer) makePluginResourceRequest(w http.ResponseWriter, req *http
|
||||
return flushStreamErr
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) flushStream(ctx context.Context, req *backend.CallResourceRequest, stream callResourceClientResponseStream, w http.ResponseWriter) error {
|
||||
func (hs *HTTPServer) flushStream(stream callResourceClientResponseStream, w http.ResponseWriter) error {
|
||||
processedStreams := 0
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
for {
|
||||
resp, err := stream.Recv()
|
||||
if errors.Is(err, io.EOF) {
|
||||
@ -200,12 +197,6 @@ func (hs *HTTPServer) flushStream(ctx context.Context, req *backend.CallResource
|
||||
|
||||
if _, err := w.Write(resp.Body); err != nil {
|
||||
hs.log.Error("Failed to write resource response", "err", err)
|
||||
} else if hs.Features.IsEnabled(featuremgmt.FlagUseCachingService) {
|
||||
// Placing the new service implementation behind a feature flag until it is known to be stable
|
||||
|
||||
// The enterprise implementation of this function will use the headers and status of the first response,
|
||||
// And append the body of any subsequent responses. It waits for the context to be canceled before caching the cumulative result.
|
||||
hs.cachingService.CacheResourceResponse(ctx, req, resp)
|
||||
}
|
||||
|
||||
if flusher, ok := w.(http.Flusher); ok {
|
||||
|
Reference in New Issue
Block a user