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
Adds support for rules screen in react-ui #6503
Conversation
Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>
Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>
Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>
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.
Thanks! This is a first round of comments. Currently the page doesn't load when alerting rules are defined, so let's fix these comments first before doing a second review.
Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>
@juliusv I have implemented the suggestions. Please have a look. |
Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>
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.
@Harkishen-Singh Added some comments and ideas
@@ -1,15 +1,147 @@ | |||
import React, { FC } from 'react'; |
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.
Can you align response handling with the pattern used in other pages i.e check how withStatusIndicator
HOC is used
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.
Can you align response handling with the pattern used in other pages i.e check how
withStatusIndicator
HOC is used
Better to merge this one first #6629
Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>
@@ -1,15 +1,147 @@ | |||
import React, { FC } from 'react'; |
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.
Can you align response handling with the pattern used in other pages i.e check how
withStatusIndicator
HOC is used
Better to merge this one first #6629
@Harkishen-Singh On top of all the suggestions, I would say that there is inconsistency with the old UI in terms of font-size, font-family and text formatting. You can check CSS class Update: It turns out that the back button is not working once you navigate to the graph page via the expression link. This bug is already fixed with this PR #6659 |
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.
Thanks, I gave this one more thorough review, added more comments to be addressed. Seems there are also still quite a few comments by @boyskila that would be good to fix.
}; | ||
|
||
const Rules: FC<RouteComponentProps & PathPrefixProps> = ({ pathPrefix }) => { | ||
const { response, error } = useFetch<RulesMap>(`${pathPrefix}/api/v1/rules`); |
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.
<tr key={i}> | ||
{r.alerts ? ( | ||
<td> | ||
<strong>alert:</strong> |
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.
I would prefer if we didn't use CSS/HTML spacing (margin-left: 3%
, <br/>
, etc.) in this field and instead kept it all preformatted like in the old UI and use existing normal whitespace for the formatting, so it's properly copyable YAML (at least for the most part).
In the old UI the styling was achieved via:
.rule_cell {
white-space: pre-wrap;
background-color: #F5F5F5;
display: block;
font-family: monospace;
}
Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>
Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>
Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>
@@ -237,3 +237,14 @@ button.execute-btn { | |||
margin-right: 5px; | |||
max-height: 20px; | |||
} | |||
|
|||
.rules-head { |
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.
Please remove rulse-head
- it's not used anywhere
groups: RuleGroup[]; | ||
} | ||
|
||
const GraphExpressionLink: FC<{ expr: string; title: string }> = props => { |
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.
This component should look like:
export const GraphExpressionLink: FC<{ expr: string; title: string; name: string & PathPrefixProps}> = memo(({ name, title, expr, pathPrefix }) => {
return (
<div>
{title}:
<Link className="ml-4" to={createExpressionLink(expr, pathPrefix)}>
{name}
</Link>
</div>
);
});
name
and expr
may have different content, so we can't rely on expr
to represent the name
Also, wrapping the Link
and title
in div will remove the need of <br/>
. IMO it's better.
Comparing with the old UI titles here are wrapped in <strong>
, maybe you should remove the extra tag
Another, more important thing is to pas the pathPrefix
prop down to createExpressionLink
. IMO the ../
in createExpressionLink
should be passed from outside and the function just to return
${prefix}graph?g0.expr=${encodeURIComponent(expr)}&g0.tab=1&g0.stacked=0&g0.range_input=1h
The usage should looks like createExpressionLink(expr, pathPrefix + '/../')
Suggestion: GraphExpressionLink
can be moved to component
folder and can replace both expressions here
<div> | |
name: <Link to={createExpressionLink(`ALERTS{alertname="${rule.name}"}`)}>{rule.name}</Link> | |
</div> | |
<div> | |
expr: <Link to={createExpressionLink(rule.query)}>{rule.query}</Link> | |
</div> | |
<div> |
{g.rules.map((r, i) => { | ||
return ( | ||
<tr key={i}> | ||
{r.alerts ? ( |
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.
<td>
content can be reduced to
<td className="rule_cell">
<GraphExpressionLink name={r.name} title={r.alerts ? 'alert' : 'record'} expr={`ALERTS{alertname="${r.name}"}`}/>
<GraphExpressionLink title="expr" expr={r.query} name={r.query} />
{r.alerts && (
<>
labels:
{Object.entries(r.labels).map(([key, value]) => (
<div className="ml-4" key={key}>
{key}: {value}
</div>
))}
annotations:
{Object.entries(r.annotations).map(([key, value]) => (
<div className="ml-4" key={key}>
{key}: {value}
</div>
))}
</>
)}
</td>
Some of the divs are redundant and.
Alse, note that first GraphExpressionLink
has as an expression ALERTS{alertname="${r.name}"}
. Passing just r.name
as expr is not enough and its not working
@@ -197,3 +197,7 @@ export const toQueryString = ({ key, options }: PanelMeta) => { | |||
export const encodePanelOptionsToQueryString = (panels: PanelMeta[]) => { | |||
return `?${panels.map(toQueryString).join('&')}`; | |||
}; | |||
|
|||
export const createExpressionLink = (expr: string) => { |
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.
Please pass as second argument the pathPrefix
prop and remove ../
- this should be passed from outside as well
Thanks! :) There are still a couple of new (and old, #6503 (comment)) outstanding comments, but I'll merge this for now, and then we can individually refactor/address the remaining few bits. |
* base Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com> * base of rules page Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com> * initial version Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com> * removed unused function Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com> * version 1 Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com> * implemented suggestions Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com> * implemented suggestions Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com> * implemented suggestions. Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com> * new fetching pattern Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com> * implemented suggestions Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com> Signed-off-by: blalov <boiskila@gmail.com>
Fixes: #6385
Fixes: #6302
Initial-version
Update-1: