-
Notifications
You must be signed in to change notification settings - Fork 2k
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: Node drain and eligibility #4353
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6b63576
Data modeling for node drain and scheduling eligibility
DingoEatingFuzz c193a1d
Update the clients list table to include drain and eligibility
DingoEatingFuzz bb855b5
Add ineligibility to the status light
DingoEatingFuzz df81f31
Add drain and eligibility to the client details strip
DingoEatingFuzz c949b4a
Color-code node drain and eligibility in the full client list
DingoEatingFuzz 4d00f2f
Duration formatting utility
DingoEatingFuzz d649f62
Display node drain strategy information on the client detail page
DingoEatingFuzz 03aee6f
Acceptance testing for node drain information
DingoEatingFuzz 9aabe13
New traits for node states
DingoEatingFuzz 83e0b10
Account for the 0 case in format-duration
DingoEatingFuzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Helper from '@ember/component/helper'; | ||
import formatDuration from '../utils/format-duration'; | ||
|
||
function formatDurationHelper([duration], { units }) { | ||
return formatDuration(duration, units); | ||
} | ||
|
||
export default Helper.helper(formatDurationHelper); |
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,12 @@ | ||
import { lt, equal } from '@ember/object/computed'; | ||
import attr from 'ember-data/attr'; | ||
import Fragment from 'ember-data-model-fragments/fragment'; | ||
|
||
export default Fragment.extend({ | ||
deadline: attr('number'), | ||
forceDeadline: attr('date'), | ||
ignoreSystemJobs: attr('boolean'), | ||
|
||
isForced: lt('deadline', 0), | ||
hasNoDeadline: equal('deadline', 0), | ||
}); |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { computed } from '@ember/object'; | ||
import { equal } from '@ember/object/computed'; | ||
import Model from 'ember-data/model'; | ||
import attr from 'ember-data/attr'; | ||
import { hasMany } from 'ember-data/relationships'; | ||
|
@@ -11,6 +12,7 @@ export default Model.extend({ | |
name: attr('string'), | ||
datacenter: attr('string'), | ||
isDraining: attr('boolean'), | ||
schedulingEligibility: attr('string'), | ||
status: attr('string'), | ||
statusDescription: attr('string'), | ||
shortId: shortUUIDProperty('id'), | ||
|
@@ -23,6 +25,9 @@ export default Model.extend({ | |
meta: fragment('node-attributes'), | ||
resources: fragment('resources'), | ||
reserved: fragment('resources'), | ||
drainStrategy: fragment('drain-strategy'), | ||
|
||
isEligible: equal('schedulingEligibility', 'eligible'), | ||
|
||
address: computed('httpAddr', function() { | ||
return ipParts(this.get('httpAddr')).address; | ||
|
@@ -52,4 +57,10 @@ export default Model.extend({ | |
unhealthyDriverNames: computed('[email protected]', function() { | ||
return this.get('unhealthyDrivers').mapBy('name'); | ||
}), | ||
|
||
// A status attribute that includes states not included in node status. | ||
// Useful for coloring and sorting nodes | ||
compositeStatus: computed('status', 'isEligible', function() { | ||
return this.get('isEligible') ? this.get('status') : 'ineligible'; | ||
}), | ||
}); |
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,13 @@ | ||
import ApplicationSerializer from './application'; | ||
|
||
export default ApplicationSerializer.extend({ | ||
normalize(typeHash, hash) { | ||
// TODO API: finishedAt is always marshaled as a date even when unset. | ||
// To simplify things, unset it here when it's the empty date value. | ||
if (hash.ForceDeadline === '0001-01-01T00:00:00Z') { | ||
hash.ForceDeadline = null; | ||
} | ||
|
||
return this._super(typeHash, hash); | ||
}, | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,8 @@ $size: 0.75em; | |
darken($grey-lighter, 25%) 6px | ||
); | ||
} | ||
|
||
&.ineligible { | ||
background: $warning; | ||
} | ||
} |
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
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,47 @@ | ||
import moment from 'moment'; | ||
|
||
const allUnits = [ | ||
{ name: 'years', suffix: 'year', inMoment: true, pluralizable: true }, | ||
{ name: 'months', suffix: 'month', inMoment: true, pluralizable: true }, | ||
{ name: 'days', suffix: 'day', inMoment: true, pluralizable: true }, | ||
{ name: 'hours', suffix: 'h', inMoment: true, pluralizable: false }, | ||
{ name: 'minutes', suffix: 'm', inMoment: true, pluralizable: false }, | ||
{ name: 'seconds', suffix: 's', inMoment: true, pluralizable: false }, | ||
{ name: 'milliseconds', suffix: 'ms', inMoment: true, pluralizable: false }, | ||
{ name: 'microseconds', suffix: 'µs', inMoment: false, pluralizable: false }, | ||
{ name: 'nanoseconds', suffix: 'ns', inMoment: false, pluralizable: false }, | ||
]; | ||
|
||
export default function formatDuration(duration = 0, units = 'ns') { | ||
const durationParts = {}; | ||
|
||
if (units === 'ns') { | ||
durationParts.nanoseconds = duration % 1000; | ||
durationParts.microseconds = Math.floor((duration % 1000000) / 1000); | ||
duration = Math.floor(duration / 1000000); | ||
} else if (units === 'mms') { | ||
durationParts.microseconds = duration % 1000; | ||
duration = Math.floor(duration / 1000); | ||
} | ||
|
||
const momentDuration = moment.duration(duration, ['ns', 'mms'].includes(units) ? 'ms' : units); | ||
|
||
allUnits | ||
.filterBy('inMoment') | ||
.mapBy('name') | ||
.forEach(unit => { | ||
durationParts[unit] = momentDuration[unit](); | ||
}); | ||
|
||
const displayParts = allUnits.reduce((parts, unitType) => { | ||
if (durationParts[unitType.name]) { | ||
const count = durationParts[unitType.name]; | ||
const suffix = | ||
count === 1 || !unitType.pluralizable ? unitType.suffix : unitType.suffix.pluralize(); | ||
parts.push(`${count}${unitType.pluralizable ? ' ' : ''}${suffix}`); | ||
} | ||
return parts; | ||
}, []); | ||
|
||
return displayParts.join(' '); | ||
} |
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.
I found this part a little tricky to follow. My reading is that the unit of
duration
can be one of nanoseconds, microseconds, or milliseconds, and for the former two cases we're normalizing it back to milliseconds here.If that's correct, it might also be clearer to mutate the
units
argument in these blocks also, rather than in the dense ternary on the following line. And perhaps some commentary explaining this might also help?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.
Units can be any unit moment supports (ms, s, m, h, days, months, years) as well as microseconds and nanoseconds, which moment doesn't support.
So this ternary:
Uses units as is unless units is either microseconds or nanoseconds, in which case nanos and micros need to be calculated upfront and duration needs to be normalized as milliseconds.
But your suggestion to reassign
units
toms
is still valid. Also point taken about needing comments.