Chore: Use response limit middleware from SDK (#83915)

This commit is contained in:
Andres Martinez Gotor
2024-03-13 10:14:16 +01:00
committed by GitHub
parent ecd6de826a
commit c061cc33cc
12 changed files with 28 additions and 201 deletions

View File

@@ -0,0 +1,15 @@
package datasource
import (
"context"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
)
func contextualMiddlewares(ctx context.Context) context.Context {
cfg := backend.GrafanaConfigFromContext(ctx)
m := httpclient.ResponseLimitMiddleware(cfg.ResponseLimit())
return httpclient.WithContextualMiddleware(ctx, m)
}

View File

@@ -50,6 +50,7 @@ func (r *subHealthREST) Connect(ctx context.Context, name string, opts runtime.O
return nil, err
}
ctx = backend.WithGrafanaConfig(ctx, pluginCtx.GrafanaConfig)
ctx = contextualMiddlewares(ctx)
healthResponse, err := r.builder.client.CheckHealth(ctx, &backend.CheckHealthRequest{
PluginContext: pluginCtx,

View File

@@ -72,6 +72,7 @@ func (r *subQueryREST) Connect(ctx context.Context, name string, opts runtime.Ob
}
ctx = backend.WithGrafanaConfig(ctx, pluginCtx.GrafanaConfig)
ctx = contextualMiddlewares(ctx)
rsp, err := r.builder.client.QueryData(ctx, &backend.QueryDataRequest{
Queries: queries,
PluginContext: pluginCtx,

View File

@@ -51,6 +51,7 @@ func (r *subResourceREST) Connect(ctx context.Context, name string, opts runtime
return nil, err
}
ctx = backend.WithGrafanaConfig(ctx, pluginCtx.GrafanaConfig)
ctx = contextualMiddlewares(ctx)
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
body, err := io.ReadAll(req.Body)