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

CNV-16653: Statistics of secondary network interfaces #1033

Merged

Conversation

DanaOrr
Copy link
Contributor

@DanaOrr DanaOrr commented Jan 31, 2023

Signed-off-by: Dana Orr dorr@redhat.com

📝 Description

Adding the option to see in a popover on the overview page the network interfaces that the machine has.
And I added on the metrics page the possibility to see the network in, out and bandwidth graphs for each NIC and for all of them together.

🎥 Demo

Before:
On the overview page:
image
On the metrics page:
image

After:
NetworkInterfaceDemoNew2

@openshift-ci-robot
Copy link
Collaborator

@DanaOrr: This pull request references CNV-16653 which is a valid jira issue.

In response to this:

Signed-off-by: Dana Orr dorr@redhat.com

📝 Description

Adding the option to see in a popover on the overview page the network interfaces that the machine has.
And I added on the metrics page the possibility to see the network in, out and bandwidth graphs for each NIC and for all of them together.

🎥 Demo

Before:
On the overview page:
image
On the metrics page:
image

After:
NetworkInterfaceDemoNew2

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

@hstastna hstastna left a comment

Choose a reason for hiding this comment

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

Left some comments and questions, PTAL. Otherwise great work, Dana! :)

const totalTransferred = xbytes(networkInData + networkOutData || 0, {
iec: true,
fixed: 0,
});

const networkInterfacesLength = interfacesNames?.length;

Choose a reason for hiding this comment

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

I think you can use interfacesNames?.length directly in the line 92. No need to create a new variable for this, as this is very short and not used in any other places within this file :)

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`;

Choose a reason for hiding this comment

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

Hmm, do we really need to use toString for the index in here, if we are using a template literal (with backticks `) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you right👍

const legendData =
!isEmpty(chartData) &&
chartData?.map((newChartdata, index) => {
return { childName: newChartdata?.[index]?.name, name: newChartdata?.[index]?.name };

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 and name seem to be identical. is this intentional?

Copy link
Contributor Author

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...

[vmi],
const { t } = useKubevirtTranslation();
const interfacesNames = useMemo(() => {
const interfaces = vmi?.spec?.domain?.devices?.interfaces.map((nic) => nic?.name);

Choose a reason for hiding this comment

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

Maybe better ...vmi?.spec?.domain?.devices?.interfaces?.map((nic) => ... to make sure some interfaces are present :)

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const interfaces = vmi?.spec?.domain?.devices?.interfaces.map((nic) => nic?.name);
const interfaces = vmi?.spec?.domain?.devices?.interfaces?.map((nic) => nic?.name);

@@ -1,12 +1,17 @@
import React from 'react';
/* eslint-disable react-hooks/rules-of-hooks */

Choose a reason for hiding this comment

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

Do we really have to use this here? Feels like we are going to disrespect some rules... IMO we should avoid doing this as much as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

to={`${getResourceUrl({
model: VirtualMachineModel,
resource: vmi,
})}/metrics?network=All networks`}

Choose a reason for hiding this comment

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

This looks kinda weird, I mean the space in the link, between All and networks. Are you sure this is working as expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it works as expected, but I deleted "all networks" and it will move to the same place I wanted,
so it's better to delete, thank you :)

@DanaOrr DanaOrr force-pushed the secondary-network-interfaces branch 2 times, most recently from a19b372 to b77f4b3 Compare February 1, 2023 13:31
});
const isReady = !isEmpty(chartData);

const findChartMaxYAxis = (chartData1: { x: Date; y: number; name: string }[][]) => {
Copy link
Member

Choose a reason for hiding this comment

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

can be exported to util file?

return maxY;
};
const Ymax = findChartMaxYAxis(chartData);
const tickValues = Array.from({ length: Ymax + 1 }, (_, index) => {
Copy link
Member

Choose a reason for hiding this comment

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

can be exported to util file?

Choose a reason for hiding this comment

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

@DanaOrr maybe it worth to move it to src/utils/components/Charts/utils/utils.ts ?

});

const isReady = !isEmpty(chartData);
const newTickFormat = (tick: any, index: number, ticks: any[]) => {
Copy link
Member

Choose a reason for hiding this comment

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

can be exported to util file?
please consider changing the name to something more informative

/>
{isReady &&
chartData?.map((newChartdata) => (
// eslint-disable-next-line react/jsx-key
Copy link
Member

Choose a reason for hiding this comment

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

why?

return [
{
...response?.data?.result?.[0],
metric: { ...response?.data?.result?.[0]?.metric, interface: 'all-networks' },
Copy link
Member

Choose a reason for hiding this comment

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

consider transforming all-network string to a const

@@ -28,40 +34,80 @@ const useNetworkData: UseNetworkData = (vmi, nic) => {
[vmi, duration, nic],
);

const isAllNetwork = nic === 'All networks';
Copy link
Member

Choose a reason for hiding this comment

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

consider using a const for all networks

resource: vmi,
})}/metrics?network=${networkInterface.name}`}
>
{networkInterface.name}
Copy link
Member

Choose a reason for hiding this comment

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

please add ?.

Copy link
Member

Choose a reason for hiding this comment

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

all over the file where needed

@DanaOrr
Copy link
Contributor Author

DanaOrr commented Feb 8, 2023

/retest

@DanaOrr DanaOrr force-pushed the secondary-network-interfaces branch from c4481ce to 2e60c6b Compare February 9, 2023 11:56
@upalatucci
Copy link
Member

/retest

@upalatucci
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Passed code review, ready for merge label Feb 9, 2023
Copy link

@hstastna hstastna left a comment

Choose a reason for hiding this comment

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

Some more little changes and we are good to go! ;)

return singleNic ? [singleNic] : response?.data?.result;
};

export const allNetworks = 'All networks';
Copy link

@hstastna hstastna Feb 9, 2023

Choose a reason for hiding this comment

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

Please, use THIS_FORMAT for constants like that, and place constants into constants.ts file, under utils dir (if there isn't such a file, feel free to create it). It is better to have constants in a separate file :)
Additionally, don't be afraid to use the constant where needed. For example, I can see in NetworkCharts.tsx in this PR 'All networks' string instead of a constant.


const interfacesNames = useMemo(() => {
const interfaces = vmi?.spec?.domain?.devices?.interfaces?.map((nic) => nic?.name);
interfaces?.unshift('All networks');
Copy link

Choose a reason for hiding this comment

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

You could use the constant in here, for 'All networks' ;)

const query = useQuery();
const [isDropdownOpen, setIsDropdownOpen] = React.useState<boolean>(false);
const [selectedNetwork, setSelectedNetwork] = React.useState<string>(
query?.get('network') || 'All networks',
Copy link

Choose a reason for hiding this comment

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

You could use the constant in here, for 'All networks', too ;)

PrometheusResponse,
PrometheusResult,
PrometheusValue,
} from '@openshift-console/dynamic-plugin-sdk';

export const SINGLE_VM_DURATION = 'SINGLE_VM_DURATION';
export const TICKS_COUNT = 100;
Copy link

Choose a reason for hiding this comment

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

I'd move those constants into a separate constants.ts file ;) WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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..
so maybe in another PR? :)

@openshift-ci openshift-ci bot removed the lgtm Passed code review, ready for merge label Feb 9, 2023
@metalice
Copy link
Member

/approve

@openshift-ci openshift-ci bot added the approved This issue is something we want to fix label Feb 13, 2023
Copy link

@hstastna hstastna left a comment

Choose a reason for hiding this comment

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

Some more little things, otherwise great work! :)

return maxY;
};
const Ymax = findChartMaxYAxis(chartData);
const tickValues = Array.from({ length: Ymax + 1 }, (_, index) => {

Choose a reason for hiding this comment

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

@DanaOrr maybe it worth to move it to src/utils/components/Charts/utils/utils.ts ?

.network-poppver {
display: flex;
justify-content: space-between;
}

Choose a reason for hiding this comment

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

.network-poppver {
  display: flex;
  justify-content: space-between;
}

plus maybe it is nicer also to use "popover" instead of "poppver" to have this class more self-explanatory :)

Choose a reason for hiding this comment

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

Thanks for making this nicer, Dana! :) 👍🏽

@DanaOrr DanaOrr force-pushed the secondary-network-interfaces branch 4 times, most recently from 5c99632 to cb5e5f6 Compare February 13, 2023 14:15
@DanaOrr
Copy link
Contributor Author

DanaOrr commented Feb 14, 2023

/retest

Copy link

@hstastna hstastna left a comment

Choose a reason for hiding this comment

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

I've added another little comment for even better code ;) ...

position="bottom"
>
<div>
<Button variant="link" isInline>

Choose a reason for hiding this comment

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

It's better to use variant={ButtonVariant.link} :)
(Sorry, I didn't see that earlier)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you Hilda ! :)

.network-poppver {
display: flex;
justify-content: space-between;
}

Choose a reason for hiding this comment

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

Thanks for making this nicer, Dana! :) 👍🏽

Signed-off-by: Dana Orr <dorr@redhat.com>
@openshift-ci openshift-ci bot added the lgtm Passed code review, ready for merge label Feb 15, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 15, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DanaOrr, hstastna, metalice, upalatucci

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit e903e43 into kubevirt-ui:main Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved This issue is something we want to fix lgtm Passed code review, ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants