diff --git a/inspektor-gadget/http.go b/inspektor-gadget/http.go index 945e82d..9deea83 100644 --- a/inspektor-gadget/http.go +++ b/inspektor-gadget/http.go @@ -25,7 +25,7 @@ func (p *InspektorGadgetPlugin) httpInvoke(operation string, handler func(contex res, err := handler(r.Context(), sdk.InvokeCtx{ Operation: operation, ParamsJSON: params, - ConfigItemID: sdk.ConfigItemIDFromContext(r.Context()), + ConfigItemID: configItemIDFromRequest(r), Host: sdk.HostClientFromContext(r.Context()), }) if err != nil { diff --git a/inspektor-gadget/http_test.go b/inspektor-gadget/http_test.go index 95b99c4..1e5a71f 100644 --- a/inspektor-gadget/http_test.go +++ b/inspektor-gadget/http_test.go @@ -1,14 +1,30 @@ package main import ( + "context" "net/http" "net/http/httptest" + "github.com/flanksource/incident-commander/plugin/sdk" ginkgo "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) var _ = ginkgo.Describe("http", func() { + ginkgo.It("passes config_id query parameters into operation invoke context", func() { + plugin := newPlugin() + handler := plugin.httpInvoke("trace-list", func(_ context.Context, req sdk.InvokeCtx) (any, error) { + Expect(req.ConfigItemID).To(Equal("config-123")) + return map[string]string{"ok": "true"}, nil + }) + + rec := httptest.NewRecorder() + req := httptest.NewRequest(http.MethodPost, "/trace-list?config_id=config-123", nil) + handler.ServeHTTP(rec, req) + + Expect(rec.Code).To(Equal(http.StatusOK)) + }) + ginkgo.It("exports buffered events as an attachment", func() { plugin := newPlugin() gadget, ok := gadgetByID("trace_exec", defaultIGTag) diff --git a/inspektor-gadget/ui-src/src/main.tsx b/inspektor-gadget/ui-src/src/main.tsx index ec25b23..fd1e040 100644 --- a/inspektor-gadget/ui-src/src/main.tsx +++ b/inspektor-gadget/ui-src/src/main.tsx @@ -244,6 +244,11 @@ function App() { return () => window.clearInterval(timer); }, []); + const activeSession = useMemo( + () => sessions.find((session) => session.id === selectedSession) || null, + [sessions, selectedSession] + ); + useEffect(() => { setEvents([]); if (!selectedSession) return; @@ -257,12 +262,7 @@ function App() { return () => { cancelled = true; }; - }, [selectedSession]); - - const activeSession = useMemo( - () => sessions.find((session) => session.id === selectedSession) || null, - [sessions, selectedSession] - ); + }, [selectedSession, activeSession?.state]); const activeGadgetSpec = useMemo( () => gadgets.find((gadget) => gadget.id === activeSession?.gadgetId) || null, [gadgets, activeSession?.gadgetId]