OpenSearch: Use aoss servicename if OpenSearch is configured as serverless (#60344)

* Use `aoss` if opensearch is configured as `serverless`
This commit is contained in:
Sven Grossmann
2022-12-14 20:22:26 +01:00
committed by GitHub
parent 5a7f38053b
commit 386faf5958
2 changed files with 77 additions and 3 deletions
@@ -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{}