Skip to content

Commit

Permalink
DEV-46517 Grafana 10 alerting groups the url to see source is not wor…
Browse files Browse the repository at this point in the history
…king (#57)
  • Loading branch information
copyhold authored Oct 14, 2024
1 parent 3e0eb81 commit 8cf26e2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 17 deletions.
32 changes: 27 additions & 5 deletions public/app/core/components/SharedPreferences/SharedPreferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { LANGUAGES } from 'app/core/internationalization/constants';
import { PreferencesService } from 'app/core/services/PreferencesService';
import { backendSrv } from "app/core/services/backend_srv";// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
import { changeTheme } from 'app/core/services/theme';
import { DashboardSearchItem } from 'app/features/search/types';

export interface Props {
resourceUri: string;
Expand All @@ -30,7 +31,7 @@ export interface Props {
onConfirm?: () => Promise<boolean>;
}

export type State = UserPreferencesDTO;
export type State = UserPreferencesDTO & { homeDashboardId?: number; dashboards: Array<DashboardSearchItem & {id?: number}>}; // LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard

function getLanguageOptions(): Array<SelectableValue<string>> {
const languageOptions = LANGUAGES.map((v) => ({
Expand Down Expand Up @@ -63,6 +64,7 @@ export class SharedPreferences extends PureComponent<Props, State> {
weekStart: '',
language: '',
queryHistory: { homeTab: '' },
dashboards: [],
};

this.themeOptions = getBuiltInThemes(config.featureToggles.extraThemes).map((theme) => ({
Expand All @@ -75,16 +77,35 @@ export class SharedPreferences extends PureComponent<Props, State> {
}

async componentDidMount() {
const prefs = await backendSrv.get(`/api/${this.props.resourceUri.toLowerCase()}/preferences`);// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
const prefs = await backendSrv.get(`/api/${this.props.resourceUri.toLowerCase()}/preferences`);
const dashboards = await backendSrv.search({ starred: true });
//
// this.setState({
// homeDashboardUID: prefs.homeDashboardUID,
// theme: prefs.theme,
// timezone: prefs.timezone,
// weekStart: prefs.weekStart,
// language: prefs.language,
// queryHistory: prefs.queryHistory,
// });

if (prefs.homeDashboardId > 0 && !dashboards.find((d) => d.id === prefs.homeDashboardId)) {
const missing = await backendSrv.search({ dashboardIds: [prefs.homeDashboardId] });
if (missing && missing.length > 0) {
dashboards.push(missing[0]);
}
}

this.setState({
homeDashboardId: prefs.homeDashboardId,
homeDashboardUID: prefs.homeDashboardUID,
theme: prefs.theme,
timezone: prefs.timezone,
weekStart: prefs.weekStart,
language: prefs.language,
queryHistory: prefs.queryHistory,
dashboards,
});
// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Remove default dashboard end
}

onSubmitForm = async (event: React.FormEvent<HTMLFormElement>) => {
Expand All @@ -94,8 +115,9 @@ export class SharedPreferences extends PureComponent<Props, State> {
if (confirmationResult) {
// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
const { homeDashboardUID, theme, timezone } = this.state;
const homeDashboard = this.state.dashboards.find(d => d.uid === homeDashboardUID);
await backendSrv.put(`/api/${this.props.resourceUri.toLowerCase()}/preferences`, {
homeDashboardId: homeDashboardUID,
homeDashboardId: homeDashboard?.id || null,
theme,
timezone,
});
Expand Down
2 changes: 1 addition & 1 deletion public/app/core/services/backend_srv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export class BackendSrv implements BackendService {
}

/** @deprecated */
search(query: any): Promise<DashboardSearchItem[]> {
search(query: any): Promise<Array<DashboardSearchItem & {id?: number}>> { // LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
return this.get('/api/search', query);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ import { RuleEditorSection } from '../RuleEditorSection';
import { errorFromCurrentCondition, errorFromPreviewData, findRenamedDataQueryReferences, refIdExists } from '../util';

import { CloudDataSourceSelector } from './CloudDataSourceSelector';
// LOGZ.IO CHANGE :: DEV-46521 remove rule type switch
// import { SmartAlertTypeDetector } from './SmartAlertTypeDetector';
import { SmartAlertTypeDetector } from './SmartAlertTypeDetector';
import { DESCRIPTIONS } from './descriptions';
import {
addExpressions,
Expand Down Expand Up @@ -371,7 +370,7 @@ export const QueryAndExpressionsStep = ({ editingExistingRule, onDataChange }: P
removeExpressionsInQueries,
condition,
]);

const { sectionTitle, helpLabel, helpContent, helpLink } = DESCRIPTIONS[type ?? RuleFormType.grafana];

return (
Expand Down Expand Up @@ -432,14 +431,12 @@ export const QueryAndExpressionsStep = ({ editingExistingRule, onDataChange }: P
}}
/>
</Field>
{/*
// LOGZ.IO CHANGE :: DEV-46521 remove rule type switch
<SmartAlertTypeDetector
editingExistingRule={editingExistingRule}
queries={queries}
rulesSourcesWithRuler={rulesSourcesWithRuler}
onClickSwitch={onClickSwitch}
/> */}
/>
</Stack>
)}

Expand Down Expand Up @@ -471,14 +468,18 @@ export const QueryAndExpressionsStep = ({ editingExistingRule, onDataChange }: P
Add query
</Button>
</Tooltip>
{/*
// LOGZ.IO CHANGE :: DEV-46521 remove rule type switch
<SmartAlertTypeDetector
editingExistingRule={editingExistingRule}
rulesSourcesWithRuler={rulesSourcesWithRuler}
queries={queries}
onClickSwitch={onClickSwitch}
/> */}
/>
<SmartAlertTypeDetector
editingExistingRule={editingExistingRule}
rulesSourcesWithRuler={rulesSourcesWithRuler}
queries={queries}
onClickSwitch={onClickSwitch}
/>
{/* Expression Queries */}
<Stack direction="column" gap={0}>
<Text element="h5">Expressions</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export function SmartAlertTypeDetector({
// if we can't switch to data-source managed, disable it
// TODO figure out how to show a popover to the user to indicate _why_ it's disabled
const disabledOptions = canSwitch ? [] : [RuleFormType.cloudAlerting];

return null;

return (
<Stack direction="column" gap={1} alignItems="flex-start">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ interface PluginBridgeHookResponse {
}

export function usePluginBridge(plugin: PluginID): PluginBridgeHookResponse {
const { loading, error, value } = useAsync(() => getPluginSettings(plugin, { showErrorAlert: false }));
// LOGZ.IO CHANGE :: DEV-46522 disable the oncall grafana plugin
if (plugin === SupportedPlugin.OnCall) {
return { loading: false, installed: false};
}
// LOGZ.IO CHANGE :: DEV-46522 disable the oncall grafana plugin. END
const { loading, error, value } = useAsync(() => getPluginSettings(plugin, { showErrorAlert: false }));

const installed = value && !error && !loading;
const enabled = value?.enabled;
const isLoading = loading && !value;
Expand Down
7 changes: 7 additions & 0 deletions public/app/plugins/panel/alertGroups/AlertGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export const AlertGroup = ({ alertManagerSourceName, group, expandAll }: Props)
start: new Date(alert.startsAt),
end: Date.now(),
});

// LOGZ.IO CHANGE :: DEV-46517 - fix "see source button"
if (alert.generatorURL) {
const url = new URL(alert.generatorURL);
alert.generatorURL = url.hash.replace(/^#/, '/grafana-app');
}
// LOGZ.IO CHANGE :: DEV-46517 - fix "see source button" end

return (
<div data-testid={'alert-group-alert'} className={styles.alert} key={`${alert.fingerprint}-${index}`}>
Expand Down

0 comments on commit 8cf26e2

Please sign in to comment.