-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4704 from hashicorp/f-ui-applied-stat-charts
UI: Stat charts everywhere
- Loading branch information
Showing
35 changed files
with
892 additions
and
162 deletions.
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
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,99 @@ | ||
import Ember from 'ember'; | ||
import Component from '@ember/component'; | ||
import { inject as service } from '@ember/service'; | ||
import { computed } from '@ember/object'; | ||
import { task, timeout } from 'ember-concurrency'; | ||
|
||
export default Component.extend({ | ||
token: service(), | ||
statsTrackersRegistry: service('stats-trackers-registry'), | ||
|
||
classNames: ['primary-metric'], | ||
|
||
// One of Node, Allocation, or TaskState | ||
resource: null, | ||
|
||
// cpu or memory | ||
metric: null, | ||
|
||
'data-test-primary-metric': true, | ||
|
||
// An instance of a StatsTracker. An alternative interface to resource | ||
tracker: computed('trackedResource', 'type', function() { | ||
const resource = this.get('trackedResource'); | ||
return this.get('statsTrackersRegistry').getTracker(resource); | ||
}), | ||
|
||
type: computed('resource', function() { | ||
const resource = this.get('resource'); | ||
return resource && resource.constructor.modelName; | ||
}), | ||
|
||
trackedResource: computed('resource', 'type', function() { | ||
// TaskStates use the allocation stats tracker | ||
return this.get('type') === 'task-state' | ||
? this.get('resource.allocation') | ||
: this.get('resource'); | ||
}), | ||
|
||
metricLabel: computed('metric', function() { | ||
const metric = this.get('metric'); | ||
const mappings = { | ||
cpu: 'CPU', | ||
memory: 'Memory', | ||
}; | ||
return mappings[metric] || metric; | ||
}), | ||
|
||
data: computed('resource', 'metric', 'type', function() { | ||
if (!this.get('tracker')) return []; | ||
|
||
const metric = this.get('metric'); | ||
if (this.get('type') === 'task-state') { | ||
// handle getting the right task out of the tracker | ||
const task = this.get('tracker.tasks').findBy('task', this.get('resource.name')); | ||
return task && task[metric]; | ||
} | ||
|
||
return this.get(`tracker.${metric}`); | ||
}), | ||
|
||
reservedAmount: computed('resource', 'metric', 'type', function() { | ||
const metricProperty = this.get('metric') === 'cpu' ? 'reservedCPU' : 'reservedMemory'; | ||
|
||
if (this.get('type') === 'task-state') { | ||
const task = this.get('tracker.tasks').findBy('task', this.get('resource.name')); | ||
return task[metricProperty]; | ||
} | ||
|
||
return this.get(`tracker.${metricProperty}`); | ||
}), | ||
|
||
chartClass: computed('metric', function() { | ||
const metric = this.get('metric'); | ||
const mappings = { | ||
cpu: 'is-info', | ||
memory: 'is-danger', | ||
}; | ||
|
||
return mappings[metric] || 'is-primary'; | ||
}), | ||
|
||
poller: task(function*() { | ||
do { | ||
this.get('tracker.poll').perform(); | ||
yield timeout(100); | ||
} while (!Ember.testing); | ||
}), | ||
|
||
didReceiveAttrs() { | ||
if (this.get('tracker')) { | ||
this.get('poller').perform(); | ||
} | ||
}, | ||
|
||
willDestroy() { | ||
this.get('poller').cancelAll(); | ||
this.get('tracker.signalPause').perform(); | ||
}, | ||
}); |
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 was deleted.
Oops, something went wrong.
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,49 @@ | ||
import { computed } from '@ember/object'; | ||
import Service, { inject as service } from '@ember/service'; | ||
import { LRUMap } from 'lru_map'; | ||
import NodeStatsTracker from 'nomad-ui/utils/classes/node-stats-tracker'; | ||
import AllocationStatsTracker from 'nomad-ui/utils/classes/allocation-stats-tracker'; | ||
|
||
// An unbounded number of stat trackers is a great way to gobble up all the memory | ||
// on a machine. This max number is unscientific, but aims to balance losing | ||
// stat trackers a user is likely to return to with preventing gc from freeing | ||
// memory occupied by stat trackers a user is likely to no longer care about | ||
const MAX_STAT_TRACKERS = 10; | ||
let registry; | ||
|
||
export default Service.extend({ | ||
token: service(), | ||
|
||
init() { | ||
// The LRUMap limits the number of trackers tracked by making room for | ||
// new entries beyond the limit by removing the least recently used entry. | ||
registry = new LRUMap(MAX_STAT_TRACKERS); | ||
}, | ||
|
||
// A read-only way of getting a reference to the registry. | ||
// Since this could be overwritten by a bad actor, it isn't | ||
// used in getTracker | ||
registryRef: computed(() => registry), | ||
|
||
getTracker(resource) { | ||
if (!resource) return; | ||
|
||
const type = resource && resource.constructor.modelName; | ||
const key = `${type}:${resource.get('id')}`; | ||
|
||
const cachedTracker = registry.get(key); | ||
if (cachedTracker) return cachedTracker; | ||
|
||
const Constructor = type === 'node' ? NodeStatsTracker : AllocationStatsTracker; | ||
const resourceProp = type === 'node' ? 'node' : 'allocation'; | ||
|
||
const tracker = Constructor.create({ | ||
fetch: url => this.get('token').authorizedRequest(url), | ||
[resourceProp]: resource, | ||
}); | ||
|
||
registry.set(key, tracker); | ||
|
||
return tracker; | ||
}, | ||
}); |
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 |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
|
||
& + .boxed-section-body { | ||
border-top: none; | ||
padding-top: 0.75em; | ||
} | ||
} | ||
|
||
|
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,30 @@ | ||
.primary-metric { | ||
background: $white-bis; | ||
border-radius: $radius; | ||
padding: 0.75em; | ||
color: $grey-dark; | ||
|
||
.title { | ||
color: $grey; | ||
font-weight: $weight-normal; | ||
} | ||
|
||
.primary-graphic { | ||
height: 150px; | ||
} | ||
|
||
.secondary-graphic { | ||
padding: 0.75em; | ||
padding-bottom: 0; | ||
margin-bottom: 0; | ||
|
||
> .column { | ||
padding: 0.5rem 0.75rem; | ||
} | ||
} | ||
|
||
.annotation { | ||
padding: 0 0.75em; | ||
margin-top: -0.75rem; | ||
} | ||
} |
Oops, something went wrong.