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

[server] listWorkspaceSessions API #19733

Merged
merged 1 commit into from May 13, 2024
Merged

[server] listWorkspaceSessions API #19733

merged 1 commit into from May 13, 2024

Conversation

svenefftinge
Copy link
Member

@svenefftinge svenefftinge commented May 10, 2024

Description

Introduces a new RPC for listing workspaces sessions (aka as workspace instances internally).
The API uses the same workspace shape which is already a shape that combines information from a workspace and a workspaceInstance (usually the latest one).

Related Issue(s)

Fixes https://linear.app/gitpod/issue/ENT-66/add-listworkspacesessions-rpc-call-to-workspace-service-endpoint

How to test

https://se-workspad026375d1b.preview.gitpod-dev.com/workspaces

Create a bunch of workspaces and also restart them in order to create multiple instances per workspace.
Ideally also do this with different users in the same work.

Use the new API to list the sessions and verify the data represents the system state.

curl -X POST \
  'https://api.gitpod.io/gitpod.v1.WorkspaceService/ListWorkspaceSessions' \
  --header 'Authorization: Bearer <YOUR_ACCESS_TOKEN>' \
  --header 'content-type: application/json' \
  --data-raw '{
      "organizationId": "<ORG_ID>"
}'

Documentation

Preview status

gitpod:summary

Build Options

Build
  • /werft with-werft
    Run the build with werft instead of GHA
  • leeway-no-cache
  • /werft no-test
    Run Leeway with --dont-test
Publish
  • /werft publish-to-npm
  • /werft publish-to-jb-marketplace
Installer
  • analytics=segment
  • with-dedicated-emulation
  • workspace-feature-flags
    Add desired feature flags to the end of the line above, space separated
Preview Environment / Integration Tests
  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-gce-vm
    If enabled this will create the environment on GCE infra
  • /werft preemptible
    Saves cost. Untick this only if you're really sure you need a non-preemtible machine.
  • with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh. If enabled, with-preview and with-large-vm will be enabled.
  • with-monitoring

/hold

@mustard-mh
Copy link
Contributor

mustard-mh commented May 10, 2024

API responded 🐰 , generally LGTM

  • Phase is missing but maybe not that important for ENT-66?
  • ❓ No stop reason (timed out / others)
  • ❓ No result (prebuild result) see data example below, that prebuild was canceled manually
respond data example
{
    "pagination": {
        "total": 3
    },
    "workspaceSessions": [
        {
            "workspace": {
                "id": "mustardmh-springpetclin-83qmuz2qpc0",
                "metadata": {
                    "ownerId": "ebfa0776-c604-4b62-98b4-fd74f3d58c5c",
                    "organizationId": "3b921ba3-62ef-4e3b-a644-08ab30f4fd2d",
                    "configurationId": "e0afbde4-d188-4e35-bb64-7eea78dae046",
                    "name": "mustard-mh/spring-petclinic - master",
                    "originalContextUrl": "https://github.com/mustard-mh/spring-petclinic/tree/master"
                },
                "spec": {
                    "initializer": {
                        "specs": [
                            {
                                "git": {
                                    "remoteUri": "https://github.com/mustard-mh/spring-petclinic.git",
                                    "upstreamRemoteUri": "https://github.com/gitpod-samples/spring-petclinic.git",
                                    "targetMode": "CLONE_TARGET_MODE_REMOTE_COMMIT",
                                    "cloneTarget": "b84fc2ca666c336a0468c65ac636d0a41499d68e",
                                    "checkoutLocation": "spring-petclinic",
                                    "config": {}
                                }
                            }
                        ]
                    },
                    "type": "WORKSPACE_TYPE_PREBUILD",
                    "git": {},
                    "admission": "ADMISSION_LEVEL_OWNER_ONLY"
                },
                "status": {
                    "phase": {
                        "lastTransitionTime": "2024-05-10T15:32:15.383Z"
                    },
                    "prebuildResult": {},
                    "gitStatus": {
                        "cloneUrl": "https://github.com/mustard-mh/spring-petclinic.git",
                        "branch": "master",
                        "latestCommit": "b84fc2ca666c336a0468c65ac636d0a41499d68e"
                    }
                }
            },
            "creationTime": "2024-05-10T15:32:15.749Z",
            "startedTime": "2024-05-10T15:32:58.605Z",
            "stoppingTime": "2024-05-10T15:34:04.823Z",
            "stoppedTime": "2024-05-10T15:34:05.308Z"
        },
        {
            "workspace": {
                "id": "mustardmh-templatesvelt-08aia0x8m0e",
                "metadata": {
                    "ownerId": "ebfa0776-c604-4b62-98b4-fd74f3d58c5c",
                    "organizationId": "3b921ba3-62ef-4e3b-a644-08ab30f4fd2d",
                    "name": "#1: Update README.md",
                    "originalContextUrl": "https://github.com/mustard-mh/template-sveltejs/pull/1"
                },
                "spec": {
                    "initializer": {
                        "specs": [
                            {
                                "git": {
                                    "remoteUri": "https://github.com/mustard-mh/template-sveltejs.git",
                                    "targetMode": "CLONE_TARGET_MODE_REMOTE_COMMIT",
                                    "cloneTarget": "eb6a71af3aa82c9b1e979981d213676dd8879a2b",
                                    "checkoutLocation": "template-sveltejs",
                                    "config": {}
                                }
                            }
                        ]
                    },
                    "type": "WORKSPACE_TYPE_REGULAR",
                    "git": {},
                    "admission": "ADMISSION_LEVEL_OWNER_ONLY"
                },
                "status": {
                    "phase": {
                        "lastTransitionTime": "2024-05-10T15:22:50.064Z"
                    },
                    "gitStatus": {
                        "cloneUrl": "https://github.com/mustard-mh/template-sveltejs.git",
                        "branch": "hw/test-pr",
                        "latestCommit": "eb6a71af3aa82c9b1e979981d213676dd8879a2b"
                    }
                }
            },
            "creationTime": "2024-05-10T15:22:50.133Z",
            "startedTime": "2024-05-10T15:23:39.126Z",
            "stoppingTime": "2024-05-10T15:28:09.747Z",
            "stoppedTime": "2024-05-10T15:29:01.072Z"
        },
        {
            "workspace": {
                "id": "mustardmh-springpetclin-ih7cfpagvx5",
                "metadata": {
                    "ownerId": "ebfa0776-c604-4b62-98b4-fd74f3d58c5c",
                    "organizationId": "3b921ba3-62ef-4e3b-a644-08ab30f4fd2d",
                    "name": "mustard-mh/spring-petclinic - master",
                    "originalContextUrl": "https://github.com/mustard-mh/spring-petclinic"
                },
                "spec": {
                    "initializer": {
                        "specs": [
                            {
                                "git": {
                                    "remoteUri": "https://github.com/mustard-mh/spring-petclinic.git",
                                    "upstreamRemoteUri": "https://github.com/gitpod-samples/spring-petclinic.git",
                                    "targetMode": "CLONE_TARGET_MODE_REMOTE_COMMIT",
                                    "cloneTarget": "b84fc2ca666c336a0468c65ac636d0a41499d68e",
                                    "checkoutLocation": "spring-petclinic",
                                    "config": {}
                                }
                            }
                        ]
                    },
                    "type": "WORKSPACE_TYPE_REGULAR",
                    "git": {},
                    "admission": "ADMISSION_LEVEL_OWNER_ONLY"
                },
                "status": {
                    "phase": {
                        "lastTransitionTime": "2024-05-10T15:21:55.878Z"
                    },
                    "gitStatus": {
                        "cloneUrl": "https://github.com/mustard-mh/spring-petclinic.git",
                        "branch": "master",
                        "latestCommit": "b84fc2ca666c336a0468c65ac636d0a41499d68e"
                    }
                }
            },
            "creationTime": "2024-05-10T15:21:55.942Z",
            "startedTime": "2024-05-10T15:23:31.378Z"
        }
    ]
}

Copy link
Contributor

@mustard-mh mustard-mh left a comment

Choose a reason for hiding this comment

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

Approve to unblock. I'm not quite sure about the filter, i.e. can user find out which workspace (instance) made which usage data? But if we treat them as two different APIs, then I'm good with it (or let's wait users' feedback)

Don't forget to check last comment above (<3)

@@ -448,53 +448,32 @@ export class TypeORMWorkspaceDBImpl extends TransactionalDBImpl<WorkspaceDB> imp
}

public async findSessionsInPeriod(
Copy link
Member

Choose a reason for hiding this comment

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

Nice, this was actually dead code since the PAYG transition! 🧡

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

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

Concept + code changes LGTM ✔️

Really like that we are only exposing the bare minimum from the instance (timestamps). 👍

Copy link

gitguardian bot commented May 13, 2024

⚠️ GitGuardian has uncovered 3 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
11010498 Triggered Generic High Entropy Secret aedc230 components/public-api/typescript-common/fixtures/toWorkspaceSession_2.json View secret
11010499 Triggered Generic High Entropy Secret aedc230 components/public-api/typescript-common/fixtures/toWorkspaceSession_3.json View secret
11010501 Triggered Generic High Entropy Secret aedc230 components/public-api/typescript-common/fixtures/toWorkspaceSession_4.json View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@svenefftinge
Copy link
Member Author

/unhold

@roboquat roboquat merged commit 2a397c3 into main May 13, 2024
13 of 15 checks passed
@roboquat roboquat deleted the se/workspace-sessions branch May 13, 2024 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants