Elasticsearch: Use _field_caps instead of _mapping to get fields (#97607)
This commit is contained in:
@@ -1676,6 +1676,12 @@ var (
|
||||
Owner: grafanaOperatorExperienceSquad,
|
||||
HideFromDocs: true,
|
||||
},
|
||||
{
|
||||
Name: "elasticsearchCrossClusterSearch",
|
||||
Description: "Enables cross cluster search in the Elasticsearch datasource",
|
||||
Stage: FeatureStagePublicPreview,
|
||||
Owner: awsDatasourcesSquad,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -223,3 +223,4 @@ alertingUIOptimizeReducer,GA,@grafana/alerting-squad,false,false,true
|
||||
azureMonitorEnableUserAuth,GA,@grafana/partner-datasources,false,false,false
|
||||
alertingNotificationsStepMode,experimental,@grafana/alerting-squad,false,false,true
|
||||
feedbackButton,experimental,@grafana/grafana-operator-experience-squad,false,false,false
|
||||
elasticsearchCrossClusterSearch,preview,@grafana/aws-datasources,false,false,false
|
||||
|
||||
|
@@ -902,4 +902,8 @@ const (
|
||||
// FlagFeedbackButton
|
||||
// Enables a button to send feedback from the Grafana UI
|
||||
FlagFeedbackButton = "feedbackButton"
|
||||
|
||||
// FlagElasticsearchCrossClusterSearch
|
||||
// Enables cross cluster search in the Elasticsearch datasource
|
||||
FlagElasticsearchCrossClusterSearch = "elasticsearchCrossClusterSearch"
|
||||
)
|
||||
|
||||
@@ -1269,6 +1269,21 @@
|
||||
"frontend": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"name": "elasticsearchCrossClusterSearch",
|
||||
"resourceVersion": "1733848475752",
|
||||
"creationTimestamp": "2024-12-09T13:53:38Z",
|
||||
"annotations": {
|
||||
"grafana.app/updatedTimestamp": "2024-12-10 16:34:35.752111 +0000 UTC"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"description": "Enables cross cluster search in the Elasticsearch datasource",
|
||||
"stage": "preview",
|
||||
"codeowner": "@grafana/aws-datasources"
|
||||
}
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"name": "enableDatagridEditing",
|
||||
|
||||
@@ -182,14 +182,21 @@ func (s *Service) getDSInfo(ctx context.Context, pluginCtx backend.PluginContext
|
||||
return &instance, nil
|
||||
}
|
||||
|
||||
func isFieldCaps(url string) bool {
|
||||
return strings.HasSuffix(url, "/_field_caps") || url == "_field_caps"
|
||||
}
|
||||
|
||||
func (s *Service) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
||||
logger := s.logger.FromContext(ctx)
|
||||
// allowed paths for resource calls:
|
||||
// - empty string for fetching db version
|
||||
// - /_mapping for fetching index mapping, e.g. requests going to `index/_mapping`
|
||||
// - /_field_caps for fetching field capabilities, e.g. requests going to `index/_field_caps`
|
||||
// - _msearch for executing getTerms queries
|
||||
// - _mapping for fetching "root" index mappings
|
||||
if req.Path != "" && !strings.HasSuffix(req.Path, "/_mapping") && req.Path != "_msearch" && req.Path != "_mapping" {
|
||||
// - _field_caps for fetching "root" field capabilities
|
||||
if req.Path != "" && !isFieldCaps(req.Path) && req.Path != "_msearch" &&
|
||||
!strings.HasSuffix(req.Path, "/_mapping") && req.Path != "_mapping" {
|
||||
logger.Error("Invalid resource path", "path", req.Path)
|
||||
return fmt.Errorf("invalid resource URL: %s", req.Path)
|
||||
}
|
||||
@@ -266,6 +273,9 @@ func createElasticsearchURL(req *backend.CallResourceRequest, ds *es.DatasourceI
|
||||
}
|
||||
|
||||
esUrl.Path = path.Join(esUrl.Path, req.Path)
|
||||
if isFieldCaps(req.Path) {
|
||||
esUrl.RawQuery = "fields=*"
|
||||
}
|
||||
esUrlString := esUrl.String()
|
||||
// If the request path is empty and the URL does not end with a slash, add a slash to the URL.
|
||||
// This ensures that for version checks executed to the root URL, the URL ends with a slash.
|
||||
|
||||
Reference in New Issue
Block a user