forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AzureMonitor: Migrate Metrics query editor to React (grafana#30783)
* AzureMonitor: Remove anys from datasource to get the inferred type * AzureMonitor: Cast some datasource types TODO: we want proper types for these * AzureMonitor: Initial react Metrics editor components * start dimension fields * replace replaceTemplateVariable with datasource.replace, and rename onQueryChange to onChange * actually just do template variable replacement in the datasource * don't use azureMonitorIsConfigured * Refactors, mainly around the metric metadata - Convert all the metric metadata options for the Select before its set into state - Stop using SelectableValue because it's basically any when all the properties are optional - the onChange function passed to the fields now just accepts the direct value, rather than wrapped in a SelectableValue * added proper fields, and adding and removing for DimensionFields * Update query with Dimension changes * Width * subscription and query type fields * Should be feature complete now, more or less * fix missing import * fix lint issues * set default subscription ID * Starting to write some tests * tests for query editor * Remove subscription ID from the label in Metrics But we keep it there for the angular stuff * MetricsQueryEditor tests * Update index.test.tsx * fix tests * add template variables to dropdowns * clean up * update tests * Reorganise react components * Group query fields into rows * Rename Option type, add Azure response type * Refactor Metrics metric metadata - Types the Azure API - Moves default metadata values into datasource * nit * update test
- Loading branch information
Showing
32 changed files
with
1,576 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
public/app/plugins/datasource/grafana-azure-monitor-datasource/__mocks__/datasource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Datasource from '../datasource'; | ||
|
||
type DeepPartial<T> = { | ||
[P in keyof T]?: DeepPartial<T[P]>; | ||
}; | ||
|
||
export default function createMockDatasource() { | ||
// We make this a partial so we get _some_ kind of type safety when making this, rather than | ||
// having it be any or casted immediately to Datasource | ||
const _mockDatasource: DeepPartial<Datasource> = { | ||
getVariables: jest.fn().mockReturnValueOnce([]), | ||
|
||
azureMonitorDatasource: { | ||
isConfigured() { | ||
return true; | ||
}, | ||
getSubscriptions: jest.fn().mockResolvedValueOnce([]), | ||
}, | ||
|
||
getResourceGroups: jest.fn().mockResolvedValueOnce([]), | ||
getMetricDefinitions: jest.fn().mockResolvedValueOnce([]), | ||
getResourceNames: jest.fn().mockResolvedValueOnce([]), | ||
getMetricNamespaces: jest.fn().mockResolvedValueOnce([]), | ||
getMetricNames: jest.fn().mockResolvedValueOnce([]), | ||
getMetricMetadata: jest.fn().mockResolvedValueOnce({ | ||
primaryAggType: 'average', | ||
supportedAggTypes: [], | ||
supportedTimeGrains: [], | ||
dimensions: [], | ||
}), | ||
}; | ||
|
||
const mockDatasource = _mockDatasource as Datasource; | ||
|
||
return mockDatasource; | ||
} |
42 changes: 42 additions & 0 deletions
42
public/app/plugins/datasource/grafana-azure-monitor-datasource/__mocks__/query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { AzureMonitorQuery, AzureQueryType } from '../types'; | ||
|
||
const azureMonitorQuery: AzureMonitorQuery = { | ||
appInsights: undefined, // The actualy shape of this at runtime disagrees with the ts interface | ||
|
||
azureLogAnalytics: { | ||
query: | ||
'//change this example to create your own time series query\n<table name> //the table to query (e.g. Usage, Heartbeat, Perf)\n| where $__timeFilter(TimeGenerated) //this is a macro used to show the full chart’s time range, choose the datetime column here\n| summarize count() by <group by column>, bin(TimeGenerated, $__interval) //change “group by column” to a column in your table, such as “Computer”. The $__interval macro is used to auto-select the time grain. Can also use 1h, 5m etc.\n| order by TimeGenerated asc', | ||
resultFormat: 'time_series', | ||
workspace: 'e3fe4fde-ad5e-4d60-9974-e2f3562ffdf2', | ||
}, | ||
|
||
azureMonitor: { | ||
// aggOptions: [], | ||
aggregation: 'Average', | ||
allowedTimeGrainsMs: [60000, 300000, 900000, 1800000, 3600000, 21600000, 43200000, 86400000], | ||
// dimensionFilter: '*', | ||
dimensionFilters: [], | ||
metricDefinition: 'Microsoft.Compute/virtualMachines', | ||
metricName: 'Metric A', | ||
metricNamespace: 'Microsoft.Compute/virtualMachines', | ||
resourceGroup: 'grafanastaging', | ||
resourceName: 'grafana', | ||
timeGrain: 'auto', | ||
alias: '', | ||
// timeGrains: [], | ||
top: '10', | ||
}, | ||
|
||
insightsAnalytics: { | ||
query: '', | ||
resultFormat: 'time_series', | ||
}, | ||
|
||
queryType: AzureQueryType.AzureMonitor, | ||
refId: 'A', | ||
subscription: 'abc-123', | ||
|
||
format: 'dunno lol', // unsure what this value should be. It's not there at runtime, but it's in the ts interface | ||
}; | ||
|
||
export default azureMonitorQuery; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
public/app/plugins/datasource/grafana-azure-monitor-datasource/components/Field.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { InlineField } from '@grafana/ui'; | ||
import React from 'react'; | ||
import { Props as InlineFieldProps } from '@grafana/ui/src/components/Forms/InlineField'; | ||
|
||
const DEFAULT_LABEL_WIDTH = 18; | ||
|
||
export const Field = (props: InlineFieldProps) => { | ||
return <InlineField labelWidth={DEFAULT_LABEL_WIDTH} {...props} />; | ||
}; |
Oops, something went wrong.