mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix explore link in alert detail view (#66106)
This commit is contained in:
parent
3e12b72f58
commit
cb8a5b2c96
@ -44,47 +44,51 @@ export function GrafanaRuleQueryViewer({
|
|||||||
const dsByUid = keyBy(Object.values(config.datasources), (ds) => ds.uid);
|
const dsByUid = keyBy(Object.values(config.datasources), (ds) => ds.uid);
|
||||||
const dataQueries = queries.filter((q) => !isExpressionQuery(q.model));
|
const dataQueries = queries.filter((q) => !isExpressionQuery(q.model));
|
||||||
const expressions = queries.filter((q) => isExpressionQuery(q.model));
|
const expressions = queries.filter((q) => isExpressionQuery(q.model));
|
||||||
|
const styles = useStyles2(getExpressionViewerStyles);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap={2} direction="column">
|
<Stack gap={2} direction="column">
|
||||||
<Stack gap={2}>
|
<div className={styles.maxWidthContainer}>
|
||||||
{dataQueries.map(({ model, relativeTimeRange, refId, datasourceUid }, index) => {
|
<Stack gap={2}>
|
||||||
const dataSource = dsByUid[datasourceUid];
|
{dataQueries.map(({ model, relativeTimeRange, refId, datasourceUid }, index) => {
|
||||||
|
const dataSource = dsByUid[datasourceUid];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QueryPreview
|
<QueryPreview
|
||||||
key={index}
|
|
||||||
refId={refId}
|
|
||||||
isAlertCondition={condition === refId}
|
|
||||||
model={model}
|
|
||||||
relativeTimeRange={relativeTimeRange}
|
|
||||||
evalTimeRange={evalTimeRanges[refId]}
|
|
||||||
dataSource={dataSource}
|
|
||||||
queryData={evalDataByQuery[refId]}
|
|
||||||
onEvalTimeRangeChange={(timeRange) => onTimeRangeChange(refId, timeRange)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</Stack>
|
|
||||||
|
|
||||||
<Stack gap={1}>
|
|
||||||
{expressions.map(({ model, relativeTimeRange, refId, datasourceUid }, index) => {
|
|
||||||
const dataSource = dsByUid[datasourceUid];
|
|
||||||
|
|
||||||
return (
|
|
||||||
isExpressionQuery(model) && (
|
|
||||||
<ExpressionPreview
|
|
||||||
key={index}
|
key={index}
|
||||||
refId={refId}
|
refId={refId}
|
||||||
isAlertCondition={condition === refId}
|
isAlertCondition={condition === refId}
|
||||||
model={model}
|
model={model}
|
||||||
|
relativeTimeRange={relativeTimeRange}
|
||||||
|
evalTimeRange={evalTimeRanges[refId]}
|
||||||
dataSource={dataSource}
|
dataSource={dataSource}
|
||||||
evalData={evalDataByQuery[refId]}
|
queryData={evalDataByQuery[refId]}
|
||||||
|
onEvalTimeRangeChange={(timeRange) => onTimeRangeChange(refId, timeRange)}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
);
|
})}
|
||||||
})}
|
</Stack>
|
||||||
</Stack>
|
</div>
|
||||||
|
<div className={styles.maxWidthContainer}>
|
||||||
|
<Stack gap={1}>
|
||||||
|
{expressions.map(({ model, refId, datasourceUid }, index) => {
|
||||||
|
const dataSource = dsByUid[datasourceUid];
|
||||||
|
|
||||||
|
return (
|
||||||
|
isExpressionQuery(model) && (
|
||||||
|
<ExpressionPreview
|
||||||
|
key={index}
|
||||||
|
refId={refId}
|
||||||
|
isAlertCondition={condition === refId}
|
||||||
|
model={model}
|
||||||
|
dataSource={dataSource}
|
||||||
|
evalData={evalDataByQuery[refId]}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Stack>
|
||||||
|
</div>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -389,6 +393,9 @@ const getExpressionViewerStyles = (theme: GrafanaTheme2) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...common,
|
...common,
|
||||||
|
maxWidthContainer: css`
|
||||||
|
max-width: 100%;
|
||||||
|
`,
|
||||||
container: css`
|
container: css`
|
||||||
padding: ${theme.spacing(1)};
|
padding: ${theme.spacing(1)};
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -141,12 +141,19 @@ export function RuleViewerVisualization({
|
|||||||
function createExploreLink(settings: DataSourceInstanceSettings, model: AlertDataQuery): string {
|
function createExploreLink(settings: DataSourceInstanceSettings, model: AlertDataQuery): string {
|
||||||
const { name } = settings;
|
const { name } = settings;
|
||||||
const { refId, ...rest } = model;
|
const { refId, ...rest } = model;
|
||||||
const queryParams = { ...rest, datasource: name };
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
In my testing I've found some alerts that don't have a data source embedded inside the model.
|
||||||
|
|
||||||
|
At this moment in time it is unclear to me why some alert definitions not have a data source embedded in the model.
|
||||||
|
Ideally we'd resolve the datasource name to the proper datasource Ref "{ type: string, uid: string }" and pass that in to the model.
|
||||||
|
|
||||||
|
I don't think that should happen here, the fact that the datasource ref is sometimes missing here is a symptom of another cause. (Gilles)
|
||||||
|
*/
|
||||||
return urlUtil.renderUrl(`${config.appSubUrl}/explore`, {
|
return urlUtil.renderUrl(`${config.appSubUrl}/explore`, {
|
||||||
left: JSON.stringify({
|
left: JSON.stringify({
|
||||||
datasource: name,
|
datasource: name,
|
||||||
queries: [{ refId: 'A', ...queryParams }],
|
queries: [{ refId: 'A', ...rest }],
|
||||||
range: { from: 'now-1h', to: 'now' },
|
range: { from: 'now-1h', to: 'now' },
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user