Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Monitor: Fix migration issue with MetricDefinitionsQuery template variable query types #55262

Merged
merged 5 commits into from Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -822,7 +822,7 @@
"options": [],
"query": {
"grafanaTemplateVariableFn": {
"kind": "MetricDefinitionsQuery",
"kind": "MetricNamespaceQuery",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually it's good to leave these queries as the "old" way to check if we break migrations but for this case I guess it's okay to update them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it did not help us spot that we did break migrations ;)

I would rather update them in case someone uses them as template to create another curated dashboard.
But we could leave one (not importable) and use it in the tests...
WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, it's not automated so it's difficult to catch errors ... but it's helpful to reproduce issues :) anyway I also get your point for people using these as templates so it's also fine to update them.

"rawQuery": "Namespaces($sub, $rg)",
"resourceGroup": "$rg",
"subscription": "$sub"
Expand Down
Expand Up @@ -1870,7 +1870,7 @@
"options": [],
"query": {
"grafanaTemplateVariableFn": {
"kind": "MetricDefinitionsQuery",
"kind": "MetricNamespaceQuery",
"rawQuery": "namespaces($sub,$rg)",
"resourceGroup": "$rg",
"subscription": "$sub"
Expand Down Expand Up @@ -1898,7 +1898,7 @@
"options": [],
"query": {
"grafanaTemplateVariableFn": {
"kind": "MetricDefinitionsQuery",
"kind": "MetricNamespaceQuery",
"rawQuery": "namespaces($sub,$rg)",
"resourceGroup": "$rg",
"subscription": "$sub"
Expand Down Expand Up @@ -1926,7 +1926,7 @@
"options": [],
"query": {
"grafanaTemplateVariableFn": {
"kind": "MetricDefinitionsQuery",
"kind": "MetricNamespaceQuery",
"rawQuery": "namespaces($sub,$rg)",
"resourceGroup": "$rg",
"subscription": "$sub"
Expand Down Expand Up @@ -1954,7 +1954,7 @@
"options": [],
"query": {
"grafanaTemplateVariableFn": {
"kind": "MetricDefinitionsQuery",
"kind": "MetricNamespaceQuery",
"rawQuery": "namespaces($sub,$rg)",
"resourceGroup": "$rg",
"subscription": "$sub"
Expand Down
Expand Up @@ -258,7 +258,7 @@ const migrateGrafanaTemplateVariableFn = (query: AzureMonitorQuery) => {
return query;
}

const migratedQuery: AzureMonitorQuery = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can still be a const?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I thought I had to change it when I had the delete for grafanaTemplateVariableFn but you're right 👍

let migratedQuery: AzureMonitorQuery = {
...query,
};
if ('subscription' in grafanaTemplateVariableFn) {
Expand Down Expand Up @@ -287,6 +287,9 @@ const migrateGrafanaTemplateVariableFn = (query: AzureMonitorQuery) => {
case 'MetricNamespaceQuery':
migratedQuery.queryType = AzureQueryType.NamespacesQuery;
break;
case 'MetricDefinitionsQuery':
migratedQuery.queryType = AzureQueryType.NamespacesQuery;
break;
case 'MetricNamesQuery':
migratedQuery.queryType = AzureQueryType.MetricNamesQuery;
break;
Expand Down
Expand Up @@ -43,6 +43,13 @@ export interface MetricNamespaceQuery extends BaseGrafanaTemplateVariableQuery {
metricNamespace?: string;
resourceName?: string;
}
export interface MetricDefinitionsQuery extends BaseGrafanaTemplateVariableQuery {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a /* @deprecated message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

kind: 'MetricDefinitionsQuery';
subscription: string;
resourceGroup: string;
metricNamespace?: string;
resourceName?: string;
}
export interface MetricNamesQuery extends BaseGrafanaTemplateVariableQuery {
kind: 'MetricNamesQuery';
subscription: string;
Expand All @@ -62,6 +69,7 @@ export type GrafanaTemplateVariableQuery =
| ResourceGroupsQuery
| ResourceNamesQuery
| MetricNamespaceQuery
| MetricDefinitionsQuery
| MetricNamesQuery
| WorkspacesQuery
| UnknownQuery;