diff --git a/public/app/plugins/datasource/prometheus/configuration/PromSettings.test.tsx b/public/app/plugins/datasource/prometheus/configuration/PromSettings.test.tsx
index 5953f0fc000..ae426979d3d 100644
--- a/public/app/plugins/datasource/prometheus/configuration/PromSettings.test.tsx
+++ b/public/app/plugins/datasource/prometheus/configuration/PromSettings.test.tsx
@@ -1,7 +1,9 @@
-import { getValueFromEventItem, promSettingsValidationEvents } from './PromSettings';
+import React, { SyntheticEvent } from 'react';
+import { render, screen } from '@testing-library/react';
import { EventsWithValidation } from '@grafana/ui';
-import { SyntheticEvent } from 'react';
import { SelectableValue } from '@grafana/data';
+import { getValueFromEventItem, promSettingsValidationEvents, PromSettings } from './PromSettings';
+import { createDefaultConfigOptions } from './mocks';
describe('PromSettings', () => {
describe('getValueFromEventItem', () => {
@@ -83,4 +85,56 @@ describe('PromSettings', () => {
}
);
});
+ describe('PromSettings component', () => {
+ const defaultProps = createDefaultConfigOptions();
+
+ it('should show POST httpMethod if no httpMethod and no url', () => {
+ const options = defaultProps;
+ options.url = '';
+ options.jsonData.httpMethod = '';
+
+ render(
+
+
{}} options={options} />
+
+ );
+ expect(screen.getByText('POST')).toBeInTheDocument();
+ });
+ it('should show GET httpMethod if no httpMethod and url', () => {
+ const options = defaultProps;
+ options.url = 'test_url';
+ options.jsonData.httpMethod = '';
+
+ render(
+
+
{}} options={options} />
+
+ );
+ expect(screen.getByText('GET')).toBeInTheDocument();
+ });
+ it('should show POST httpMethod if POST httpMethod is configured', () => {
+ const options = defaultProps;
+ options.url = 'test_url';
+ options.jsonData.httpMethod = 'POST';
+
+ render(
+
+
{}} options={options} />
+
+ );
+ expect(screen.getByText('POST')).toBeInTheDocument();
+ });
+ it('should show GET httpMethod if GET httpMethod is configured', () => {
+ const options = defaultProps;
+ options.url = 'test_url';
+ options.jsonData.httpMethod = 'GET';
+
+ render(
+
+
{}} options={options} />
+
+ );
+ expect(screen.getByText('GET')).toBeInTheDocument();
+ });
+ });
});
diff --git a/public/app/plugins/datasource/prometheus/configuration/PromSettings.tsx b/public/app/plugins/datasource/prometheus/configuration/PromSettings.tsx
index 2000232077c..6a0386d6364 100644
--- a/public/app/plugins/datasource/prometheus/configuration/PromSettings.tsx
+++ b/public/app/plugins/datasource/prometheus/configuration/PromSettings.tsx
@@ -11,8 +11,8 @@ import { ExemplarsSettings } from './ExemplarsSettings';
const { Select, Input, FormField, Switch } = LegacyForms;
const httpOptions = [
- { value: 'GET', label: 'GET' },
{ value: 'POST', label: 'POST' },
+ { value: 'GET', label: 'GET' },
];
type Props = Pick, 'options' | 'onOptionsChange'>;
@@ -20,6 +20,17 @@ type Props = Pick, 'options' | '
export const PromSettings = (props: Props) => {
const { options, onOptionsChange } = props;
+ /**
+ * We want to change the default httpMethod to 'POST' for all of the new Prometheus data sources instances (no url) added in 7.5+.
+ * We are explicitly adding httpMethod, as previously it could be undefined and defaulted to 'GET'.
+ * Undefined httpMethod is still going to be considered 'GET' for backward compatibility reasons, but if users open data
+ * source settings it is going to be set to 'GET' explicitly and it will be selected in httpMethod dropdown as 'GET'.
+ * */
+
+ if (!options.jsonData.httpMethod) {
+ options.url ? (options.jsonData.httpMethod = 'GET') : (options.jsonData.httpMethod = 'POST');
+ }
+
return (
<>
@@ -64,7 +75,7 @@ export const PromSettings = (props: Props) => {
HTTP Method
diff --git a/public/app/plugins/datasource/prometheus/configuration/mocks.ts b/public/app/plugins/datasource/prometheus/configuration/mocks.ts
new file mode 100644
index 00000000000..76d9a61fa24
--- /dev/null
+++ b/public/app/plugins/datasource/prometheus/configuration/mocks.ts
@@ -0,0 +1,12 @@
+import { DataSourceSettings } from '@grafana/data';
+import { PromOptions } from '../types';
+import { createDatasourceSettings } from '../../../../features/datasources/mocks';
+
+export function createDefaultConfigOptions(): DataSourceSettings
{
+ return createDatasourceSettings({
+ timeInterval: '1m',
+ queryTimeout: '1m',
+ httpMethod: 'GET',
+ directUrl: 'url',
+ });
+}
diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts
index 3ff3d58a63f..8a7f2ebc505 100644
--- a/public/app/plugins/datasource/prometheus/datasource.ts
+++ b/public/app/plugins/datasource/prometheus/datasource.ts
@@ -83,7 +83,6 @@ export class PrometheusDatasource extends DataSourceApi
this.languageProvider = new PrometheusLanguageProvider(this);
this.lookupsDisabled = instanceSettings.jsonData.disableMetricsLookup ?? false;
this.customQueryParameters = new URLSearchParams(instanceSettings.jsonData.customQueryParameters);
-
this.variables = new PrometheusVariableSupport(this, this.templateSrv, this.timeSrv);
}
@@ -144,6 +143,7 @@ export class PrometheusDatasource extends DataSourceApi
data[key] = value;
}
}
+
return this._request(url, data, { method: 'GET', hideFromInspector: true }).toPromise(); // toPromise until we change getTagValues, getTagKeys to Observable
}