Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Alerts tab in devconsole monitoring
- Loading branch information
1 parent
6bb23df
commit 77d7338
Showing
14 changed files
with
301 additions
and
47 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
32 changes: 32 additions & 0 deletions
32
frontend/packages/dev-console/src/components/monitoring/alerts/MonitoringRuleDetailsPage.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,32 @@ | ||
import * as React from 'react'; | ||
import { AlertRulesDetailsPage } from '@console/internal/components/monitoring/alerting'; | ||
import { history } from '@console/internal/components/utils'; | ||
import { ALL_NAMESPACES_KEY } from '@console/shared'; | ||
import NamespacedPage, { NamespacedPageVariants } from '../../NamespacedPage'; | ||
import { match as RMatch } from 'react-router-dom'; | ||
|
||
type MonitoringRuleDetailsPageProps = { | ||
match: RMatch<{ | ||
ns?: string; | ||
}>; | ||
}; | ||
|
||
const handleNamespaceChange = (ns: string): void => { | ||
ns === ALL_NAMESPACES_KEY | ||
? history.push('/dev-monitoring/all-namespaces') | ||
: history.push('/dev-monitoring/ns/:ns/alerts'); | ||
}; | ||
|
||
const MonitoringRuleDetailsPage: React.FC<MonitoringRuleDetailsPageProps> = ({ match }) => { | ||
return ( | ||
<NamespacedPage | ||
variant={NamespacedPageVariants.light} | ||
hideApplications | ||
onNamespaceChange={handleNamespaceChange} | ||
> | ||
<AlertRulesDetailsPage match={match} /> | ||
</NamespacedPage> | ||
); | ||
}; | ||
|
||
export default MonitoringRuleDetailsPage; |
5 changes: 5 additions & 0 deletions
5
frontend/packages/dev-console/src/components/monitoring/alerts/SilenceAlert.scss
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,5 @@ | ||
.odc-silence-alert { | ||
.pf-c-switch__label.pf-m-on { | ||
display: none; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
frontend/packages/dev-console/src/components/monitoring/alerts/SilenceAlert.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,51 @@ | ||
import * as React from 'react'; | ||
import * as _ from 'lodash'; | ||
import { Switch } from '@patternfly/react-core'; | ||
import { Rule } from '@console/internal/components/monitoring/types'; | ||
import { RuleStates } from '@console/internal/reducers/monitoring'; | ||
import { StateTimestamp } from '@console/internal/components/monitoring/alerting'; | ||
import SilenceDurationDropDown from './SilenceDurationDropdown'; | ||
import './SilenceAlert.scss'; | ||
|
||
type SilenceAlertProps = { | ||
rule: Rule; | ||
namespace: string; | ||
}; | ||
|
||
const SilenceUntil = ({ rule }) => { | ||
if (alert && !_.isEmpty(rule.silencedBy)) { | ||
return <StateTimestamp text="Until" timestamp={_.max(_.map(rule.silencedBy, 'endsAt'))} />; | ||
} | ||
return null; | ||
}; | ||
|
||
const SilenceAlert: React.FC<SilenceAlertProps> = ({ rule, namespace }) => { | ||
const [isChecked, setIsChecked] = React.useState(true); | ||
React.useEffect( | ||
() => (rule.state === RuleStates.Silenced ? setIsChecked(false) : setIsChecked(true)), | ||
[rule], | ||
); | ||
|
||
const handleChange = (checked: boolean) => { | ||
setIsChecked(checked); | ||
}; | ||
|
||
return ( | ||
<Switch | ||
aria-label="Silence switch" | ||
className="odc-silence-alert" | ||
label="On" | ||
labelOff={ | ||
rule.state === RuleStates.Silenced ? ( | ||
<SilenceUntil rule={rule} /> | ||
) : ( | ||
<SilenceDurationDropDown rule={rule} namespace={namespace} /> | ||
) | ||
} | ||
isChecked={isChecked} | ||
onChange={handleChange} | ||
/> | ||
); | ||
}; | ||
|
||
export default SilenceAlert; |
64 changes: 64 additions & 0 deletions
64
frontend/packages/dev-console/src/components/monitoring/alerts/SilenceDurationDropdown.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,64 @@ | ||
import * as React from 'react'; | ||
import * as _ from 'lodash'; | ||
// FIXME upgrading redux types is causing many errors at this time | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore | ||
// @ts-ignore | ||
import { useSelector } from 'react-redux'; | ||
import { Dropdown } from '@console/internal/components/utils'; | ||
import { RootState } from '@console/internal/redux'; | ||
import { parsePrometheusDuration } from '@console/internal/components/utils/datetime'; | ||
import { coFetchJSON } from '@console/internal/co-fetch'; | ||
import { Rule } from '@console/internal/components/monitoring/types'; | ||
|
||
type SilenceDurationDropDownProps = { | ||
rule: Rule; | ||
namespace: string; | ||
}; | ||
|
||
const SILENCE_FOR = 'Silence for '; | ||
const durations = [SILENCE_FOR, '30m', '1h', '2h', '6h', '12h', '1d', '2d', '1w']; | ||
const durationItems = _.zipObject(durations, durations); | ||
const { alertManagerBaseURL } = window.SERVER_FLAGS; | ||
|
||
const SilenceDurationDropDown: React.FC<SilenceDurationDropDownProps> = ({ rule, namespace }) => { | ||
const createdBy = useSelector((state: RootState) => state.UI.get('user')?.metadata?.name); | ||
|
||
const matchers = [ | ||
{ | ||
isRegex: false, | ||
name: 'alertname', | ||
value: rule.name, | ||
}, | ||
{ | ||
isRegex: false, | ||
name: 'namespace', | ||
value: namespace, | ||
}, | ||
]; | ||
|
||
const setDuration = (duration: string) => { | ||
const startsAt = new Date(); | ||
const endsAt = new Date(startsAt.getTime() + parsePrometheusDuration(duration)); | ||
|
||
const payload = { | ||
createdBy, | ||
endsAt: endsAt.toISOString(), | ||
startsAt: startsAt.toISOString(), | ||
matchers, | ||
comment: '', | ||
}; | ||
|
||
coFetchJSON.post(`${alertManagerBaseURL}/api/v2/silences`, payload); | ||
}; | ||
|
||
return ( | ||
<Dropdown | ||
dropDownClassName="dropdown--full-width" | ||
items={durationItems} | ||
onChange={(v: string) => setDuration(v)} | ||
selectedKey={SILENCE_FOR} | ||
/> | ||
); | ||
}; | ||
|
||
export default SilenceDurationDropDown; |
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
Oops, something went wrong.