Skip to content
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

UI: Showed host reservations and allocation utilization by task on existing stats charts #10208

Merged
merged 24 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
febecbb
Pass the LineChart named blocks through to callers of StatsTimeSeries
DingoEatingFuzz Mar 15, 2021
ce7f6d0
Compute and render reserved annotations for client stats
DingoEatingFuzz Mar 15, 2021
d6b72c1
Refactor PrimaryMetric into parts/purposes
DingoEatingFuzz Mar 15, 2021
a6a9df5
Simple bind helper
DingoEatingFuzz Mar 16, 2021
8ae7645
Stacked percentages of tasks for alloc charts
DingoEatingFuzz Mar 16, 2021
8ab3014
Sort and index multi-series data correctly in line chart
DingoEatingFuzz Mar 16, 2021
d72eaa1
Refactor stats-time-series to allow for multiple series
DingoEatingFuzz Mar 16, 2021
4f27bee
Refactored multi-series allocation variant of the primary metric comp…
DingoEatingFuzz Mar 16, 2021
df11688
Memoize the tracker and the series properties to avoid repeat computa…
DingoEatingFuzz Mar 19, 2021
745a55b
Apply the new multi-line primary metric to the alloc index page
DingoEatingFuzz Mar 19, 2021
7b73460
New PrimaryMetric::Task component
DingoEatingFuzz Mar 19, 2021
17cf4ad
Improved language around what the client stat charts represent
DingoEatingFuzz Mar 22, 2021
2953542
Remove now unused chartClass arg from LineChart
DingoEatingFuzz Mar 22, 2021
2ed5b28
Tests for PrimaryMetric::Node
DingoEatingFuzz Mar 22, 2021
e3a1106
Tests for PrimaryMetric::Allocation
DingoEatingFuzz Mar 22, 2021
ead08e2
Tests for PrimaryMetric::Task
DingoEatingFuzz Mar 22, 2021
91521d6
Updated old tests
DingoEatingFuzz Mar 22, 2021
5191693
Update topology info box primary metric
DingoEatingFuzz Mar 22, 2021
b009fc1
Remove old primary metric
DingoEatingFuzz Mar 22, 2021
2b1449c
Use more explicit branching of reserved amounts based on metric type
DingoEatingFuzz Mar 24, 2021
ebd91a9
Fix line-wrapping issue with chart tooltips
DingoEatingFuzz Mar 24, 2021
1d8bc39
Guard against empty data when determining active linechart data
DingoEatingFuzz Mar 24, 2021
d9426df
Correctly sort tasks in alloc stat tracker so the main task takes pre…
DingoEatingFuzz Mar 24, 2021
c15bf65
Remove errant log line
DingoEatingFuzz Mar 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/app/components/chart-primitives/area.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<path class="fill" d="{{this.area}}" />
</clipPath>
</defs>
<g class="area {{this.colorClass}}" ...attributes>
<g data-test-chart-area class="area {{this.colorClass}}" ...attributes>
<path class="line" d="{{this.line}}" />
<rect class="fill" x="0" y="0" width="{{@width}}" height="{{@height}}" fill="url(#{{this.fillId}})" clip-path="url(#{{this.maskId}})" />
</g>
2 changes: 1 addition & 1 deletion ui/app/components/chart-primitives/tooltip.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div data-test-chart-tooltip class="chart-tooltip {{if @active "active" "inactive"}}" style={{@style}} ...attributes>
<ol>
{{#each @data as |props|}}
{{yield props.series props.datum (inc props.index)}}
{{yield props.series props.datum (inc props.index)}}
{{/each}}
</ol>
</div>
1 change: 0 additions & 1 deletion ui/app/components/chart-primitives/v-annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export default class ChartPrimitiveVAnnotations extends Component {

annotationIsActive(annotation) {
const { key, activeAnnotation } = this.args;
console.log(key, activeAnnotation, annotation);
if (!activeAnnotation) return false;

if (key) return get(annotation, key) === get(activeAnnotation, key);
Expand Down
74 changes: 39 additions & 35 deletions ui/app/components/line-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export default class LineChart extends Component {
title = 'Line Chart';
description = null;
timeseries = false;
chartClass = 'is-primary';
activeAnnotation = null;
onAnnotationClick() {}
xFormat;
Expand Down Expand Up @@ -92,9 +91,6 @@ export default class LineChart extends Component {
get curve() {
return this.args.curve || 'linear';
}
get chartClass() {
return this.args.chartClass || 'is-primary';
}

@action
xFormat(timeseries) {
Expand Down Expand Up @@ -272,39 +268,47 @@ export default class LineChart extends Component {
const x = xScale.invert(mouseX);

// Find the closest datum to the cursor for each series
const activeData = data.map((series, seriesIndex) => {
const dataset = series[dataProp];
const index = bisector(dataset, x, 1);

// The data point on either side of the cursor
const dLeft = dataset[index - 1];
const dRight = dataset[index];

let datum;

// If there is only one point, it's the activeDatum
if (dLeft && !dRight) {
datum = dLeft;
} else {
// Pick the closer point
datum = x - dLeft[xProp] > dRight[xProp] - x ? dRight : dLeft;
}

return {
series,
datum: {
formattedX: this.xFormat(this.args.timeseries)(datum[xProp]),
formattedY: this.yFormat()(datum[yProp]),
datum,
},
index: seriesIndex,
};
});
const activeData = data
.map((series, seriesIndex) => {
const dataset = series[dataProp];

// If the dataset is empty, there can't be an activeData.
// This must be done here instead of preemptively in a filter to
// preserve the seriesIndex value.
if (!dataset.length) return null;

const index = bisector(dataset, x, 1);

// The data point on either side of the cursor
const dLeft = dataset[index - 1];
const dRight = dataset[index];

let datum;

// If there is only one point, it's the activeDatum
if (dLeft && !dRight) {
datum = dLeft;
} else {
// Pick the closer point
datum = x - dLeft[xProp] > dRight[xProp] - x ? dRight : dLeft;
}

return {
series,
datum: {
formattedX: this.xFormat(this.args.timeseries)(datum[xProp]),
formattedY: this.yFormat()(datum[yProp]),
datum,
},
index: data.length - seriesIndex - 1,
};
})
.compact();

// Of the selected data, determine which is closest
const closestDatum = activeData.sort(
(a, b) => Math.abs(a.datum.datum[xProp] - x) - Math.abs(b.datum.datum[xProp] - x)
)[0];
const closestDatum = activeData
.slice()
.sort((a, b) => Math.abs(a.datum.datum[xProp] - x) - Math.abs(b.datum.datum[xProp] - x))[0];

// If any other selected data are beyond a distance threshold, drop them from the list
// xScale is used here to measure distance in screen-space rather than data-space.
Expand Down
107 changes: 0 additions & 107 deletions ui/app/components/primary-metric.js

This file was deleted.

42 changes: 42 additions & 0 deletions ui/app/components/primary-metric/allocation.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<div data-test-primary-metric class="primary-metric" ...attributes
{{did-insert this.start}}
{{did-update this.start}}>
<h4 data-test-primary-metric-title class="title is-5">
{{#if (eq this.metric "cpu")}} CPU
{{else if (eq this.metric "memory")}} Memory
{{else}} {{this.metric}} {{/if}}
</h4>
<div class="primary-graphic">
<StatsTimeSeries @data={{this.series}} @dataProp="data" >
<:svg as |c|>
{{#each (reverse this.series) as |series idx|}}
<c.Area @data={{series.data}} @colorScale={{this.colorScale}} @index={{idx}} />
{{/each}}
</:svg>
<:after as |c|>
<c.Tooltip class="is-snappy" as |series datum idx|>
<li>
<span class="label"><span class="color-swatch swatch-{{this.colorScale}} swatch-{{this.colorScale}}-{{idx}}" />{{series.name}}</span>
{{#if (eq this.metric "cpu")}}
<span class="value">{{datum.datum.used}} MHz</span>
{{else if (eq this.metric "memory")}}
<span class="value">{{format-bytes datum.datum.used}}</span>
{{else}}
<span class="value">{{datum.formatttedY}}</span>
{{/if}}
</li>
</c.Tooltip>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure what it is but there’s something broken in allocation chart tooltips when I run locally:

image

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Looks like this happens for allocs with lifecycle tasks that haven't started yet. Is that when you encountered it too?

</:after>
</StatsTimeSeries>
</div>
<PrimaryMetric::CurrentValue @chartClass={{this.chartClass}} @percent={{this.data.lastObject.percent}} />
<div class="annotation" data-test-absolute-value>
{{#if (eq this.metric "cpu")}}
<strong>{{this.data.lastObject.used}} MHz</strong> / {{this.reservedAmount}} MHz Total
{{else if (eq this.metric "memory")}}
<strong>{{format-bytes this.data.lastObject.used}}</strong> / {{this.reservedAmount}} MiB Total
{{else}}
<strong>{{this.data.lastObject.used}}</strong> / {{this.reservedAmount}} Total
{{/if}}
</div>
</div>
82 changes: 82 additions & 0 deletions ui/app/components/primary-metric/allocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import Ember from 'ember';
import Component from '@glimmer/component';
import { task, timeout } from 'ember-concurrency';
import { assert } from '@ember/debug';
import { inject as service } from '@ember/service';
import { action, get, computed } from '@ember/object';

export default class AllocationPrimaryMetric extends Component {
@service('stats-trackers-registry') statsTrackersRegistry;

/** Args
allocation = null;
metric null; (one of 'cpu' or 'memory'
*/

get metric() {
assert('metric is a required argument', this.args.metric);
return this.args.metric;
}

get allocation() {
return this.args.allocation;
}

@computed('allocation')
get tracker() {
return this.statsTrackersRegistry.getTracker(this.allocation);
}

get data() {
if (!this.tracker) return [];
return get(this, `tracker.${this.metric}`);
}

@computed('tracker.tasks.[]', 'metric')
get series() {
const ret = this.tracker.tasks
.map(task => ({
name: task.task,
data: task[this.metric],
}))
.reverse();

return ret;
}

get reservedAmount() {
if (this.metric === 'cpu') return this.tracker.reservedCPU;
if (this.metric === 'memory') return this.tracker.reservedMemory;
return null;
}

get chartClass() {
if (this.metric === 'cpu') return 'is-info';
if (this.metric === 'memory') return 'is-danger';
return 'is-primary';
}

get colorScale() {
if (this.metric === 'cpu') return 'blues';
if (this.metric === 'memory') return 'reds';
return 'ordinal';
}

@task(function*() {
do {
this.tracker.poll.perform();
yield timeout(100);
} while (!Ember.testing);
})
poller;

@action
start() {
if (this.tracker) this.poller.perform();
}

willDestroy() {
this.poller.cancelAll();
this.tracker.signalPause.perform();
}
}
16 changes: 16 additions & 0 deletions ui/app/components/primary-metric/current-value.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="columns secondary-graphic">
<div class="column">
<div class="inline-chart" data-test-percentage-bar>
<progress
data-test-current-value
class="progress {{@chartClass}} is-small"
value="{{@percent}}"
max="1">
{{@percent}}
</progress>
</div>
</div>
<div class="column is-minimum">
<span class="nowrap" data-test-percentage>{{format-percentage @percent total=1}}</span>
</div>
</div>
Loading