New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Notifications coloumn in alerts table #5943
Merged
openshift-merge-robot
merged 2 commits into
openshift:master
from
vikram-raj:alerts-silence
Jul 27, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
55 changes: 55 additions & 0 deletions
55
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,55 @@ | ||
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 { coFetchJSON } from '@console/internal/co-fetch'; | ||
import SilenceDurationDropDown from './SilenceDurationDropdown'; | ||
|
||
type SilenceAlertProps = { | ||
rule: Rule; | ||
}; | ||
|
||
const { alertManagerBaseURL } = window.SERVER_FLAGS; | ||
|
||
const SilenceUntil = ({ rule }) => { | ||
if (!_.isEmpty(rule.silencedBy)) { | ||
return <StateTimestamp text="Until" timestamp={_.max(_.map(rule.silencedBy, 'endsAt'))} />; | ||
} | ||
return null; | ||
}; | ||
|
||
const SilenceAlert: React.FC<SilenceAlertProps> = ({ rule }) => { | ||
const [isChecked, setIsChecked] = React.useState(rule.state !== RuleStates.Silenced); | ||
const [ruleState] = React.useState(rule); | ||
React.useEffect(() => setIsChecked(ruleState.state !== RuleStates.Silenced), [ruleState]); | ||
|
||
const handleChange = (checked: boolean) => { | ||
if (checked) { | ||
_.each(rule.silencedBy, (silence) => { | ||
coFetchJSON.delete(`${alertManagerBaseURL}/api/v2/silence/${silence.id}`); | ||
}); | ||
} | ||
setIsChecked(checked); | ||
}; | ||
|
||
return ( | ||
<Switch | ||
aria-label="Silence switch" | ||
className="odc-silence-alert" | ||
label={null} | ||
labelOff={ | ||
rule.state === RuleStates.Silenced ? ( | ||
<SilenceUntil rule={rule} /> | ||
) : ( | ||
<SilenceDurationDropDown rule={rule} /> | ||
) | ||
} | ||
isChecked={isChecked} | ||
onChange={handleChange} | ||
/> | ||
); | ||
}; | ||
|
||
export default SilenceAlert; |
67 changes: 67 additions & 0 deletions
67
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,67 @@ | ||
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; | ||
}; | ||
|
||
const durations = { | ||
silenceFor: 'Silence for', | ||
'30m': '30 minutes', | ||
'1h': '1 hour', | ||
'2h': '2 hours', | ||
'1d': '1 day', | ||
}; | ||
|
||
const { alertManagerBaseURL } = window.SERVER_FLAGS; | ||
|
||
const SilenceDurationDropDown: React.FC<SilenceDurationDropDownProps> = ({ rule }) => { | ||
const createdBy = useSelector((state: RootState) => state.UI.get('user')?.metadata?.name); | ||
const ruleMatchers = _.map(rule?.labels, (value, key) => ({ isRegex: false, name: key, value })); | ||
|
||
const matchers = [ | ||
{ | ||
isRegex: false, | ||
name: 'alertname', | ||
value: rule.name, | ||
}, | ||
...ruleMatchers, | ||
]; | ||
|
||
const setDuration = (duration: string) => { | ||
if (duration !== 'silenceFor') { | ||
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={durations} | ||
onChange={(v: string) => setDuration(v)} | ||
selectedKey={'silenceFor'} | ||
/> | ||
); | ||
}; | ||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also add matchers for any additional labels found in
rule.labels
.