-
Notifications
You must be signed in to change notification settings - Fork 30
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
CNV-16653: Statistics of secondary network interfaces #1033
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import DurationOption from '@kubevirt-utils/components/DurationOption/DurationOption'; | ||
import { PrometheusResponse, PrometheusValue } from '@openshift-console/dynamic-plugin-sdk'; | ||
import { isEmpty } from '@kubevirt-utils/utils/utils'; | ||
import { | ||
PrometheusResponse, | ||
PrometheusResult, | ||
PrometheusValue, | ||
} from '@openshift-console/dynamic-plugin-sdk'; | ||
import { ALL_NETWORKS } from '@virtualmachines/details/tabs/metrics/utils/constants'; | ||
|
||
export const SINGLE_VM_DURATION = 'SINGLE_VM_DURATION'; | ||
export const TICKS_COUNT = 100; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd move those constants into a separate constants.ts file ;) WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a good idea but it requires me to change the import to many more files and it creates a load on this PR.. |
||
|
@@ -32,5 +38,55 @@ export const tickFormat = | |
return ''; | ||
}; | ||
|
||
export const getPrometheusData = (response: PrometheusResponse): PrometheusValue[] => | ||
response?.data?.result?.[0]?.values; | ||
export const getPrometheusData = (response: PrometheusResponse): PrometheusValue[] => { | ||
return response?.data?.result?.[0]?.values; | ||
}; | ||
|
||
export const getPrometheusDataByNic = ( | ||
response: PrometheusResponse, | ||
nic: string, | ||
): PrometheusResult[] => { | ||
if (!response?.data?.result) { | ||
return []; | ||
} | ||
const singleNic = response?.data?.result?.find((res) => res.metric?.interface === nic); | ||
return singleNic ? [singleNic] : response?.data?.result; | ||
}; | ||
|
||
export const getPrometheusDataAllNics = (response: PrometheusResponse): PrometheusResult[] => { | ||
if (!response?.data?.result) { | ||
return []; | ||
} | ||
return [ | ||
{ | ||
...response?.data?.result?.[0], | ||
metric: { ...response?.data?.result?.[0]?.metric, interface: ALL_NETWORKS }, | ||
}, | ||
]; | ||
}; | ||
export const findChartMaxYAxis = (chartData: { x: Date; y: number; name: string }[][]) => { | ||
const yValues = | ||
!isEmpty(chartData) && | ||
chartData?.map((dataArray) => { | ||
return Math.max(...dataArray?.map((data) => data?.y)); | ||
}); | ||
const maxY = Math.max(...(yValues || [])); | ||
return maxY; | ||
}; | ||
|
||
export const tickValue = (Ymax: number) => { | ||
const tickValues = Array.from({ length: Ymax + 1 }, (_, index) => { | ||
if (index === 0) return '1 Bps'; | ||
if (index === Math.round(Ymax)) return `${Math.round(Ymax + 1)} Bps`; | ||
return index.toString() + ' Bps'; | ||
}); | ||
return tickValues; | ||
}; | ||
export const yTickFormat = (tick: any, index: number, ticks: any[]) => { | ||
const isFirst = index === 0; | ||
const isLast = index === ticks.length - 1; | ||
if (isLast || isFirst) { | ||
return tick; | ||
} | ||
return; | ||
}; |
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 the values for
childName
andname
seem to be identical. is this intentional?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.
The childName is used to synchronize the data series associated with the given chart name so it is better to have the same name I think...