[v9.3.x] Azure Monitor: Fix namespace selection for storageaccounts (#59184)
Azure Monitor: Fix namespace selection for storageaccounts (#56449)
(cherry picked from commit 3bea8f2462)
Co-authored-by: Andres Martinez Gotor <andres.martinez@grafana.com>
This commit is contained in:
co-authored by
Andres Martinez Gotor
parent
82e6fdfaf9
commit
17d98d79d9
+3
-1
@@ -4,8 +4,10 @@ describe('setQueryValue', () => {
|
|||||||
describe('setCustomNamespace', () => {
|
describe('setCustomNamespace', () => {
|
||||||
it('The metricnamespace must be: microsoft.storage/storageaccounts for storage accounts.', () => {
|
it('The metricnamespace must be: microsoft.storage/storageaccounts for storage accounts.', () => {
|
||||||
const result = setCustomNamespace({ refId: 'A' }, 'microsoft.storage/storageaccounts/fileservices');
|
const result = setCustomNamespace({ refId: 'A' }, 'microsoft.storage/storageaccounts/fileservices');
|
||||||
expect(result.azureMonitor?.customNamespace).toEqual('');
|
expect(result.azureMonitor?.customNamespace).toBeUndefined();
|
||||||
|
expect(result.azureMonitor?.metricNamespace).toEqual('microsoft.storage/storageaccounts/fileservices');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Set a custom namespace for non storage accounts.', () => {
|
it('Set a custom namespace for non storage accounts.', () => {
|
||||||
const result = setCustomNamespace({ refId: 'A' }, 'foo/bar');
|
const result = setCustomNamespace({ refId: 'A' }, 'foo/bar');
|
||||||
expect(result.azureMonitor?.customNamespace).toEqual('foo/bar');
|
expect(result.azureMonitor?.customNamespace).toEqual('foo/bar');
|
||||||
|
|||||||
+15
-2
@@ -4,13 +4,26 @@ export function setCustomNamespace(query: AzureMonitorQuery, selection: string |
|
|||||||
if (query.azureMonitor?.customNamespace === selection) {
|
if (query.azureMonitor?.customNamespace === selection) {
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
const customNamespace = selection?.toLowerCase().startsWith('microsoft.storage/storageaccounts/') ? '' : selection;
|
|
||||||
|
if (selection?.toLowerCase().startsWith('microsoft.storage/storageaccounts/')) {
|
||||||
|
return {
|
||||||
|
...query,
|
||||||
|
azureMonitor: {
|
||||||
|
...query.azureMonitor,
|
||||||
|
metricNamespace: selection,
|
||||||
|
metricName: undefined,
|
||||||
|
aggregation: undefined,
|
||||||
|
timeGrain: '',
|
||||||
|
dimensionFilters: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...query,
|
...query,
|
||||||
azureMonitor: {
|
azureMonitor: {
|
||||||
...query.azureMonitor,
|
...query.azureMonitor,
|
||||||
customNamespace,
|
customNamespace: selection,
|
||||||
metricName: undefined,
|
metricName: undefined,
|
||||||
aggregation: undefined,
|
aggregation: undefined,
|
||||||
timeGrain: '',
|
timeGrain: '',
|
||||||
|
|||||||
Reference in New Issue
Block a user