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

Respond PortsStatus with sorted ports #13788

Merged
merged 4 commits into from
Oct 20, 2022
Merged

Respond PortsStatus with sorted ports #13788

merged 4 commits into from
Oct 20, 2022

Conversation

mustard-mh
Copy link
Contributor

@mustard-mh mustard-mh commented Oct 12, 2022

Description

Related PR gitpod-io/openvscode-server#444

image

Related Issue(s)

How to test

  • Open workspace in preview env with ports opened. Example repo https://github.com/mustard-mh/test/tree/hw/logs-ports
  • Check if ports are sorted in PortsView
  • Check if ports are sorted in gp-cli
  • Update .gitpod.yml ports order should change order in portsView too (if file change is detect, you can change name after order change to see if it is detect or not)

Rules of order

  • First respect to .gitpod.yml 's ports define
  • Others' are sorted by port number ASC
  • Filter with ports that are not served and defined in gitpod.yml

Release Notes

Display sorted ports with both `gp-cli` and VSCode Browser `PortsView`

Documentation

Werft options:

  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-integration-tests=all
    Valid options are all, workspace, webapp, ide

@mustard-mh mustard-mh requested a review from a team October 12, 2022 06:23
@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-hw-port-responsive.6 because the annotations in the pull request description changed
(with .werft/ from main)

@akosyakov
Copy link
Member

akosyakov commented Oct 12, 2022

/hold

@mustard-mh we should respect order configured in .gitpod.yml #7764 (comment) that a user can control it

I think the order should be like:

  • configured ports with order defined as in .gitpod.yml
  • not configured but served ports sorted numerically
  • not configured and not served ports anymore sorted numerically (maybe we should just hide them all together?)

You need to create a test project with all these cases. I don't think just sorting numerically is good idea.

@mustard-mh
Copy link
Contributor Author

mustard-mh commented Oct 19, 2022

/werft run

👍 started the job as gitpod-build-hw-port-responsive.16
(with .werft/ from main)

@mustard-mh
Copy link
Contributor Author

mustard-mh commented Oct 19, 2022

/werft run

👍 started the job as gitpod-build-hw-port-responsive.18
(with .werft/ from main)

@mustard-mh mustard-mh marked this pull request as ready for review October 19, 2022 12:59
@mustard-mh mustard-mh requested a review from a team October 19, 2022 12:59
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Oct 19, 2022
@mustard-mh
Copy link
Contributor Author

Is this PR need to document / change on website? @loujaybee

@iQQBot iQQBot self-assigned this Oct 19, 2022
@@ -184,7 +186,7 @@ func parseWorkspaceConfigs(ports []*gitpod.PortConfig) (portConfigs map[uint32]*
}

func parseInstanceConfigs(ports []*gitpod.PortsItems) (portConfigs map[uint32]*gitpod.PortConfig, rangeConfigs []*RangeConfig) {
Copy link
Member

Choose a reason for hiding this comment

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

Could we instead return an ordered list and avoid specifying the sort order as a property on a map of items?

Copy link
Contributor Author

@mustard-mh mustard-mh Oct 19, 2022

Choose a reason for hiding this comment

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

Could we instead return an ordered list and avoid specifying the sort order as a property on a map of items?

I want to do it too (my first implement), but we have ranged ports (i.e. 3000-5000), if someone defined it with large range, the array will be very large too

Copy link
Member

Choose a reason for hiding this comment

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

Is this a concern around the number of bytes needed to store or some other size? I'd expect that the resulting size in bytes would be nearly identical, we're storing n items in both cases.

The extra property of Index probably costs us more as its repeated on each item as opposed to have the sorting implicit which is what a list would do.

Anyhow, just to wanted to flag this up as it felt odd.

Copy link
Contributor Author

@mustard-mh mustard-mh Oct 19, 2022

Choose a reason for hiding this comment

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

# user can define ranged port like this, and ignore if this num of port is validate or not
ports:
  - port: 100001
  - port: 1-100000

With Sort property defined, we don't need anything.

But if we use a new variable like SortedPorts array, it will contain 100001 items. Or, you need to check if this port number is inside this range or not everytime, it makes code harder to read and wastes resources while getting the ports list

Copy link
Member

Choose a reason for hiding this comment

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

We could store it as

ports: [{range: {from: 1, to: 10000}, ...}, {range: {from: 10001, to: 10001}, ...}

Which would give us the same result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or, you need to check if this port number is inside this range or not everytime

It's this case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's leave it open, and make it a follow-up PR if we are going to change it.

cc @akosyakov @iQQBot

@mustard-mh
Copy link
Contributor Author

mustard-mh commented Oct 19, 2022

/hold

To drop debug commit before merged

Copy link
Contributor

@iQQBot iQQBot left a comment

Choose a reason for hiding this comment

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

Test works, but with a small problem

pic1

pic2

(non-block) If I only update the port order in .gitpod.yml, not change name or add new port, the port order in vscode port view not change, but if I run gp ports list it works, but if I change a port name, or add new port, the vscode port view is works too

@mustard-mh
Copy link
Contributor Author

mustard-mh commented Oct 19, 2022

(non-block) If I only update the port order in .gitpod.yml, not change name or add new port, the port order in vscode port view not change, but if I run gp ports list it works, but if I change a port name, or add new port, the vscode port view is works too

@iQQBot Thanks, I will file an issue to track it 🙏

Copy link
Member

@easyCZ easyCZ left a comment

Choose a reason for hiding this comment

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

Code-wise, changes look good. I think it's awkward API-wise to put the sort index on the resulting Port object and using a sorted list would be cleaner but the port logic is in your domain ownership so feel free to go with this approach.

@mustard-mh
Copy link
Contributor Author

/unhold

@roboquat roboquat merged commit c2f7cdf into main Oct 20, 2022
@roboquat roboquat deleted the hw/port-responsive branch October 20, 2022 20:01
@@ -1756,6 +1756,7 @@ type PortConfig struct {
Visibility string `json:"visibility,omitempty"`
Description string `json:"description,omitempty"`
Name string `json:"name,omitempty"`
Sort uint32 `json:"sort,omitempty"`
Copy link
Member

@akosyakov akosyakov Oct 20, 2022

Choose a reason for hiding this comment

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

Is it something only for internal usage of supervisor? I don’t think we should have such property here then. These are types for gitpod config.

cc @mustard-mh could you remove it to avoid confusion please

@akosyakov
Copy link
Member

@mustard-mh did we consider ports which are not served and not configured but public? We need to show them always as well. Maybe even with higher priority then served but not configured.

@mustard-mh
Copy link
Contributor Author

mustard-mh commented Oct 21, 2022

@mustard-mh did we consider ports which are not served and not configured but public? We need to show them always as well. Maybe even with higher priority then served but not configured.

Yes, we did, but if we consider public means user changed the visibility of port, then private also can be one of them (private -> public -> private) and if user switch not served public to private again, it will disappear. In this case, users may don't know why private sometimes show and sometimes does not.

So, for me, I think we have only two choices:

  • Don't filter ports
  • Filter not served ports

PS. change visibility of ports should not adjust their sort, in case users click so fast (prefer to change them in the same position

cc @akosyakov

@mustard-mh
Copy link
Contributor Author

mustard-mh commented Oct 21, 2022

@akosyakov I created a follow-up PR, to move sort property exists in supervisor only. To address #13788 (comment) and don't filter not served ports

@roboquat roboquat added deployed: webapp Meta team change is running in production deployed: IDE IDE change is running in production deployed Change is completely running in production labels Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: gp cli deployed: IDE IDE change is running in production deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note size/L team: IDE team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hide unused ports from ports view(s) Remote Explorer should list ports in numerical order
6 participants