-
Notifications
You must be signed in to change notification settings - Fork 993
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
Fixes #23665 - Use Patternfly charts in Runtime #5600
Conversation
Issues: #23665 |
/cc @ohadlevy @sharvit @amirfefer @lizagilman PTAL |
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.
initial code review, did not test really as its not mountable.
Also would be happy to see storybook examples on how to use the time series charts.
app/controllers/hosts_controller.rb
Outdated
@@ -300,7 +300,7 @@ def vm | |||
end | |||
|
|||
def runtime | |||
render :partial => 'runtime' | |||
render :json => helpers.runtime_chart(params["range"].empty? ? 7 : params["range"].to_i) | |||
rescue ActionView::Template::Error => exception |
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 guess the exception is no longer valid?
app/helpers/hosts_helper.rb
Outdated
@@ -229,7 +229,10 @@ def runtime_chart(timerange = 1.day.ago) | |||
config << [r.reported_at.to_i*1000, r.config_retrieval] | |||
runtime << [r.reported_at.to_i*1000, r.runtime] | |||
end | |||
[{:label=>_("Config Retrieval"), :data=> config, :color=>'#AA4643'}, {:label=>_("Runtime"), :data=> runtime, :color=>'#4572A7'}] | |||
{:results => [ | |||
{:label=>_("Config Retrieval"), :data=> config, :color=>'#AA4643'}, |
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 wonder if we need to keep the color overrides, which colors do you get without defining it?
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.
#0088ce ,#39a5dc, #3f9c35 and #ec7a08 which are the defaults in c3js
app/views/hosts/show.html.erb
Outdated
<div class="chart" data-ajax-url='<%= runtime_host_path(@host, :range => @range) %>' data-on-complete='updateChart'> | ||
<%= spinner(_('Loading runtime information ...')) %> | ||
</div> | ||
<div id="runtime_react"></div> |
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.
not sure if react is needed as part of the div, just host_runtime or something similar would suffice
@@ -0,0 +1,24 @@ | |||
|
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.
nitpick: extra empty line?
return c3Resp; | ||
}; | ||
|
||
export default Normalizer; |
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.
is it safe to assume this will work the same with trends too?
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.
Yes, looking at the returned value from chart_data
, it can normalize the trends too.
import { noop } from '../../common/helpers'; | ||
import Normalizer from './Normalizer'; | ||
|
||
|
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.
nitpick: extra line
} = this.props; | ||
|
||
if (hasError) { | ||
return <Alert>__("Failed loading chart data")</Alert>; |
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 we reuse chartbox ? it has a loader and a failure state afair?
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.
ChartBox
does more than what TimeseriesChart
does.
I find Loader
which is used by ChartBox
reusable in here too, though.
Thanks for the help.
axis={{ x: { type: 'timeseries', tick: { fit: false } } }} | ||
tooltip={{ grouped: false, format: { title: d => new Date(d).toUTCString() } }} | ||
zoom={{ enabled: true }} | ||
/> |
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.
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.
on second look, it looks like you forgot to add the changes to the mounter?
app/views/hosts/show.html.erb
Outdated
</div> | ||
|
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 configure your editor to remove trailing whitespaces, while not visible at github, this include 4 spaces charts (easily viewable with git diff)
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 @ripcurld !
I'm getting a PG error when a details host page renders.
more details in the inline comments.
} = this.props; | ||
|
||
if (hasError) { | ||
return <Alert>__("Failed loading chart data")</Alert>; |
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 be wrapped by {}
if (colorItems.length === 0) { | ||
return c3Resp; | ||
} | ||
const colorReducer = (acc, cur) => Object.assign(acc, { [cur.label]: cur.color }); |
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.
be aware that acc
is going to be mutated, if you'd like just a copy, use Object.assign({}, copied data
), or use object spread operator, which I tend to prefer because of its readability.
|
||
|
||
class TimeseriesChart extends React.Component { | ||
componentWillMount() { |
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.
API calls should be in componentDidMount
return ( | ||
<Spinner loading={isLoadingData} size='md'> | ||
<PfLineChart | ||
data={{ ...data, type: chartType }} |
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.
Why not using a service
module like donut chart does with ChartService
?
className="line-chart-pf" | ||
color={ | ||
Object { | ||
"pattern": Array [ |
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.
is that the default pf colors scheme? or some random colors?
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.
Yes it is or more likely pf
is using c3js
default color scheme
app/views/hosts/show.html.erb
Outdated
<%= spinner(_('Loading runtime information ...')) %> | ||
</div> | ||
<div id="runtime_react"></div> | ||
<%= mount_react_component('TimeseriesChart', '#runtime_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.
doesn't work with PG:
i'm getting this :
( the error string is not extracted )
with this error:
ActiveRecord::StatementInvalid (PG::UndefinedFunction: ERROR: operator does not exist: timestamp without time zone > integer
| LINE 1: ...t') AND "reports"."host_id" = $1 AND (reported_at > 7) ORDER...
| ^
| HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
| : SELECT "reports".* FROM "reports" WHERE "reports"."type" IN ('ConfigReport') AND "reports"."host_id" = $1 AND (reported_at > 7) ORDER BY "reports"."reported_at" ASC):
[test foreman] 🤞 |
@ripcurld can you please add it to the storybook and publish it somehwhere? thanks! |
Sure thing. 👍 |
app/helpers/hosts_helper.rb
Outdated
link_to_function(icon_text('random'), 'randomizeName()', :class => 'btn btn-default', | ||
:title => _('Generate new random name. Visit Settings to disable this feature.')) | ||
end | ||
link_to_function(icon_text('random'), 'randomizeName()', :class => 'btn btn-default', |
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.
Style/MultilineIfModifier: Favor a normal if-statement over a modifier clause in a multiline statement.
app/helpers/hosts_helper.rb
Outdated
else | ||
status = '<i class="glyphicon glyphicon glyphicon-arrow-down interface-down" title="' + _('Interface is down') + '"></i>' | ||
status = '<i class="glyphicon glyphicon glyphicon-arrow-down interface-down" title="'+ _('Interface is down') +'"></i>' |
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.
Layout/SpaceAroundOperators: Surrounding space missing for operator +.
app/helpers/hosts_helper.rb
Outdated
@@ -446,9 +439,9 @@ def link_status(nic) | |||
return '' if nic.new_record? | |||
|
|||
if nic.link | |||
status = '<i class="glyphicon glyphicon glyphicon-arrow-up interface-up" title="' + _('Interface is up') + '"></i>' | |||
status = '<i class="glyphicon glyphicon glyphicon-arrow-up interface-up" title="'+ _('Interface is up') +'"></i>' |
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.
Layout/SpaceAroundOperators: Surrounding space missing for operator +.
app/helpers/hosts_helper.rb
Outdated
@@ -354,7 +347,7 @@ def host_title_actions(host) | |||
link_to_if_authorized(_("Run puppet"), hash_for_puppetrun_host_path(:id => host).merge(:auth_object => host, :permission => 'puppetrun_hosts'), | |||
:disabled => !Setting[:puppetrun], | |||
:class => 'btn btn-default', | |||
:title => _("Trigger a puppetrun on a node; requires that puppet run is enabled")) | |||
:title => _("Trigger a puppetrun on a node; requires that puppet run is enabled")) |
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.
Layout/SpaceAroundOperators: Operator => should be surrounded by a single space.
app/helpers/hosts_helper.rb
Outdated
{ :days => select(nil, 'range', 1..number_of_days, | ||
{:selected => @range}, {:style => "float:none; width: #{width}em;", :onchange => "$('#days_filter').submit();$(this).disabled();"}), | ||
{ :days => select(nil, 'range', 1..number_of_days, | ||
{:selected => @range}, {:style=>"float:none; width: #{width}em;", :onchange =>"$('#days_filter').submit();$(this).disabled();"}), |
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.
Layout/SpaceAroundOperators: Surrounding space missing for operator =>.
app/helpers/hosts_helper.rb
Outdated
{:label=>_("Applied"), :data=>applied, :color =>'#89A54E'}, | ||
{:label=>_("Failed"), :data=>failed, :color =>'#AA4643'}, | ||
{:label=>_("Failed restarts"), :data=>failed_restarts, :color =>'#EC971F'}, | ||
{:label=>_("Skipped"), :data=>skipped, :color =>'#80699B'}, |
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.
Layout/SpaceAroundOperators: Surrounding space missing for operator =>.
app/helpers/hosts_helper.rb
Outdated
{:results => [ | ||
{:label=>_("Applied"), :data=>applied, :color =>'#89A54E'}, | ||
{:label=>_("Failed"), :data=>failed, :color =>'#AA4643'}, | ||
{:label=>_("Failed restarts"), :data=>failed_restarts, :color =>'#EC971F'}, |
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.
Layout/SpaceAroundOperators: Surrounding space missing for operator =>.
app/helpers/hosts_helper.rb
Outdated
{:label => _("Restarted"), :data => restarted, :color => '#4572A7'}] | ||
{:results => [ | ||
{:label=>_("Applied"), :data=>applied, :color =>'#89A54E'}, | ||
{:label=>_("Failed"), :data=>failed, :color =>'#AA4643'}, |
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.
Layout/SpaceAroundOperators: Surrounding space missing for operator =>.
app/helpers/hosts_helper.rb
Outdated
{:label => _("Skipped"), :data => skipped, :color => '#80699B'}, | ||
{:label => _("Restarted"), :data => restarted, :color => '#4572A7'}] | ||
{:results => [ | ||
{:label=>_("Applied"), :data=>applied, :color =>'#89A54E'}, |
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.
Layout/SpaceAroundOperators: Surrounding space missing for operator =>.
app/helpers/hosts_helper.rb
Outdated
failed << [r.reported_at.to_i*1000, r.failed ] | ||
restarted << [r.reported_at.to_i*1000, r.restarted ] | ||
failed_restarts << [r.reported_at.to_i*1000, r.failed_restarts ] | ||
skipped << [r.reported_at.to_i*1000, r.skipped ] |
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.
Layout/SpaceAroundOperators: Surrounding space missing for operator *.
app/helpers/hosts_helper.rb
Outdated
@@ -513,3 +518,4 @@ def host_breadcrumb | |||
breadcrumbs(resource_url: "/api/v2/hosts?thin=true'") | |||
end | |||
end | |||
|
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.
Layout/TrailingBlankLines: 1 trailing blank lines detected.
there is an existing feature that is not ported, the current charts allow
to zoom in, so one could select a time range and see a new chart... is that
possible to enable that?
…On Mon, Jul 9, 2018 at 12:04 PM ripcurld ***@***.***> wrote:
@ohadlevy <https://github.com/ohadlevy> the storybook can be found here
<https://rawgit.com/ripcurld/foreman/gh-pages/>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5600 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABOx68CJByeSyvpcR9oloyFD8CnRRgCks5uExy2gaJpZM4UIKXb>
.
|
Unfortunately, I didn't find a way to do that in |
@ohadlevy I had some free time, so I revisited |
gr... katello dislikes me. |
Lets hope |
[test katello] |
[test foreman] |
@boaz1337 can you rebase please? thanks! |
@boaz1337 I just tried to use it (in the storybook) and I'm not sure how? |
Uhm, I guess it's not as intuitive as I thought.
I hope this will demonstrate it better |
CI failure is unrelated to changes. |
ping @theforeman/ui-ux ? |
this looks great! as it's pretty interactive, could I see a storybook to play with it? @boaz1337 |
@terezanovotna sure you can: storybook 📖 |
The flot package is deprecated although it's being used to plot charts in Foreman. In this commit: - Added TimeseriesChart that uses Patternfly's LineChart under common/charts - Added HostChart under hosts - Rendered HostChart for runtime and resources in "hosts/show.html.erb" - Added unit tests - Removed unnecessary files such as "hosts/_runtime.html.erb" - Changed routes "hosts/:name/{runtime,resources}" to render JSON Signed-off-by: Boaz Shuster <[email protected]>
@terezanovotna sorry but right now there is no way to set the grey rectangle when chart is rendered for the first time. EDIT looking into it more - in the new version of The problem is that bcbcarl/react-c3js#41 is still waiting on review. |
Sorry if I'm confused, but based on the storybook, this will be the way we displaye all charts? Do I have to activate the bottom chart somehow? The fact there are two charts for one, each for different time span would IMHO be quite confusing. |
@boaz1337 |
It starts out of with a view of the longest history. Activitating the bottom will allow a user to zoom in. Maybe not the most helpful or runtime but can be very beneficial if one would want to focus on the details of a specific section of chart. I'm not seeing them being in different times? They are always representative of each other. |
I'm closing this as we are stuck. The current UX is not good enough and the Chart library that PF3 is using is no longer up to date which makes it impossible to have something working. If someone wants to take it, feel free to do it. I would love to help as much as I can. Thanks everyone for your feedback and hard work. 😄 |
The flot package is deprecated although it's being used
to plot charts in Foreman.
One of those charts that uses flot is the Runtime chart.
In this commit:
Before
After