Intercepts
Route the traffic of an environment service to a workspace, and give it back.
Last updated
On this page
Description and operation
General
An intercept sends all traffic of one environment service to a workspace of your session. The code that you edit in the workspace answers real requests from the rest of the environment, with no build and no deploy. Callers do not change: they use the same name and port as before.
| Without an intercept | With an intercept |
|---|---|
| The service runs in the environment and answers its callers. | The service is paused. A workspace of the session answers its callers. |
| A change is tested only after a build and a deploy. | A change is tested as soon as it is saved in the workspace. |
An intercept is for the whole environment, not only for your session. Every caller of the service reaches your workspace, including the workspaces of other sessions on the environment. This is what lets several developers test their changes against each other. See Ways to work.
Ports
By default each port of the service goes to the same port in the workspace. Give ports to map a service port to another workspace port, for example api:8080 to port 3000, where a development server listens. Callers still use port 8080.
Switch
Traffic moves only when the workspace can take it, so callers never reach a workspace that is not ready.
| Step | What happens | proxy |
|---|---|---|
| 1 | The intercept is requested. The service keeps its traffic. | starting |
| 2 | The switch to the workspace is ready. The service is paused, and its traffic goes to the workspace. | ready |
| 3 | The intercept is removed. The service starts again and takes its traffic back. | (none) |
If the switch cannot be made, proxy is failed and the service keeps its traffic. An intercept is in force when the service in the environment's service_status shows interceptedBy.
Lifecycle
- Stays until removed. An intercept stays in the session's
interceptsuntil you remove it. - Workspace stopped or not answering. If the workspace stops or does not answer for 30 seconds, traffic goes back to the service. The intercept is kept, and takes hold again when the workspace is back.
- Released with the session. Deleting the workspace, changing the session's environment, ending the session or deleting the environment releases the intercept.
- Owned by one session. Only the session that holds an intercept can remove it. Another session that asks for the same service is refused, with the name of the holder.
While a service is intercepted it does not run. A queue consumer takes no messages, and a scheduled job does not run, until the intercept is removed.
Limits
| Item | Limit |
|---|---|
| Intercepts per service | 1, across all sessions on the environment. |
| Workspace | A running workspace of the session. |
| Service | Must list at least one port. |
| Ports | TCP. A workspace port cannot be 0 or 7788, which the platform uses. |
Tasks
Intercept a service
Reason for the task: Run a service from your workspace against the rest of the environment.
Job set-up
- Access: you.
- References:
POST /v1/sessions/{id}/intercepts.
All traffic of the service goes to your workspace, including other developers' traffic, and the service stops.
Procedure
Create the intercept. Map ports with
portswhen the workspace listens on another port; this example sends 8080 to 3000.from kloudlite import Kloudlitekl = Kloudlite()kl.sessions.intercept(session="dev", service="api", workspace="backend", ports={8080: 3000})import { Kloudlite } from "./index.ts";const kl = new Kloudlite();await kl.sessions.intercept({ session: "dev", service: "api", workspace: "backend", ports: { 8080: 3000 } });kl := kloudlite.New(kloudlite.Options{})_, err := kl.Sessions.Intercept(kloudlite.InterceptService{Session: "dev", Service: "api", Workspace: "backend", Ports: map[int]int{8080: 3000}})if err != nil { log.Fatal(err)}require_relative "kloudlite"kl = Kloudlite::Client.newkl.sessions.intercept(session: "dev", service: "api", workspace: "backend", ports: { 8080 => 3000 })var kl = new Kloudlite();kl.sessions().intercept(new Kloudlite.InterceptService() .session("dev").service("api").workspace("backend").ports(Map.of(8080, 3000)));kloudlite sessions intercept api --workspace backend --port 8080=3000 --session dev
Close-out
- Wait until the service in
service_statusshowsinterceptedByandproxyisready.
Show the intercepts
Reason for the task: Check which services your session routes to a workspace.
Job set-up
- Access: you.
- References:
GET /v1/sessions/{id}.
Procedure
Show the session's intercepts.
for i in kl.sessions.get(session="dev")["intercepts"]: print(i["service"], i["workspace"], i["ports"])const s: any = await kl.sessions.get({ session: "dev" });for (const i of s.intercepts) console.log(i.service, i.workspace, i.ports);s, err := kl.Sessions.Get("dev")if err != nil { log.Fatal(err)}for _, v := range s["intercepts"].([]any) { i := v.(map[string]any) fmt.Println(i["service"], i["workspace"], i["ports"])}kl.sessions.get(session: "dev")["intercepts"].each { |i| puts "#{i['service']} #{i['workspace']} #{i['ports']}" }System.out.println(kl.sessions().get("dev"));kloudlite sessions get dev
Close-out
- Make sure that every service that you intercepted is listed.
Remove an intercept
Reason for the task: Give a service its traffic back.
Job set-up
- Access: you.
- References:
DELETE /v1/sessions/{id}/intercepts/{service}.
The service starts again and takes its traffic back. Requests in flight to your workspace can fail.
Procedure
Remove the intercept.
kl.sessions.release(session="dev", service="api")await kl.sessions.release({ session: "dev", service: "api" });if err := kl.Sessions.Release(kloudlite.ReleaseService{Session: "dev", Service: "api"}); err != nil { log.Fatal(err)}kl.sessions.release(session: "dev", service: "api")kl.sessions().release(new Kloudlite.ReleaseService().session("dev").service("api"));kloudlite sessions release api --session dev
Close-out
- Show the intercepts as in task 002. Make sure that the service is gone.
Troubleshooting
| Symptom | Possible cause | Corrective action |
|---|---|---|
409 with this session has no environment | The session has no environment. | Connect an environment. |
409 with backend is not in this session; create it in the session | The workspace was not created in this session. | Use a workspace of this session, or create one in it. |
409 with that workspace is stopped | The workspace is not running. | Start the workspace. |
409 with session dev (karthik) already intercepts this service | Another session holds the intercept. | Ask the holder to release it. |
422 with service api declares no ports | The service has no port to route. | Add a port to the service. |
422 with would land on workspace port 7788 | The mapping targets the tool server. | Map to another workspace port. |
409 with api is held by session dev (karthik); release it through that session | The intercept belongs to a session. | Release it through that session. |
proxy is failed | The switch did not complete; the service keeps its traffic. | Remove the intercept and create it again. |
The intercept is requested but interceptedBy is missing | The workspace is stopped or not answering. | Start the workspace; the intercept takes hold again. |