fix(provider/lambdai): align client with the Lambda topology API#374
fix(provider/lambdai): align client with the Lambda topology API#374alaski-lambda wants to merge 1 commit into
Conversation
Match the deployed API: query GET /api/v1/topology/instance with the
required region parameter, parse the {data, page_token} envelope and
paginate via page_token, and model networkPath as {id} objects mapped to
leaf/spine/core. Update the simulator and add an httptest covering the
request contract, envelope, pagination, and mapping.
Signed-off-by: Andrew Laski <alaski@lambdal.com>
Greptile SummaryThis PR aligns the Lambda AI provider client with the deployed topology API by correcting the endpoint path (
Confidence Score: 4/5The change is straightforward API alignment with a well-scoped impact; the pagination loop, region validation, and envelope parsing are all correct. The core logic is correct: region is validated before use, JSON null for page_token correctly unmarshals to empty string and terminates the loop, and the NetworkHop.ID mapping matches the documented API shape. The new httptest test provides good contract coverage. The only finding is a test-safety issue — require.Equal inside the httptest handler goroutine can panic rather than cleanly fail the test — which does not affect production behavior but could make test failures harder to diagnose. pkg/providers/lambdai/provider_test.go — the handler goroutine assertion pattern. Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant C as GenerateTopologyConfig
participant L as InstanceList (lambdaiClient)
participant API as Lambda /api/v1/topology/instance
C->>L: "InstanceListRequest{Region, PageSize}"
L->>API: "GET ?workspace_id=®ion=&page_size="
API-->>L: "{"data":[...], "page_token":"tok2"}"
L-->>C: "InstanceListResponse{Items, NextPageToken="tok2"}"
C->>L: "InstanceListRequest{Region, PageSize, PageToken="tok2"}"
L->>API: "GET ?workspace_id=®ion=&page_size=&page_token=tok2"
API-->>L: "{"data":[...], "page_token":null}"
L-->>C: "InstanceListResponse{Items, NextPageToken=""}"
Note over C: NextPageToken == "" → stop
C->>C: Build ClusterTopology from NetworkHop.ID (leaf/spine/core)
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant C as GenerateTopologyConfig
participant L as InstanceList (lambdaiClient)
participant API as Lambda /api/v1/topology/instance
C->>L: "InstanceListRequest{Region, PageSize}"
L->>API: "GET ?workspace_id=®ion=&page_size="
API-->>L: "{"data":[...], "page_token":"tok2"}"
L-->>C: "InstanceListResponse{Items, NextPageToken="tok2"}"
C->>L: "InstanceListRequest{Region, PageSize, PageToken="tok2"}"
L->>API: "GET ?workspace_id=®ion=&page_size=&page_token=tok2"
API-->>L: "{"data":[...], "page_token":null}"
L-->>C: "InstanceListResponse{Items, NextPageToken=""}"
Note over C: NextPageToken == "" → stop
C->>C: Build ClusterTopology from NetworkHop.ID (leaf/spine/core)
Reviews (1): Last reviewed commit: "fix(provider/lambdai): align client with..." | Re-trigger Greptile |
|
|
||
| var paths, regions, workspaces, auths []string | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| require.Equal(t, http.MethodGet, r.Method) |
There was a problem hiding this comment.
require inside handler goroutine may panic instead of failing cleanly
require.Equal calls t.FailNow(), which per Go's testing docs must only be called from the goroutine running the test function. Calling it from a goroutine managed by httptest.Server can cause a panic (via runtime.Goexit) rather than a clean test failure. Using assert.Equal (which calls t.Fail() and returns normally) is the safe pattern for assertions inside HTTP handlers.
Description
Match the deployed API: query GET /api/v1/topology/instance with the required region parameter, parse the {data, page_token} envelope and paginate via page_token, and model networkPath as {id} objects mapped to leaf/spine/core. Update the simulator and add an httptest covering the request contract, envelope, pagination, and mapping.
Checklist
git commit -s).