mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Use default POST method if no httpMethod provided (#38446)
* Prometheus: If no httpMethod, use default POST method * Use http.MethodPost
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -70,6 +71,7 @@ func (s *Service) Init() error {
|
|||||||
|
|
||||||
func newInstanceSettings() datasource.InstanceFactoryFunc {
|
func newInstanceSettings() datasource.InstanceFactoryFunc {
|
||||||
return func(settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
|
return func(settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
|
||||||
|
defaultHttpMethod := http.MethodPost
|
||||||
jsonData := map[string]interface{}{}
|
jsonData := map[string]interface{}{}
|
||||||
err := json.Unmarshal(settings.JSONData, &jsonData)
|
err := json.Unmarshal(settings.JSONData, &jsonData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -82,7 +84,7 @@ func newInstanceSettings() datasource.InstanceFactoryFunc {
|
|||||||
|
|
||||||
httpMethod, ok := jsonData["httpMethod"].(string)
|
httpMethod, ok := jsonData["httpMethod"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("no http method provided")
|
httpMethod = defaultHttpMethod
|
||||||
}
|
}
|
||||||
|
|
||||||
// timeInterval can be a string or can be missing.
|
// timeInterval can be a string or can be missing.
|
||||||
|
|||||||
Reference in New Issue
Block a user