Intercepts
Route the traffic of an environment service to a workspace, and give it back.
Last updated
On this page
Overview
An intercept sends all traffic of one environment service to a workspace of your desk. 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 desk 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 desk. Every caller of the service reaches your workspace, including the workspaces of other desks 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 desk'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 desk. Deleting the workspace, changing the desk's environment, deleting the desk, or deleting the environment releases the intercept.
- Owned by one desk. Only the desk that holds an intercept can remove it. Another desk 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 desks on the environment. |
| Workspace | A running workspace of the desk. |
| 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/desks/{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 Kodekl = Kloudlite()kl.desks.intercept(desk="dev", service="api", workspace="backend", ports={8080: 3000})import { Kode } from "./index.ts";const kl = new Kloudlite();await kl.desks.intercept({ desk: "dev", service: "api", workspace: "backend", ports: { 8080: 3000 } });kl := kloudlite.New(kloudlite.Options{})_, err := kl.Desks.Intercept(kloudlite.InterceptService{Desk: "dev", Service: "api", Workspace: "backend", Ports: map[int]int{8080: 3000}})if err != nil { log.Fatal(err)}require_relative "kloudlite"kl = Kloudlite::Client.newkl.desks.intercept(desk: "dev", service: "api", workspace: "backend", ports: { 8080 => 3000 })var kl = new Kloudlite();kl.desks().intercept(new Kloudlite.InterceptService() .desk("dev").service("api").workspace("backend").ports(Map.of(8080, 3000)));kode desks intercept api --workspace backend --port 8080=3000 --desk dev
Close-out
- Wait until the service in
service_statusshowsinterceptedByandproxyisready.
List the intercepts
Reason for the task
Check which services your desk routes to a workspace.
Job set-up
- Access: you.
- References:
GET /v1/desks/{id}.
Procedure
Show the desk's intercepts.
for i in kl.desks.get(desk="dev")["intercepts"]: print(i["service"], i["workspace"], i["ports"])const s: any = await kl.desks.get({ desk: "dev" });for (const i of s.intercepts) console.log(i.service, i.workspace, i.ports);s, err := kl.Desks.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.desks.get(desk: "dev")["intercepts"].each { |i| puts "#{i['service']} #{i['workspace']} #{i['ports']}" }System.out.println(kl.desks().get("dev"));kode desks 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/desks/{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.desks.release(desk="dev", service="api")await kl.desks.release({ desk: "dev", service: "api" });if err := kl.Desks.Release(kloudlite.ReleaseService{Desk: "dev", Service: "api"}); err != nil { log.Fatal(err)}kl.desks.release(desk: "dev", service: "api")kl.desks().release(new Kloudlite.ReleaseService().desk("dev").service("api"));kode desks release api --desk dev
Close-out
- List the intercepts as in task 002. Make sure that the service is gone.
Troubleshooting
| Symptom | Possible cause | Corrective action |
|---|---|---|
409 with this desk has no environment | The desk has no environment. | Connect an environment. |
409 with backend is not in this desk; create it in the desk | The workspace was not created in this desk. | Use a workspace of this desk, or create one in it. |
409 with that workspace is stopped | The workspace is not running. | Start the workspace. |
409 with desk dev (karthik) already intercepts this service | Another desk 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 desk dev (karthik); release it through that desk | The intercept belongs to a desk. | Release it through that desk. |
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. |