Skip to content

Commit

Permalink
fix: deployment key was missing in ingress events (#4183)
Browse files Browse the repository at this point in the history
Fixes #4181
  • Loading branch information
wesbillman authored Jan 24, 2025
1 parent 57cf1b9 commit 7684091
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions backend/ingress/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,17 @@ func (s *service) handleHTTP(startTime time.Time, sch *schema.Schema, requestKey

verbRef := &schemapb.Ref{Module: route.module, Name: route.verb}

deploymentKey, ok := s.routeTable.Current().GetDeployment(route.module).Get()
if !ok {
http.Error(w, "deployment not found", http.StatusInternalServerError)
metrics.Request(r.Context(), r.Method, r.URL.Path, optional.Some(verbRef), startTime, optional.Some("deployment not found"))
return
}

ingressEvent := timelineclient.Ingress{
RequestKey: requestKey,
StartTime: startTime,
DeploymentKey: deploymentKey,
Verb: &schema.Ref{Name: route.verb, Module: route.module},
RequestMethod: r.Method,
RequestPath: r.URL.Path,
Expand Down
19 changes: 18 additions & 1 deletion backend/ingress/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/block/ftl/common/schema"
"github.com/block/ftl/internal/key"
"github.com/block/ftl/internal/log"
"github.com/block/ftl/internal/routing"
"github.com/block/ftl/internal/schema/schemaeventsource"
"github.com/block/ftl/internal/timelineclient"
)
Expand Down Expand Up @@ -105,10 +106,26 @@ func TestIngress(t *testing.T) {
assert.NoError(t, err)
fv := &fakeVerbClient{response: response, t: t}

eventSource := schemaeventsource.NewUnattached()
testModule := &schema.Module{
Name: "test",
Runtime: &schema.ModuleRuntime{
Deployment: &schema.ModuleRuntimeDeployment{
DeploymentKey: key.NewDeploymentKey("test"),
},
},
}
// Publish the test module to the event source
eventSource.Publish(schemaeventsource.EventUpsert{
Module: testModule,
Deployment: optional.Some(key.NewDeploymentKey("test")),
})

svc := &service{
view: syncView(ctx, schemaeventsource.NewUnattached()),
view: syncView(ctx, eventSource),
client: fv,
timelineClient: timelineclient.NewClient(ctx, timelineEndpoint),
routeTable: routing.New(ctx, eventSource),
}
svc.handleHTTP(time.Now(), sch, reqKey, routes, rec, req, fv)
result := rec.Result()
Expand Down
2 changes: 2 additions & 0 deletions backend/ingress/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type service struct {
view *atomic.Value[materialisedView]
client routing.CallClient
timelineClient *timelineclient.Client
routeTable *routing.RouteTable
}

// Start the HTTP ingress service. Blocks until the context is cancelled.
Expand All @@ -51,6 +52,7 @@ func Start(ctx context.Context, config Config, schemaEventSource schemaeventsour
view: syncView(ctx, schemaEventSource),
client: client,
timelineClient: timelineClient,
routeTable: routing.New(ctx, schemaEventSource),
}

ingressHandler := otelhttp.NewHandler(http.Handler(svc), "ftl.ingress")
Expand Down

0 comments on commit 7684091

Please sign in to comment.