Skip to content
DocsAll docs
Console

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

StepWhat happensproxy
1The intercept is requested. The service keeps its traffic.starting
2The switch to the workspace is ready. The service is paused, and its traffic goes to the workspace.ready
3The 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 intercepts until 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.
CAUTION

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

ItemLimit
Intercepts per service1, across all sessions on the environment.
WorkspaceA running workspace of the session.
ServiceMust list at least one port.
PortsTCP. 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

CAUTION

All traffic of the service goes to your workspace, including other developers' traffic, and the service stops.

Procedure

  1. Create the intercept. Map ports with ports when the workspace listens on another port; this example sends 8080 to 3000.

    Python
    from kloudlite import Kloudlitekl = Kloudlite()kl.sessions.intercept(session="dev", service="api", workspace="backend", ports={8080: 3000})
    TypeScript
    import { Kloudlite } from "./index.ts";const kl = new Kloudlite();await kl.sessions.intercept({ session: "dev", service: "api", workspace: "backend", ports: { 8080: 3000 } });
    Go
    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)}
    Ruby
    require_relative "kloudlite"kl = Kloudlite::Client.newkl.sessions.intercept(session: "dev", service: "api", workspace: "backend", ports: { 8080 => 3000 })
    Java
    var kl = new Kloudlite();kl.sessions().intercept(new Kloudlite.InterceptService()    .session("dev").service("api").workspace("backend").ports(Map.of(8080, 3000)));
    CLI
    kloudlite sessions intercept api --workspace backend --port 8080=3000 --session dev

Close-out

  1. Wait until the service in service_status shows interceptedBy and proxy is ready.

Show the intercepts

Reason for the task: Check which services your session routes to a workspace.

Job set-up

Procedure

  1. Show the session's intercepts.

    Python
    for i in kl.sessions.get(session="dev")["intercepts"]:    print(i["service"], i["workspace"], i["ports"])
    TypeScript
    const s: any = await kl.sessions.get({ session: "dev" });for (const i of s.intercepts) console.log(i.service, i.workspace, i.ports);
    Go
    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"])}
    Ruby
    kl.sessions.get(session: "dev")["intercepts"].each { |i| puts "#{i['service']} #{i['workspace']} #{i['ports']}" }
    Java
    System.out.println(kl.sessions().get("dev"));
    CLI
    kloudlite sessions get dev

Close-out

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

CAUTION

The service starts again and takes its traffic back. Requests in flight to your workspace can fail.

Procedure

  1. Remove the intercept.

    Python
    kl.sessions.release(session="dev", service="api")
    TypeScript
    await kl.sessions.release({ session: "dev", service: "api" });
    Go
    if err := kl.Sessions.Release(kloudlite.ReleaseService{Session: "dev", Service: "api"}); err != nil {    log.Fatal(err)}
    Ruby
    kl.sessions.release(session: "dev", service: "api")
    Java
    kl.sessions().release(new Kloudlite.ReleaseService().session("dev").service("api"));
    CLI
    kloudlite sessions release api --session dev

Close-out

  1. Show the intercepts as in task 002. Make sure that the service is gone.

Troubleshooting

SymptomPossible causeCorrective action
409 with this session has no environmentThe session has no environment.Connect an environment.
409 with backend is not in this session; create it in the sessionThe workspace was not created in this session.Use a workspace of this session, or create one in it.
409 with that workspace is stoppedThe workspace is not running.Start the workspace.
409 with session dev (karthik) already intercepts this serviceAnother session holds the intercept.Ask the holder to release it.
422 with service api declares no portsThe service has no port to route.Add a port to the service.
422 with would land on workspace port 7788The mapping targets the tool server.Map to another workspace port.
409 with api is held by session dev (karthik); release it through that sessionThe intercept belongs to a session.Release it through that session.
proxy is failedThe switch did not complete; the service keeps its traffic.Remove the intercept and create it again.
The intercept is requested but interceptedBy is missingThe workspace is stopped or not answering.Start the workspace; the intercept takes hold again.