CloudWatch: Cross-account querying support (#59362)
* Lattice: Point to private prerelease of aws-sdk-go (#515) * point to private prerelease of aws-sdk-go * fix build issue * Lattice: Adding a feature toggle (#549) * Adding a feature toggle for lattice * Change name of feature toggle * Lattice: List accounts (#543) * Separate layers * Introduce testify/mock library Co-authored-by: Shirley Leu <4163034+fridgepoet@users.noreply.github.com> * point to version that includes metric api changes (#574) * add accounts component (#575) * Test refactor: remove unneeded clientFactoryMock (#581) * Lattice: Add monitoring badge (#576) * add monitoring badge * fix tests * solve conflict * Lattice: Add dynamic label for account display name (#579) * Build: Automatically sync lattice-main with OSS * Lattice: Point to private prerelease of aws-sdk-go (#515) * point to private prerelease of aws-sdk-go * fix build issue * Lattice: Adding a feature toggle (#549) * Adding a feature toggle for lattice * Change name of feature toggle * Lattice: List accounts (#543) * Separate layers * Introduce testify/mock library Co-authored-by: Shirley Leu <4163034+fridgepoet@users.noreply.github.com> * point to version that includes metric api changes (#574) * add accounts component (#575) * Test refactor: remove unneeded clientFactoryMock (#581) * Lattice: Add monitoring badge (#576) * add monitoring badge * fix tests * solve conflict * add account label Co-authored-by: Shirley Leu <4163034+fridgepoet@users.noreply.github.com> Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com> * fix import * solve merge related problem * add account info (#608) * add back namespaces handler * Lattice: Parse account id and return it to frontend (#609) * parse account id and return to frontend * fix route test * only show badge when feature toggle is enabled (#615) * Lattice: Refactor resource response type and return account (#613) * refactor resource response type * remove not used file. * go lint * fix tests * remove commented code * Lattice: Use account as input when listing metric names and dimensions (#611) * use account in resource requests * add account to response * revert accountInfo to accountId * PR feedback * unit test account in list metrics response * remove not used asserts * don't assert on response that is not relevant to the test * removed dupe test * pr feedback * rename request package (#626) * Lattice: Move account component and add tooltip (#630) * move accounts component to the top of metric stat editor * add tooltip * CloudWatch: add account to GetMetricData queries (#627) * Add AccountId to metric stat query * Lattice: Account variable support (#625) * add variable support in accounts component * add account variable query type * update variables * interpolate variable before its sent to backend * handle variable change in hooks * remove not used import * Update public/app/plugins/datasource/cloudwatch/components/Account.tsx Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com> * Update public/app/plugins/datasource/cloudwatch/hooks.ts Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com> * add one more unit test Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com> * cleanup (#629) * Set account Id according to crossAccountQuerying feature flag in backend (#632) * CloudWatch: Change spelling of feature-toggle (#634) * Lattice Logs (#631) * Lattice Logs * Fixes after CR * Lattice: Bug: fix dimension keys request (#644) * fix dimension keys * fix lint * more lint * CloudWatch: Add tests for QueryData with AccountId (#637) * Update from breaking change (#645) * Update from breaking change * Remove extra interface and methods Co-authored-by: Shirley Leu <4163034+fridgepoet@users.noreply.github.com> * CloudWatch: Add business logic layer for getting log groups (#642) Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com> * Lattice: Fix - unset account id in region change handler (#646) * move reset of account to region change handler * fix broken test * Lattice: Add account id to metric stat query deep link (#656) add account id to metric stat link * CloudWatch: Add new log groups handler for cross-account querying (#643) * Lattice: Add feature tracking (#660) * add tracking for account id prescense in metrics query * also check feature toggle * fix broken test * CloudWatch: Add route for DescribeLogGroups for cross-account querying (#647) Co-authored-by: Erik Sundell <erik.sundell87@gmail.com> * Lattice: Handle account id default value (#662) * make sure right type is returned * set right default values * Suggestions to lattice changes (#663) * Change ListMetricsWithPageLimit response to slice of non-pointers * Change GetAccountsForCurrentUserOrRole response to be not pointer * Clean test Cleanup calls in test * Remove CloudWatchAPI as part of mock * Resolve conflicts * Add Latest SDK (#672) * add tooltip (#674) * Docs: Add documentation for CloudWatch cross account querying (#676) * wip docs * change wordings * add sections about metrics and logs * change from monitoring to observability * Update docs/sources/datasources/aws-cloudwatch/_index.md Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com> * Update docs/sources/datasources/aws-cloudwatch/query-editor/index.md Co-authored-by: Fiona Artiaga <89225282+GrafanaWriter@users.noreply.github.com> * Update docs/sources/datasources/aws-cloudwatch/query-editor/index.md Co-authored-by: Fiona Artiaga <89225282+GrafanaWriter@users.noreply.github.com> * Update docs/sources/datasources/aws-cloudwatch/query-editor/index.md Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com> * Update docs/sources/datasources/aws-cloudwatch/query-editor/index.md Co-authored-by: Fiona Artiaga <89225282+GrafanaWriter@users.noreply.github.com> * apply pr feedback * fix file name * more pr feedback * pr feedback Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com> Co-authored-by: Fiona Artiaga <89225282+GrafanaWriter@users.noreply.github.com> * use latest version of the aws-sdk-go * Fix tests' mock response type * Remove change in Azure Monitor Co-authored-by: Sarah Zinger <sarah.zinger@grafana.com> Co-authored-by: Shirley Leu <4163034+fridgepoet@users.noreply.github.com> Co-authored-by: Fiona Artiaga <89225282+GrafanaWriter@users.noreply.github.com>
This commit is contained in:
co-authored by
Shirley Leu
Sarah Zinger
Fiona Artiaga
parent
5b861faec3
commit
254577ba56
@@ -107,6 +107,53 @@ func TestCloudWatchQuery(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, deepLink, "label")
|
||||
})
|
||||
|
||||
t.Run("includes account id in case its a metric stat query and an account id is set", func(t *testing.T) {
|
||||
startTime := time.Now()
|
||||
endTime := startTime.Add(2 * time.Hour)
|
||||
query := &CloudWatchQuery{
|
||||
RefId: "A",
|
||||
Region: "us-east-1",
|
||||
Expression: "",
|
||||
Statistic: "Average",
|
||||
Period: 300,
|
||||
Id: "id1",
|
||||
MatchExact: true,
|
||||
AccountId: pointer("123456789"),
|
||||
Label: "${PROP('Namespace')}",
|
||||
Dimensions: map[string][]string{
|
||||
"InstanceId": {"i-12345678"},
|
||||
},
|
||||
MetricQueryType: MetricQueryTypeSearch,
|
||||
MetricEditorMode: MetricEditorModeBuilder,
|
||||
}
|
||||
|
||||
deepLink, err := query.BuildDeepLink(startTime, endTime, false)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, deepLink, "accountId%22%3A%22123456789")
|
||||
})
|
||||
|
||||
t.Run("does not include account id in case its not a metric stat query", func(t *testing.T) {
|
||||
startTime := time.Now()
|
||||
endTime := startTime.Add(2 * time.Hour)
|
||||
query := &CloudWatchQuery{
|
||||
RefId: "A",
|
||||
Region: "us-east-1",
|
||||
Statistic: "Average",
|
||||
Expression: "SEARCH(someexpression)",
|
||||
AccountId: pointer("123456789"),
|
||||
Period: 300,
|
||||
Id: "id1",
|
||||
MatchExact: true,
|
||||
Label: "${PROP('Namespace')}",
|
||||
MetricQueryType: MetricQueryTypeSearch,
|
||||
MetricEditorMode: MetricEditorModeRaw,
|
||||
}
|
||||
|
||||
deepLink, err := query.BuildDeepLink(startTime, endTime, false)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, deepLink, "accountId%22%3A%22123456789")
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("SEARCH(someexpression) was specified in the query editor", func(t *testing.T) {
|
||||
@@ -269,7 +316,7 @@ func TestRequestParser(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
migratedQueries, err := ParseMetricDataQueries(oldQuery, time.Now(), time.Now(), false)
|
||||
migratedQueries, err := ParseMetricDataQueries(oldQuery, time.Now(), time.Now(), false, false)
|
||||
assert.NoError(t, err)
|
||||
require.Len(t, migratedQueries, 1)
|
||||
require.NotNil(t, migratedQueries[0])
|
||||
@@ -300,7 +347,7 @@ func TestRequestParser(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
results, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false)
|
||||
results, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, results, 1)
|
||||
res := results[0]
|
||||
@@ -343,7 +390,7 @@ func TestRequestParser(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
results, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false)
|
||||
results, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false, false)
|
||||
assert.NoError(t, err)
|
||||
require.Len(t, results, 1)
|
||||
res := results[0]
|
||||
@@ -376,7 +423,7 @@ func TestRequestParser(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
_, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false)
|
||||
_, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false, false)
|
||||
require.Error(t, err)
|
||||
|
||||
assert.Equal(t, `error parsing query "", failed to parse dimensions: unknown type as dimension value`, err.Error())
|
||||
@@ -405,7 +452,7 @@ func Test_ParseMetricDataQueries_periods(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false)
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false, false)
|
||||
assert.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
require.NotNil(t, res[0])
|
||||
@@ -437,7 +484,7 @@ func Test_ParseMetricDataQueries_periods(t *testing.T) {
|
||||
to := time.Now()
|
||||
from := to.Local().Add(time.Minute * time.Duration(5))
|
||||
|
||||
res, err := ParseMetricDataQueries(query, from, to, false)
|
||||
res, err := ParseMetricDataQueries(query, from, to, false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
assert.Equal(t, 60, res[0].Period)
|
||||
@@ -447,7 +494,7 @@ func Test_ParseMetricDataQueries_periods(t *testing.T) {
|
||||
to := time.Now()
|
||||
from := to.AddDate(0, 0, -1)
|
||||
|
||||
res, err := ParseMetricDataQueries(query, from, to, false)
|
||||
res, err := ParseMetricDataQueries(query, from, to, false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
assert.Equal(t, 60, res[0].Period)
|
||||
@@ -456,7 +503,7 @@ func Test_ParseMetricDataQueries_periods(t *testing.T) {
|
||||
t.Run("Time range is 2 days", func(t *testing.T) {
|
||||
to := time.Now()
|
||||
from := to.AddDate(0, 0, -2)
|
||||
res, err := ParseMetricDataQueries(query, from, to, false)
|
||||
res, err := ParseMetricDataQueries(query, from, to, false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
assert.Equal(t, 300, res[0].Period)
|
||||
@@ -466,7 +513,7 @@ func Test_ParseMetricDataQueries_periods(t *testing.T) {
|
||||
to := time.Now()
|
||||
from := to.AddDate(0, 0, -7)
|
||||
|
||||
res, err := ParseMetricDataQueries(query, from, to, false)
|
||||
res, err := ParseMetricDataQueries(query, from, to, false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
assert.Equal(t, 900, res[0].Period)
|
||||
@@ -476,7 +523,7 @@ func Test_ParseMetricDataQueries_periods(t *testing.T) {
|
||||
to := time.Now()
|
||||
from := to.AddDate(0, 0, -30)
|
||||
|
||||
res, err := ParseMetricDataQueries(query, from, to, false)
|
||||
res, err := ParseMetricDataQueries(query, from, to, false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
assert.Equal(t, 3600, res[0].Period)
|
||||
@@ -486,7 +533,7 @@ func Test_ParseMetricDataQueries_periods(t *testing.T) {
|
||||
to := time.Now()
|
||||
from := to.AddDate(0, 0, -90)
|
||||
|
||||
res, err := ParseMetricDataQueries(query, from, to, false)
|
||||
res, err := ParseMetricDataQueries(query, from, to, false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
assert.Equal(t, 21600, res[0].Period)
|
||||
@@ -496,7 +543,7 @@ func Test_ParseMetricDataQueries_periods(t *testing.T) {
|
||||
to := time.Now()
|
||||
from := to.AddDate(-1, 0, 0)
|
||||
|
||||
res, err := ParseMetricDataQueries(query, from, to, false)
|
||||
res, err := ParseMetricDataQueries(query, from, to, false, false)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, res, 1)
|
||||
assert.Equal(t, 21600, res[0].Period)
|
||||
@@ -506,7 +553,7 @@ func Test_ParseMetricDataQueries_periods(t *testing.T) {
|
||||
to := time.Now()
|
||||
from := to.AddDate(-2, 0, 0)
|
||||
|
||||
res, err := ParseMetricDataQueries(query, from, to, false)
|
||||
res, err := ParseMetricDataQueries(query, from, to, false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
assert.Equal(t, 86400, res[0].Period)
|
||||
@@ -515,7 +562,7 @@ func Test_ParseMetricDataQueries_periods(t *testing.T) {
|
||||
t.Run("Time range is 2 days, but 16 days ago", func(t *testing.T) {
|
||||
to := time.Now().AddDate(0, 0, -14)
|
||||
from := to.AddDate(0, 0, -2)
|
||||
res, err := ParseMetricDataQueries(query, from, to, false)
|
||||
res, err := ParseMetricDataQueries(query, from, to, false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
assert.Equal(t, 300, res[0].Period)
|
||||
@@ -524,7 +571,7 @@ func Test_ParseMetricDataQueries_periods(t *testing.T) {
|
||||
t.Run("Time range is 2 days, but 90 days ago", func(t *testing.T) {
|
||||
to := time.Now().AddDate(0, 0, -88)
|
||||
from := to.AddDate(0, 0, -2)
|
||||
res, err := ParseMetricDataQueries(query, from, to, false)
|
||||
res, err := ParseMetricDataQueries(query, from, to, false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
assert.Equal(t, 3600, res[0].Period)
|
||||
@@ -533,7 +580,7 @@ func Test_ParseMetricDataQueries_periods(t *testing.T) {
|
||||
t.Run("Time range is 2 days, but 456 days ago", func(t *testing.T) {
|
||||
to := time.Now().AddDate(0, 0, -454)
|
||||
from := to.AddDate(0, 0, -2)
|
||||
res, err := ParseMetricDataQueries(query, from, to, false)
|
||||
res, err := ParseMetricDataQueries(query, from, to, false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
assert.Equal(t, 21600, res[0].Period)
|
||||
@@ -548,7 +595,7 @@ func Test_ParseMetricDataQueries_periods(t *testing.T) {
|
||||
}`),
|
||||
},
|
||||
}
|
||||
_, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false)
|
||||
_, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false, false)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, `error parsing query "", failed to parse period as duration: time: invalid duration "invalid"`, err.Error())
|
||||
})
|
||||
@@ -563,7 +610,7 @@ func Test_ParseMetricDataQueries_periods(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false)
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false, false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
require.Len(t, res, 1)
|
||||
@@ -620,6 +667,18 @@ func Test_ParseMetricDataQueries_query_type_and_metric_editor_mode_and_GMD_query
|
||||
expectedMetricEditorMode: dummyTestEditorMode,
|
||||
expectedGMDApiMode: GMDApiModeMetricStat,
|
||||
},
|
||||
"no dimensions, matchExact is false": {
|
||||
extraDataQueryJson: `"matchExact":false,`,
|
||||
expectedMetricQueryType: MetricQueryTypeSearch,
|
||||
expectedMetricEditorMode: MetricEditorModeBuilder,
|
||||
expectedGMDApiMode: GMDApiModeInferredSearchExpression,
|
||||
},
|
||||
"query metricQueryType": {
|
||||
extraDataQueryJson: `"metricQueryType":1,`,
|
||||
expectedMetricQueryType: MetricQueryTypeQuery,
|
||||
expectedMetricEditorMode: MetricEditorModeBuilder,
|
||||
expectedGMDApiMode: GMDApiModeSQLExpression,
|
||||
},
|
||||
}
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
@@ -638,7 +697,7 @@ func Test_ParseMetricDataQueries_query_type_and_metric_editor_mode_and_GMD_query
|
||||
),
|
||||
},
|
||||
}
|
||||
res, err := ParseMetricDataQueries(query, time.Now(), time.Now(), false)
|
||||
res, err := ParseMetricDataQueries(query, time.Now(), time.Now(), false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
require.NotNil(t, res[0])
|
||||
@@ -664,7 +723,7 @@ func Test_ParseMetricDataQueries_hide_and_ReturnData(t *testing.T) {
|
||||
}`),
|
||||
},
|
||||
}
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false)
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
require.NotNil(t, res[0])
|
||||
@@ -685,7 +744,7 @@ func Test_ParseMetricDataQueries_hide_and_ReturnData(t *testing.T) {
|
||||
}`),
|
||||
},
|
||||
}
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false)
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
require.NotNil(t, res[0])
|
||||
@@ -706,7 +765,7 @@ func Test_ParseMetricDataQueries_hide_and_ReturnData(t *testing.T) {
|
||||
}`),
|
||||
},
|
||||
}
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false)
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
require.NotNil(t, res[0])
|
||||
@@ -725,7 +784,7 @@ func Test_ParseMetricDataQueries_hide_and_ReturnData(t *testing.T) {
|
||||
}`),
|
||||
},
|
||||
}
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false)
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
require.NotNil(t, res[0])
|
||||
@@ -746,7 +805,7 @@ func Test_ParseMetricDataQueries_hide_and_ReturnData(t *testing.T) {
|
||||
}`),
|
||||
},
|
||||
}
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false)
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
require.NotNil(t, res[0])
|
||||
@@ -767,7 +826,7 @@ func Test_ParseMetricDataQueries_hide_and_ReturnData(t *testing.T) {
|
||||
}`),
|
||||
},
|
||||
}
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false)
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
require.NotNil(t, res[0])
|
||||
@@ -790,7 +849,7 @@ func Test_ParseMetricDataQueries_ID(t *testing.T) {
|
||||
}`),
|
||||
},
|
||||
}
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false)
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
require.NotNil(t, res[0])
|
||||
@@ -811,7 +870,7 @@ func Test_ParseMetricDataQueries_ID(t *testing.T) {
|
||||
}`),
|
||||
},
|
||||
}
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false)
|
||||
res, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
require.NotNil(t, res[0])
|
||||
@@ -838,7 +897,7 @@ func Test_ParseMetricDataQueries_sets_label_when_label_is_present_in_json_query(
|
||||
},
|
||||
}
|
||||
|
||||
res, err := ParseMetricDataQueries(query, time.Now(), time.Now(), true)
|
||||
res, err := ParseMetricDataQueries(query, time.Now(), time.Now(), true, false)
|
||||
assert.NoError(t, err)
|
||||
require.Len(t, res, 1)
|
||||
require.NotNil(t, res[0])
|
||||
@@ -902,7 +961,7 @@ func Test_ParseMetricDataQueries_migrate_alias_to_label(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
res, err := ParseMetricDataQueries(query, time.Now(), time.Now(), true)
|
||||
res, err := ParseMetricDataQueries(query, time.Now(), time.Now(), true, false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
require.Len(t, res, 1)
|
||||
@@ -949,7 +1008,7 @@ func Test_ParseMetricDataQueries_migrate_alias_to_label(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
res, err := ParseMetricDataQueries(query, time.Now(), time.Now(), true)
|
||||
res, err := ParseMetricDataQueries(query, time.Now(), time.Now(), true, false)
|
||||
assert.NoError(t, err)
|
||||
require.Len(t, res, 2)
|
||||
|
||||
@@ -1019,7 +1078,7 @@ func Test_ParseMetricDataQueries_migrate_alias_to_label(t *testing.T) {
|
||||
}`, tc.labelJson)),
|
||||
},
|
||||
}
|
||||
res, err := ParseMetricDataQueries(query, time.Now(), time.Now(), tc.dynamicLabelsFeatureToggleEnabled)
|
||||
res, err := ParseMetricDataQueries(query, time.Now(), time.Now(), tc.dynamicLabelsFeatureToggleEnabled, false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
require.Len(t, res, 1)
|
||||
@@ -1046,7 +1105,7 @@ func Test_ParseMetricDataQueries_statistics_and_query_type_validation_and_MatchE
|
||||
{
|
||||
JSON: []byte("{}"),
|
||||
},
|
||||
}, time.Now(), time.Now(), false)
|
||||
}, time.Now(), time.Now(), false, false)
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, `error parsing query "", query must have either statistic or statistics field`, err.Error())
|
||||
|
||||
@@ -1059,7 +1118,7 @@ func Test_ParseMetricDataQueries_statistics_and_query_type_validation_and_MatchE
|
||||
{
|
||||
JSON: []byte(`{"type":"some other type", "statistic":"Average", "matchExact":false}`),
|
||||
},
|
||||
}, time.Now(), time.Now(), false)
|
||||
}, time.Now(), time.Now(), false, false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Empty(t, actual)
|
||||
@@ -1071,7 +1130,7 @@ func Test_ParseMetricDataQueries_statistics_and_query_type_validation_and_MatchE
|
||||
{
|
||||
JSON: []byte(`{"statistic":"Average"}`),
|
||||
},
|
||||
}, time.Now(), time.Now(), false)
|
||||
}, time.Now(), time.Now(), false, false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NotEmpty(t, actual)
|
||||
@@ -1083,7 +1142,7 @@ func Test_ParseMetricDataQueries_statistics_and_query_type_validation_and_MatchE
|
||||
{
|
||||
JSON: []byte(`{"statistic":"Average"}`),
|
||||
},
|
||||
}, time.Now(), time.Now(), false)
|
||||
}, time.Now(), time.Now(), false, false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Len(t, actual, 1)
|
||||
@@ -1097,7 +1156,7 @@ func Test_ParseMetricDataQueries_statistics_and_query_type_validation_and_MatchE
|
||||
{
|
||||
JSON: []byte(`{"statistic":"Average","matchExact":false}`),
|
||||
},
|
||||
}, time.Now(), time.Now(), false)
|
||||
}, time.Now(), time.Now(), false, false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Len(t, actual, 1)
|
||||
@@ -1105,3 +1164,36 @@ func Test_ParseMetricDataQueries_statistics_and_query_type_validation_and_MatchE
|
||||
assert.False(t, actual[0].MatchExact)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_ParseMetricDataQueries_account_Id(t *testing.T) {
|
||||
t.Run("account is set when cross account querying enabled", func(t *testing.T) {
|
||||
actual, err := ParseMetricDataQueries(
|
||||
[]backend.DataQuery{
|
||||
{
|
||||
JSON: []byte(`{"accountId":"some account id", "statistic":"Average"}`),
|
||||
},
|
||||
}, time.Now(), time.Now(), false, true)
|
||||
assert.NoError(t, err)
|
||||
|
||||
require.Len(t, actual, 1)
|
||||
require.NotNil(t, actual[0])
|
||||
require.NotNil(t, actual[0].AccountId)
|
||||
assert.Equal(t, "some account id", *actual[0].AccountId)
|
||||
})
|
||||
|
||||
t.Run("account is not set when cross account querying disabled", func(t *testing.T) {
|
||||
actual, err := ParseMetricDataQueries(
|
||||
[]backend.DataQuery{
|
||||
{
|
||||
JSON: []byte(`{"accountId":"some account id", "statistic":"Average"}`),
|
||||
},
|
||||
}, time.Now(), time.Now(), false, false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
require.Len(t, actual, 1)
|
||||
require.NotNil(t, actual[0])
|
||||
assert.Nil(t, actual[0].AccountId)
|
||||
})
|
||||
}
|
||||
|
||||
func pointer[T any](arg T) *T { return &arg }
|
||||
|
||||
Reference in New Issue
Block a user