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
AzureMonitor: Ensure resourceURI template variable is migrated #56095
Conversation
- Do not filter queries containing a resource URI template - Update migration - Add test
Backend code coverage report for PR #56095 |
Frontend code coverage report for PR #56095
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just one question here.
BTW, it may be worth it to also backport this to 9.1.x (just in case the user cannot upgrade to the new minor anytime soon)
@@ -146,7 +146,7 @@ function migrateDimensionToResourceObj(query: AzureMonitorQuery): AzureMonitorQu | |||
resourceGroup: details?.resourceGroup, | |||
metricNamespace: details?.metricNamespace, | |||
resourceName: details?.resourceName, | |||
resourceUri: undefined, | |||
resourceUri: details.subscription ? undefined : query.azureMonitor.resourceUri, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 why does this depend on having a subscription if the resourceUri already includes it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this to maintain the behaviour of setting the resourceUri
to undefined
. I'm assuming (it may be a poor assumption) that if the subscription
value is set then we can unset the resourceUri
, otherwise we maintain the value so that the migration can be carried out later when applyTemplateVariables
is called.
The current behaviour of resourceUri: undefined
means that we remove the template variable value before it is actually applied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not remove it if it's defined: If it's defined, it should take precedence over the rest of params (subs, group, name...) and the backend will skip the URI generation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this not go against our deprecation of resourceUri
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, we need to clean up the resourceUri value, since if not, the UI, showing a subs + group + name, won't reflect what is actually being used in the backend (the resource URI). BTW, that also means that even after this PR, the client won't be able to see the selection in the resource picker (even though the query will be executed).
I was thinking about our conversation in #55372. If we have a template variable with multiple resources from different resource groups, the more straight forward way to support that is to have a list of resource IDs so supporting both formats sounds like something we will need to do. In any case, it's not something we are prepared to do at the moment.
Going to the original comment here, the condition is probably better to also take into account the resource group and name, since sometimes the subscription is automatically added using the default value from the data source configuration.
resourceUri: details.subscription ? undefined : query.azureMonitor.resourceUri, | |
resourceUri: (details.subscription && details?.resourceGroup && details?.resourceName) ? undefined : query.azureMonitor.resourceUri, |
}, | ||
}); | ||
const templatedQuery = ctx.ds.azureMonitorDatasource.applyTemplateVariables(query, {}); | ||
expect(templatedQuery).toMatchObject({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a test for not undefined resourceUri
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean a test for the case where resourceUri
is entirely undefined or a test for the case where we return the resourceUri
because it could not be parsed?
resourceUri: | ||
details?.subscription && details?.resourceGroup && details?.resourceName | ||
? undefined | ||
: query.azureMonitor.resourceUri, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we leave the resourceUri
, does it mean the query will be migrated again next time? As query.azureMonitor?.resourceUri
will be true?
Maybe I'm misunderstanding what you're trying to achieve here 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the resourceUri
is a template variable then we'd require the query to be migrated every time to account for any changes to the variable 😊
The goal of this PR is to ensure that if a template variable is used for the resourceUri
(as is the case for the support escalation) then it should be appropriately migrated to the relevant components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, we don't need to migrate it in the case it's a template variable, since it will never be parsed. Maybe you can update the condition to something like:
if (query.azureMonitor?.resourceUri && !query.azureMonitor.resourceUri.startsWith('$')) {
To be clear that template variables won't be migrated (but the result will be the same than with this code).
What would be nice, is to modify the "Advance" section of the resource picker to show the resource URI (in this case, the template variable) rather than the empty fields that they are going to see for the Subscription + Resource Group + Resource Name. But you can do that in a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha! Thanks, I think Andres' suggestion makes sense, maybe we can add some comment in the code for the next person that is trying to make sense of it?
// migrating if the query is using the deprecated `resourceURI` prop and it's not a template variable
Could we always set the uri as undefined
if we change the condition then?
If not, could we maybe extract details?.subscription && details?.resourceGroup && details?.resourceName
and give it a name that would help us understand what we are trying to achieve, such as isWellFormedURI
or isNotTemplateVariableURI
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's helpful to not set always the uri as undefined, to cover corner cases, like template variables covering weird parts of the resource URI (e.g. /subscriptions/$restOfTheThing
). +1 to define the condition as a variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made the suggested changes and will set this to auto-merge 😊 Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks for the changes 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Drone build failed: https://drone.grafana.net/grafana/grafana-enterprise/36009 |
* Ensure resourceURI template vars are migrated - Do not filter queries containing a resource URI template - Update migration - Add test * Update condition * Review (cherry picked from commit 462ca50)
* Ensure resourceURI template vars are migrated - Do not filter queries containing a resource URI template - Update migration - Add test * Update condition * Review (cherry picked from commit 462ca50)
Related to grafana/support-escalations#4104. #52897 removed a check on the existence of the
resourceUri
prop. This then leads to a query containing a resource URI that is a template variable being filtered out.This PR readds the check on
resourceUri
to ensure queries will get migrated.