mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 03:34:15 -06:00
OpenSearch: Use aoss
servicename if OpenSearch is configured as serverless
(#60344)
* Use `aoss` if opensearch is configured as `serverless`
This commit is contained in:
parent
5a7f38053b
commit
386faf5958
@ -441,7 +441,7 @@ func (s *Service) httpClientOptions(ctx context.Context, ds *datasources.DataSou
|
||||
|
||||
if ds.JsonData != nil && ds.JsonData.Get("sigV4Auth").MustBool(false) && setting.SigV4AuthEnabled {
|
||||
opts.SigV4 = &sdkhttpclient.SigV4Config{
|
||||
Service: awsServiceNamespace(ds.Type),
|
||||
Service: awsServiceNamespace(ds.Type, ds.JsonData),
|
||||
Region: ds.JsonData.Get("sigV4Region").MustString(),
|
||||
AssumeRoleARN: ds.JsonData.Get("sigV4AssumeRoleArn").MustString(),
|
||||
AuthType: ds.JsonData.Get("sigV4AuthType").MustString(),
|
||||
@ -572,10 +572,18 @@ func (s *Service) getCustomHeaders(jsonData *simplejson.Json, decryptedValues ma
|
||||
return headers
|
||||
}
|
||||
|
||||
func awsServiceNamespace(dsType string) string {
|
||||
func awsServiceNamespace(dsType string, jsonData *simplejson.Json) string {
|
||||
switch dsType {
|
||||
case datasources.DS_ES, datasources.DS_ES_OPEN_DISTRO, datasources.DS_ES_OPENSEARCH:
|
||||
case datasources.DS_ES, datasources.DS_ES_OPEN_DISTRO:
|
||||
return "es"
|
||||
case datasources.DS_ES_OPENSEARCH:
|
||||
serverless := jsonData.Get("serverless").MustBool()
|
||||
|
||||
if serverless {
|
||||
return "aoss"
|
||||
} else {
|
||||
return "es"
|
||||
}
|
||||
case datasources.DS_PROMETHEUS, datasources.DS_ALERTMANAGER:
|
||||
return "aps"
|
||||
default:
|
||||
|
@ -180,6 +180,72 @@ func TestService_IDScopeResolver(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestService_awsServiceNamespace(t *testing.T) {
|
||||
type testCaseResolver struct {
|
||||
desc string
|
||||
givenDs string
|
||||
givenJson string
|
||||
want string
|
||||
panic bool
|
||||
}
|
||||
|
||||
testCases := []testCaseResolver{
|
||||
{
|
||||
desc: "elasticsearch",
|
||||
givenDs: datasources.DS_ES,
|
||||
givenJson: `{ "sigV4Auth": true, "serverless": true }`,
|
||||
want: "es",
|
||||
}, {
|
||||
desc: "opendistro",
|
||||
givenDs: datasources.DS_ES_OPEN_DISTRO,
|
||||
givenJson: `{ "sigV4Auth": true, "serverless": true }`,
|
||||
want: "es",
|
||||
}, {
|
||||
desc: "opensearch not serverless",
|
||||
givenDs: datasources.DS_ES_OPENSEARCH,
|
||||
givenJson: `{ "sigV4Auth": true }`,
|
||||
want: "es",
|
||||
}, {
|
||||
desc: "opensearch not serverless",
|
||||
givenDs: datasources.DS_ES_OPENSEARCH,
|
||||
givenJson: `{ "sigV4Auth": true, "serverless": false }`,
|
||||
want: "es",
|
||||
}, {
|
||||
desc: "opensearch serverless",
|
||||
givenDs: datasources.DS_ES_OPENSEARCH,
|
||||
givenJson: `{ "sigV4Auth": true, "serverless": true }`,
|
||||
want: "aoss",
|
||||
}, {
|
||||
desc: "prometheus",
|
||||
givenDs: datasources.DS_PROMETHEUS,
|
||||
givenJson: `{ "sigV4Auth": true, "serverless": true }`,
|
||||
want: "aps",
|
||||
}, {
|
||||
desc: "alertmanager",
|
||||
givenDs: datasources.DS_ALERTMANAGER,
|
||||
givenJson: `{ "sigV4Auth": true, "serverless": true }`,
|
||||
want: "aps",
|
||||
}, {
|
||||
desc: "panic",
|
||||
givenDs: "panic",
|
||||
givenJson: `{ "sigV4Auth": true, "serverless": true }`,
|
||||
want: "aps",
|
||||
panic: true,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
json, _ := simplejson.NewJson([]byte(tc.givenJson))
|
||||
if tc.panic {
|
||||
require.Panics(t, func() { awsServiceNamespace(tc.givenDs, json) })
|
||||
} else {
|
||||
resolved := awsServiceNamespace(tc.givenDs, json)
|
||||
require.Equal(t, tc.want, resolved)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//nolint:goconst
|
||||
func TestService_GetHttpTransport(t *testing.T) {
|
||||
cfg := &setting.Cfg{}
|
||||
|
Loading…
Reference in New Issue
Block a user