Elasticsearch: use application/x-ndjson content type for multisearch requests (#32282)

This commit is contained in:
Giordano Ricci 2021-03-29 23:41:45 +01:00 committed by GitHub
parent 56159a1c43
commit f7b408f99f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 8 deletions

View File

@ -184,7 +184,7 @@ func (c *baseClientImpl) executeRequest(method, uriPath, uriQuery string, body [
} }
req.Header.Set("User-Agent", "Grafana") req.Header.Set("User-Agent", "Grafana")
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/x-ndjson")
if c.ds.BasicAuth { if c.ds.BasicAuth {
clientLog.Debug("Request configured to use basic authentication") clientLog.Debug("Request configured to use basic authentication")

View File

@ -366,7 +366,7 @@ func httpClientScenario(t *testing.T, desc string, ds *models.DataSource, fn sce
sc.requestBody = bytes.NewBuffer(buf) sc.requestBody = bytes.NewBuffer(buf)
rw.Header().Set("Content-Type", "application/json") rw.Header().Set("Content-Type", "application/x-ndjson")
_, err = rw.Write([]byte(sc.responseBody)) _, err = rw.Write([]byte(sc.responseBody))
require.NoError(t, err) require.NoError(t, err)
rw.WriteHeader(sc.responseStatus) rw.WriteHeader(sc.responseStatus)

View File

@ -23,7 +23,7 @@ import { ElasticResponse } from './elastic_response';
import { IndexPattern } from './index_pattern'; import { IndexPattern } from './index_pattern';
import { ElasticQueryBuilder } from './query_builder'; import { ElasticQueryBuilder } from './query_builder';
import { defaultBucketAgg, hasMetricOfType } from './query_def'; import { defaultBucketAgg, hasMetricOfType } from './query_def';
import { getBackendSrv, getDataSourceSrv } from '@grafana/runtime'; import { BackendSrvRequest, getBackendSrv, getDataSourceSrv } from '@grafana/runtime';
import { getTemplateSrv, TemplateSrv } from 'app/features/templating/template_srv'; import { getTemplateSrv, TemplateSrv } from 'app/features/templating/template_srv';
import { DataLinkConfig, ElasticsearchOptions, ElasticsearchQuery } from './types'; import { DataLinkConfig, ElasticsearchOptions, ElasticsearchQuery } from './types';
import { RowContextOptions } from '@grafana/ui/src/components/Logs/LogRowContextProvider'; import { RowContextOptions } from '@grafana/ui/src/components/Logs/LogRowContextProvider';
@ -104,11 +104,17 @@ export class ElasticDatasource extends DataSourceApi<ElasticsearchQuery, Elastic
this.languageProvider = new LanguageProvider(this); this.languageProvider = new LanguageProvider(this);
} }
private request(method: string, url: string, data?: undefined): Observable<any> { private request(
const options: any = { method: string,
url: string,
data?: undefined,
headers?: BackendSrvRequest['headers']
): Observable<any> {
const options: BackendSrvRequest = {
url: this.url + '/' + url, url: this.url + '/' + url,
method: method, method,
data: data, data,
headers,
}; };
if (this.basicAuth || this.withCredentials) { if (this.basicAuth || this.withCredentials) {
@ -192,7 +198,7 @@ export class ElasticDatasource extends DataSourceApi<ElasticsearchQuery, Elastic
} }
private post(url: string, data: any): Observable<any> { private post(url: string, data: any): Observable<any> {
return this.request('POST', url, data); return this.request('POST', url, data, { 'Content-Type': 'application/x-ndjson' });
} }
annotationQuery(options: any): Promise<any> { annotationQuery(options: any): Promise<any> {