Compare commits

..
Author SHA1 Message Date
Torkel Ödegaard d666c4e2a7 Update 2025-12-18 17:11:01 +01:00
Torkel Ödegaard 5012b4079e Dashboards: Do not show alert rules button for new dashboads 2025-12-18 16:19:33 +01:00
Andreas Christou f1b19dd9fa ElasticSearch: Update annotation time-range properties (#115500)
Update time-range properties
2025-12-18 14:38:15 +00:00
Marc M. 4fbcebac2c Deps: Upgrade Scenes to v6.51.0 (#115547)
Scenes: Upgrade to v6.51.0
2025-12-18 15:01:04 +01:00
Alexander Akhmetov 5c7cdabaa3 Alerting: Improve performance of rule list view with limit_alerts=0 (#115548)
Alerting: Improve performance of rule list view
2025-12-18 14:58:39 +01:00
Kevin Minehart 39fa6559ee CI: Remove the default alpine & ubuntu versions so that the ones in Dockerfile (#115544)
* Remove the default alpine & ubuntu versions so that the ones in Dockerfile are used

* set default to just 'alpine' or 'ubuntu'

* use defaults instead
2025-12-18 14:46:24 +01:00
12 changed files with 46 additions and 189 deletions
+1 -11
View File
@@ -82,14 +82,6 @@ inputs:
description: Docker registry of produced images
default: docker.io
required: false
ubuntu-base:
type: string
default: 'ubuntu:22.04'
required: false
alpine-base:
type: string
default: 'alpine:3.22'
required: false
outputs:
dist-dir:
description: Directory where artifacts are placed
@@ -134,13 +126,11 @@ runs:
UBUNTU_TAG_FORMAT: ${{ inputs.docker-tag-format-ubuntu }}
CHECKSUM: ${{ inputs.checksum }}
VERIFY: ${{ inputs.verify }}
ALPINE_BASE: ${{ inputs.alpine-base }}
UBUNTU_BASE: ${{ inputs.ubuntu-base }}
with:
verb: run
dagger-flags: --verbose=0
version: 0.18.8
args: go run -C ${GRAFANA_PATH} ./pkg/build/cmd artifacts --artifacts ${ARTIFACTS} --grafana-dir=${GRAFANA_PATH} --alpine-base=${ALPINE_BASE} --ubuntu-base=${UBUNTU_BASE} --enterprise-dir=${ENTERPRISE_PATH} --version=${VERSION} --patches-repo=${PATCHES_REPO} --patches-ref=${PATCHES_REF} --patches-path=${PATCHES_PATH} --build-id=${BUILD_ID} --tag-format="${TAG_FORMAT}" --ubuntu-tag-format="${UBUNTU_TAG_FORMAT}" --org=${DOCKER_ORG} --registry=${DOCKER_REGISTRY} --checksum=${CHECKSUM} --verify=${VERIFY} > $OUTFILE
args: go run -C ${GRAFANA_PATH} ./pkg/build/cmd artifacts --artifacts ${ARTIFACTS} --grafana-dir=${GRAFANA_PATH} --enterprise-dir=${ENTERPRISE_PATH} --version=${VERSION} --patches-repo=${PATCHES_REPO} --patches-ref=${PATCHES_REF} --patches-path=${PATCHES_PATH} --build-id=${BUILD_ID} --tag-format="${TAG_FORMAT}" --ubuntu-tag-format="${UBUNTU_TAG_FORMAT}" --org=${DOCKER_ORG} --registry=${DOCKER_REGISTRY} --checksum=${CHECKSUM} --verify=${VERIFY} > $OUTFILE
- id: output
shell: bash
env:
+2 -2
View File
@@ -295,8 +295,8 @@
"@grafana/plugin-ui": "^0.11.1",
"@grafana/prometheus": "workspace:*",
"@grafana/runtime": "workspace:*",
"@grafana/scenes": "6.50.0",
"@grafana/scenes-react": "6.50.0",
"@grafana/scenes": "^6.51.0",
"@grafana/scenes-react": "^6.51.0",
"@grafana/schema": "workspace:*",
"@grafana/sql": "workspace:*",
"@grafana/ui": "workspace:*",
@@ -357,7 +357,7 @@ func (srv PrometheusSrv) RouteGetRuleStatuses(c *contextmodel.ReqContext) respon
type RuleStatusMutator func(source *ngmodels.AlertRule, toMutate *apimodels.AlertingRule)
// mutator function used to attach alert states to the rule and returns the totals and filtered totals
type RuleAlertStateMutator func(source *ngmodels.AlertRule, toMutate *apimodels.AlertingRule, stateFilterSet map[eval.State]struct{}, matchers labels.Matchers, labelOptions []ngmodels.LabelOption) (total map[string]int64, filteredTotal map[string]int64)
type RuleAlertStateMutator func(source *ngmodels.AlertRule, toMutate *apimodels.AlertingRule, stateFilterSet map[eval.State]struct{}, matchers labels.Matchers, labelOptions []ngmodels.LabelOption, limitAlerts int64) (total map[string]int64, filteredTotal map[string]int64)
func RuleStatusMutatorGenerator(statusReader StatusReader) RuleStatusMutator {
return func(source *ngmodels.AlertRule, toMutate *apimodels.AlertingRule) {
@@ -377,32 +377,18 @@ func RuleStatusMutatorGenerator(statusReader StatusReader) RuleStatusMutator {
}
func RuleAlertStateMutatorGenerator(manager state.AlertInstanceManager) RuleAlertStateMutator {
return func(source *ngmodels.AlertRule, toMutate *apimodels.AlertingRule, stateFilterSet map[eval.State]struct{}, matchers labels.Matchers, labelOptions []ngmodels.LabelOption) (map[string]int64, map[string]int64) {
return func(source *ngmodels.AlertRule, toMutate *apimodels.AlertingRule, stateFilterSet map[eval.State]struct{}, matchers labels.Matchers, labelOptions []ngmodels.LabelOption, limitAlerts int64) (map[string]int64, map[string]int64) {
states := manager.GetStatesForRuleUID(source.OrgID, source.UID)
totals := make(map[string]int64)
totalsFiltered := make(map[string]int64)
for _, alertState := range states {
activeAt := alertState.StartsAt
valString := ""
if alertState.State == eval.Alerting || alertState.State == eval.Pending || alertState.State == eval.Recovering {
valString = FormatValues(alertState)
}
stateKey := strings.ToLower(alertState.State.String())
totals[stateKey] += 1
// Do not add error twice when execution error state is Error
if alertState.Error != nil && source.ExecErrState != ngmodels.ErrorErrState {
totals["error"] += 1
}
alert := apimodels.Alert{
Labels: apimodels.LabelsFromMap(alertState.GetLabels(labelOptions...)),
Annotations: apimodels.LabelsFromMap(alertState.Annotations),
// TODO: or should we make this two fields? Using one field lets the
// frontend use the same logic for parsing text on annotations and this.
State: state.FormatStateAndReason(alertState.State, alertState.StateReason),
ActiveAt: &activeAt,
Value: valString,
}
// Set the state of the rule based on the state of its alerts.
// Only update the rule state with 'pending' or 'recovering' if the current state is 'inactive'.
@@ -442,7 +428,23 @@ func RuleAlertStateMutatorGenerator(manager state.AlertInstanceManager) RuleAler
totalsFiltered["error"] += 1
}
toMutate.Alerts = append(toMutate.Alerts, alert)
if limitAlerts != 0 {
valString := ""
if alertState.State == eval.Alerting || alertState.State == eval.Pending || alertState.State == eval.Recovering {
valString = FormatValues(alertState)
}
toMutate.Alerts = append(toMutate.Alerts, apimodels.Alert{
Labels: apimodels.LabelsFromMap(alertState.GetLabels(labelOptions...)),
Annotations: apimodels.LabelsFromMap(alertState.Annotations),
// TODO: or should we make this two fields? Using one field lets the
// frontend use the same logic for parsing text on annotations and this.
State: state.FormatStateAndReason(alertState.State, alertState.StateReason),
ActiveAt: &activeAt,
Value: valString,
})
}
}
return totals, totalsFiltered
}
@@ -1227,7 +1229,7 @@ func toRuleGroup(log log.Logger, groupKey ngmodels.AlertRuleGroupKey, folderFull
}
// mutate rule for alert states
totals, totalsFiltered := ruleAlertStateMutator(rule, &alertingRule, stateFilterSet, matchers, labelOptions)
totals, totalsFiltered := ruleAlertStateMutator(rule, &alertingRule, stateFilterSet, matchers, labelOptions, limitAlerts)
if alertingRule.State != "" {
rulesTotals[alertingRule.State] += 1
@@ -22,7 +22,7 @@ export function initAlerting() {
component: ({ dashboard }) =>
alertingEnabled ? (
<Suspense fallback={null} key="alert-rules-button">
{dashboard && <AlertRulesToolbarButton dashboardUid={dashboard.uid} />}
{dashboard && dashboard.uid && <AlertRulesToolbarButton dashboardUid={dashboard.uid} />}
</Suspense>
) : null,
index: -2,
@@ -76,12 +76,6 @@ export function DashboardEditPaneRenderer({ editPane, dashboard, isDocked }: Pro
data-testid={selectors.pages.Dashboard.Sidebar.optionsButton}
active={selectedObject === dashboard ? true : false}
/>
{/* <Sidebar.Button
tooltip={t('dashboard.sidebar.edit-schema.tooltip', 'Edit as code')}
title={t('dashboard.sidebar.edit-schema.title', 'Code')}
icon="brackets-curly"
onClick={() => dashboard.openV2SchemaEditor()}
/> */}
<Sidebar.Divider />
</>
)}
@@ -1,110 +0,0 @@
import { screen } from '@testing-library/react';
import { render } from 'test/test-utils';
import { getPanelPlugin } from '@grafana/data/test';
import { setPluginImportUtils } from '@grafana/runtime';
import { SceneGridLayout, SceneTimeRange, VizPanel } from '@grafana/scenes';
import { DashboardScene } from '../scene/DashboardScene';
import { AutoGridItem } from '../scene/layout-auto-grid/AutoGridItem';
import { AutoGridLayout } from '../scene/layout-auto-grid/AutoGridLayout';
import { AutoGridLayoutManager } from '../scene/layout-auto-grid/AutoGridLayoutManager';
import { DashboardGridItem } from '../scene/layout-default/DashboardGridItem';
import { DefaultGridLayoutManager } from '../scene/layout-default/DefaultGridLayoutManager';
import { activateFullSceneTree } from '../utils/test-utils';
import { ShareLibraryPanelTab } from './ShareLibraryPanelTab';
jest.mock('app/features/dashboard/components/ShareModal/ShareLibraryPanel', () => ({
// eslint-disable-next-line react/display-name
ShareLibraryPanel: ({ panel }: { panel: { title: string } }) => (
<div data-testid="share-library-panel">panel-title:{panel.title}</div>
),
}));
setPluginImportUtils({
importPanelPlugin: () => Promise.resolve(getPanelPlugin({})),
getPanelPluginFromCache: () => undefined,
});
describe('ShareLibraryPanelTab', () => {
it('renders library panel content for auto grid panels', () => {
const { tab } = setupAutoGridScenario();
render(<tab.Component model={tab} />);
expect(screen.getByTestId('share-library-panel')).toHaveTextContent('panel-title:Auto panel');
});
it('renders library panel content for default grid panels', () => {
const { tab } = setupDefaultGridScenario();
render(<tab.Component model={tab} />);
expect(screen.getByTestId('share-library-panel')).toHaveTextContent('panel-title:Default panel');
});
});
function setupAutoGridScenario() {
const vizPanel = new VizPanel({
key: 'panel-1',
pluginId: 'table',
title: 'Auto panel',
});
const autoGridItem = new AutoGridItem({
key: 'auto-grid-item-1',
body: vizPanel,
});
const layoutManager = new AutoGridLayoutManager({
layout: new AutoGridLayout({ children: [autoGridItem] }),
});
const tab = new ShareLibraryPanelTab({
panelRef: vizPanel.getRef(),
});
const dashboard = new DashboardScene({
title: 'Dash',
uid: 'dash-1',
meta: { canEdit: true },
$timeRange: new SceneTimeRange({}),
body: layoutManager,
overlay: tab,
});
activateFullSceneTree(dashboard);
return { tab, dashboard };
}
function setupDefaultGridScenario() {
const vizPanel = new VizPanel({
key: 'panel-1',
pluginId: 'table',
title: 'Default panel',
});
const gridItem = new DashboardGridItem({
key: 'grid-item-1',
body: vizPanel,
});
const tab = new ShareLibraryPanelTab({
panelRef: vizPanel.getRef(),
});
const dashboard = new DashboardScene({
title: 'Dash',
uid: 'dash-1',
meta: { canEdit: true },
$timeRange: new SceneTimeRange({}),
body: new DefaultGridLayoutManager({ grid: new SceneGridLayout({ children: [gridItem] }) }),
overlay: tab,
});
activateFullSceneTree(dashboard);
return { tab, dashboard };
}
@@ -6,13 +6,8 @@ import { shareDashboardType } from 'app/features/dashboard/components/ShareModal
import { DashboardModel } from 'app/features/dashboard/state/DashboardModel';
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
import { AutoGridItem } from '../scene/layout-auto-grid/AutoGridItem';
import { DashboardGridItem } from '../scene/layout-default/DashboardGridItem';
import {
gridItemToPanel,
transformSceneToSaveModel,
vizPanelToPanel,
} from '../serialization/transformSceneToSaveModel';
import { gridItemToPanel, transformSceneToSaveModel } from '../serialization/transformSceneToSaveModel';
import { getDashboardSceneFor } from '../utils/utils';
import { SceneShareTabState } from './types';
@@ -40,10 +35,9 @@ function ShareLibraryPanelTabRenderer({ model }: SceneComponentProps<ShareLibrar
const panel = panelRef.resolve();
const parent = panel.parent;
if (parent instanceof DashboardGridItem || parent instanceof AutoGridItem) {
if (parent instanceof DashboardGridItem) {
const dashboardScene = getDashboardSceneFor(model);
const panelJson =
parent instanceof DashboardGridItem ? gridItemToPanel(parent) : autoGridItemToLibraryPanel(parent);
const panelJson = gridItemToPanel(parent);
const panelModel = new PanelModel(panelJson);
const dashboardJson = transformSceneToSaveModel(dashboardScene);
@@ -64,12 +58,3 @@ function ShareLibraryPanelTabRenderer({ model }: SceneComponentProps<ShareLibrar
return null;
}
function autoGridItemToLibraryPanel(autoGridItem: AutoGridItem) {
const vizPanel = autoGridItem.state.body;
if (!(vizPanel instanceof VizPanel)) {
throw new Error('AutoGridItem body expected to be VizPanel');
}
return vizPanelToPanel(vizPanel, { x: 0, y: 0, w: 6, h: 3 }, false, autoGridItem);
}
@@ -1000,7 +1000,7 @@ describe('ElasticDatasource', () => {
});
expect(postResourceRequestMock).toHaveBeenCalledWith(
'_msearch',
'{"search_type":"query_then_fetch","ignore_unavailable":true,"index":"[test-]YYYY.MM.DD"}\n{"query":{"bool":{"filter":[{"bool":{"should":[{"range":{"@test_time":{"from":1683291160012,"to":1683291460012,"format":"epoch_millis"}}},{"range":{"@time_end_field":{"from":1683291160012,"to":1683291460012,"format":"epoch_millis"}}}],"minimum_should_match":1}},{"query_string":{"query":"abc"}}]}},"size":10000}\n'
'{"search_type":"query_then_fetch","ignore_unavailable":true,"index":"[test-]YYYY.MM.DD"}\n{"query":{"bool":{"filter":[{"bool":{"should":[{"range":{"@test_time":{"gte":1683291160012,"lte":1683291460012,"format":"epoch_millis"}}},{"range":{"@time_end_field":{"gte":1683291160012,"lte":1683291460012,"format":"epoch_millis"}}}],"minimum_should_match":1}},{"query_string":{"query":"abc"}}]}},"size":10000}\n'
);
});
@@ -1030,7 +1030,7 @@ describe('ElasticDatasource', () => {
});
expect(postResourceRequestMock).toHaveBeenCalledWith(
'_msearch',
'{"search_type":"query_then_fetch","ignore_unavailable":true,"index":"[test-]YYYY.MM.DD"}\n{"query":{"bool":{"filter":[{"bool":{"should":[{"range":{"@timestamp":{"from":1683291160012,"to":1683291460012,"format":"epoch_millis"}}}],"minimum_should_match":1}}]}},"size":10000}\n'
'{"search_type":"query_then_fetch","ignore_unavailable":true,"index":"[test-]YYYY.MM.DD"}\n{"query":{"bool":{"filter":[{"bool":{"should":[{"range":{"@timestamp":{"gte":1683291160012,"lte":1683291460012,"format":"epoch_millis"}}}],"minimum_should_match":1}}]}},"size":10000}\n'
);
});
@@ -1087,7 +1087,7 @@ describe('ElasticDatasource', () => {
});
expect(postResourceRequestMock).toHaveBeenCalledWith(
'_msearch',
'{"search_type":"query_then_fetch","ignore_unavailable":true,"index":"[test-]YYYY.MM.DD"}\n{"query":{"bool":{"filter":[{"bool":{"should":[{"range":{"@test_time":{"from":1683291160012,"to":1683291460012,"format":"epoch_millis"}}},{"range":{"@time_end_field":{"from":1683291160012,"to":1683291460012,"format":"epoch_millis"}}}],"minimum_should_match":1}},{"query_string":{"query":"abc AND abc_key:\\"abc_value\\""}}]}},"size":10000}\n'
'{"search_type":"query_then_fetch","ignore_unavailable":true,"index":"[test-]YYYY.MM.DD"}\n{"query":{"bool":{"filter":[{"bool":{"should":[{"range":{"@test_time":{"gte":1683291160012,"lte":1683291460012,"format":"epoch_millis"}}},{"range":{"@time_end_field":{"gte":1683291160012,"lte":1683291460012,"format":"epoch_millis"}}}],"minimum_should_match":1}},{"query_string":{"query":"abc AND abc_key:\\"abc_value\\""}}]}},"size":10000}\n'
);
});
});
@@ -294,8 +294,8 @@ export class ElasticDatasource
const dateRanges = [];
const rangeStart: RangeMap = {};
rangeStart[timeField] = {
from: options.range.from.valueOf(),
to: options.range.to.valueOf(),
gte: options.range.from.valueOf(),
lte: options.range.to.valueOf(),
format: 'epoch_millis',
};
dateRanges.push({ range: rangeStart });
@@ -303,8 +303,8 @@ export class ElasticDatasource
if (timeEndField) {
const rangeEnd: RangeMap = {};
rangeEnd[timeEndField] = {
from: options.range.from.valueOf(),
to: options.range.to.valueOf(),
gte: options.range.from.valueOf(),
lte: options.range.to.valueOf(),
format: 'epoch_millis',
};
dateRanges.push({ range: rangeEnd });
@@ -137,7 +137,7 @@ export interface ElasticsearchAnnotationQuery {
index?: string;
}
export type RangeMap = Record<string, { from: number; to: number; format: string }>;
export type RangeMap = Record<string, { gte: number; lte: number; format: string }>;
export type ElasticsearchResponse = ElasticsearchResponseWithHits | ElasticsearchResponseWithAggregations;
-4
View File
@@ -5392,10 +5392,6 @@
"title": "Options",
"tooltip": "Dashboard options"
},
"edit-schema": {
"title": "Code",
"tooltip": "Edit as code"
},
"export": {
"title": "Export",
"unsaved-modal": {
+11 -11
View File
@@ -3604,11 +3604,11 @@ __metadata:
languageName: unknown
linkType: soft
"@grafana/scenes-react@npm:6.50.0":
version: 6.50.0
resolution: "@grafana/scenes-react@npm:6.50.0"
"@grafana/scenes-react@npm:^6.51.0":
version: 6.51.0
resolution: "@grafana/scenes-react@npm:6.51.0"
dependencies:
"@grafana/scenes": "npm:6.50.0"
"@grafana/scenes": "npm:6.51.0"
lru-cache: "npm:^10.2.2"
react-use: "npm:^17.4.0"
peerDependencies:
@@ -3620,7 +3620,7 @@ __metadata:
react: ^18.0.0
react-dom: ^18.0.0
react-router-dom: ^6.28.0
checksum: 10/9ac9f8a32699f447c7b67dd2aef4e3ca5bc9fc98e94e0dc139e7824274ffa005b7fb3fc42ca5e55bdf89b91e3af0d3807b03e1a261db91c65717ee1763e5e807
checksum: 10/14acdfe5220e67e7450780320b779e2e4a255995d55f0c82eb0d25933e72598e54826df0a8beee05591efe01a91ddab840483fea3bb828bd5925c3f0b44b8d17
languageName: node
linkType: hard
@@ -3650,9 +3650,9 @@ __metadata:
languageName: node
linkType: hard
"@grafana/scenes@npm:6.50.0":
version: 6.50.0
resolution: "@grafana/scenes@npm:6.50.0"
"@grafana/scenes@npm:6.51.0, @grafana/scenes@npm:^6.51.0":
version: 6.51.0
resolution: "@grafana/scenes@npm:6.51.0"
dependencies:
"@floating-ui/react": "npm:^0.26.16"
"@leeoniya/ufuzzy": "npm:^1.0.16"
@@ -3672,7 +3672,7 @@ __metadata:
react: ^18.0.0
react-dom: ^18.0.0
react-router-dom: ^6.28.0
checksum: 10/7bc6280ff065bbba37f010e2a1f0a7dc998fe43721ddc0121e27a754c41e824b82a44222100282a69143a52061cf0dce39e6bc8b95292ca444a59c114d4b5a41
checksum: 10/4e4f43babe786ff729d58b7636182df57c58ce40c13b56036f725c070e0cf597cbe52aaa0f811184b8d42d8d1f9a32679695471d410f883051b09da44f8bf36a
languageName: node
linkType: hard
@@ -19508,8 +19508,8 @@ __metadata:
"@grafana/plugin-ui": "npm:^0.11.1"
"@grafana/prometheus": "workspace:*"
"@grafana/runtime": "workspace:*"
"@grafana/scenes": "npm:6.50.0"
"@grafana/scenes-react": "npm:6.50.0"
"@grafana/scenes": "npm:^6.51.0"
"@grafana/scenes-react": "npm:^6.51.0"
"@grafana/schema": "workspace:*"
"@grafana/sql": "workspace:*"
"@grafana/test-utils": "workspace:*"