Prometheus: Browser resource caching (#60711)
Add cache control headers and range snapping to Prometheus resource API calls.
This commit is contained in:
@@ -438,6 +438,13 @@ var (
|
||||
FrontendOnly: true,
|
||||
Owner: appO11ySquad,
|
||||
},
|
||||
{
|
||||
Name: "prometheusResourceBrowserCache",
|
||||
Description: "Displays browser caching options in Prometheus data source configuration",
|
||||
State: FeatureStateAlpha,
|
||||
FrontendOnly: true,
|
||||
Owner: grafanaObservabilityMetricsSquad,
|
||||
},
|
||||
{
|
||||
Name: "influxdbBackendMigration",
|
||||
Description: "Query InfluxDB InfluxQL without the proxy",
|
||||
|
||||
@@ -64,6 +64,7 @@ drawerDataSourcePicker,alpha,@grafana/grafana-bi-squad,false,false,false,true
|
||||
traceqlSearch,alpha,@grafana/observability-traces-and-profiling,false,false,false,true
|
||||
prometheusMetricEncyclopedia,alpha,@grafana/observability-metrics,false,false,false,true
|
||||
timeSeriesTable,alpha,@grafana/app-o11y,false,false,false,true
|
||||
prometheusResourceBrowserCache,alpha,@grafana/observability-metrics,false,false,false,true
|
||||
influxdbBackendMigration,alpha,@grafana/observability-metrics,false,false,false,true
|
||||
clientTokenRotation,alpha,@grafana/grafana-authnz-team,false,false,false,false
|
||||
disableElasticsearchBackendExploreQuery,beta,@grafana/observability-logs,false,false,false,false
|
||||
|
||||
|
@@ -267,6 +267,10 @@ const (
|
||||
// Enable time series table transformer & sparkline cell type
|
||||
FlagTimeSeriesTable = "timeSeriesTable"
|
||||
|
||||
// FlagPrometheusResourceBrowserCache
|
||||
// Displays browser caching options in Prometheus data source configuration
|
||||
FlagPrometheusResourceBrowserCache = "prometheusResourceBrowserCache"
|
||||
|
||||
// FlagInfluxdbBackendMigration
|
||||
// Query InfluxDB InfluxQL without the proxy
|
||||
FlagInfluxdbBackendMigration = "influxdbBackendMigration"
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/tsdb/prometheus/client"
|
||||
"github.com/grafana/grafana/pkg/tsdb/prometheus/utils"
|
||||
@@ -47,6 +46,12 @@ func (r *Resource) Execute(ctx context.Context, req *backend.CallResourceRequest
|
||||
return nil, fmt.Errorf("error querying resource: %v", err)
|
||||
}
|
||||
|
||||
// frontend sets the X-Grafana-Cache with the desired response cache control value
|
||||
if len(req.GetHTTPHeaders().Get("X-Grafana-Cache")) > 0 {
|
||||
resp.Header.Set("X-Grafana-Cache", "y")
|
||||
resp.Header.Set("Cache-Control", req.GetHTTPHeaders().Get("X-Grafana-Cache"))
|
||||
}
|
||||
|
||||
defer func() {
|
||||
tmpErr := resp.Body.Close()
|
||||
if tmpErr != nil && err == nil {
|
||||
|
||||
Reference in New Issue
Block a user