-
Notifications
You must be signed in to change notification settings - Fork 30
Added top consumer card for storage dashboard #349
Conversation
Pull Request Test Coverage Report for Build 1184
💛 - Coveralls |
Pull Request Test Coverage Report for Build 1230
💛 - Coveralls |
@rawagner @mareklibra Please review |
import { getTopConsumerVectorStats } from '../../../selectors'; | ||
|
||
const TopConsumersBody = ({ stats }) => { | ||
let results = 'Not data available'; |
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.
typo - should be No data available
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.
ack
export const getTopConsumerVectorStats = result => { | ||
let maxVal = 0; | ||
|
||
forEach(result, namespace => { |
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 ES6 forEach
?
let largestLengthArrayIndex = 0; | ||
|
||
// timestamps count and values are not same for all the namespaces. Hence, finding the largest length array and taking its timestamps value as x-axis point | ||
forEach(result, (namespace, index) => { |
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 ES6 forEach ?
<Row> | ||
<Col lg={12} md={12} sm={12} xs={12}> | ||
<LineChart | ||
className="kubevirt-top-consumers__body" |
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 dont see this classname in any scss
file
691f862
to
95c0933
Compare
if (stats.length) { | ||
const columnsConf = getTopConsumerVectorStats(stats); | ||
const { columns, unit } = columnsConf; | ||
const formatTime = x => { |
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.
new Date(x).toISOString().substring(11,16)
is a bit simpler. Could you please put this into utils? And maybe rename it as formatToShortISOTime
?
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.
toISOString method will return the time in zero UTC time zone. Instead of that toString method can be used.
@@ -28,3 +28,40 @@ export const getLastUtilizationStat = response => { | |||
const history = getUtilizationVectorStats(response); | |||
return history ? history[history.length - 1] : null; | |||
}; | |||
|
|||
export const getTopConsumerVectorStats = result => { |
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 please move this to prometheus/storage.js
? it is getting overcrowded here IMO.
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.
ack
export const getTopConsumerVectorStats = result => { | ||
let maxVal = 0; | ||
|
||
result.forEach(namespace => { |
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.
you can use map here instead
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 don't think map can be used here. Map method creates a new array with the results of calling a provided function on every element in the calling array. Here, I don't want to create a new array after performing the required actions. I just want to iterate over the array in order to find the max element. Hence, used forEach.
let maxVal = 0; | ||
|
||
result.forEach(namespace => { | ||
namespace.values.forEach(value => { |
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.
you could also use lodash flatMap
here and have one Math.max
call
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, flatMap will be a better solution.
}); | ||
}); | ||
|
||
const maxCapacityConveretd = { ...formatBytes(maxVal) }; |
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.
typo
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.
ack
0fd9058
to
815f232
Compare
Incorporated the review comments. @rawagner @mareklibra @suomiy Please review. |
src/selectors/prometheus/storage.js
Outdated
let flattenedResult = []; | ||
|
||
// returns all the namespace.values in an array | ||
flattenedResult = flatMap(result, namespace => namespace.values); |
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.
you can name the variables accordingly and we might not need the comments
e.g.
namespaceValues =
allValues = // allBytes ?
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.
ack
815f232
to
c4a040b
Compare
src/selectors/prometheus/storage.js
Outdated
let namespaceValues = []; | ||
let allBytes = []; | ||
|
||
namespaceValues = flatMap(result, namespace => namespace.values); |
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 be const
src/selectors/prometheus/storage.js
Outdated
let allBytes = []; | ||
|
||
namespaceValues = flatMap(result, namespace => namespace.values); | ||
allBytes = flatMap(namespaceValues, value => parseNumber(value[1])); |
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.
+ here
|
||
.kubevirt-top-consumer__time-duration { | ||
float: right; | ||
padding-right: 17px; |
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 change to rem
c4a040b
to
74657b9
Compare
ref: kubevirt/web-ui#298