Prometheus: Browser resource caching (#60711)

Add cache control headers and range snapping to Prometheus resource API calls.
This commit is contained in:
Galen Kistler
2023-04-03 09:07:17 -05:00
committed by GitHub
parent 008bf143ac
commit 96e9e80739
27 changed files with 1033 additions and 212 deletions
+7
View File
@@ -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",
+1
View File
@@ -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
1 Name State Owner requiresDevMode RequiresLicense RequiresRestart FrontendOnly
64 traceqlSearch alpha @grafana/observability-traces-and-profiling false false false true
65 prometheusMetricEncyclopedia alpha @grafana/observability-metrics false false false true
66 timeSeriesTable alpha @grafana/app-o11y false false false true
67 prometheusResourceBrowserCache alpha @grafana/observability-metrics false false false true
68 influxdbBackendMigration alpha @grafana/observability-metrics false false false true
69 clientTokenRotation alpha @grafana/grafana-authnz-team false false false false
70 disableElasticsearchBackendExploreQuery beta @grafana/observability-logs false false false false
+4
View File
@@ -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"
+6 -1
View File
@@ -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 {