Skip to content

Commit a0f92ab

Browse files
authored
remove logs/calls apis, async, and most of hybrid (#1458)
* start from the top remove runner configuration mode * remove async, logs, calls... hybrid still has one use * add note * fix tests * remove all async verbiage / cruft * fix test * remove logs and calls from swagger * fix rebase * fix system tests * remove calls/logs from sql db adds migration and removes datastore methods * go mod tidy && go mod vendor * remove unused env vars * remove stale server options
1 parent ebbb510 commit a0f92ab

File tree

277 files changed

+272
-67227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

277 files changed

+272
-67227
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The Fn Server is only for the essential parts of the entire Fn ecosystem.
1111
These include:
1212

1313
- The core API (apps, routes, calls, logs)
14-
- Executing functions (sync and async)
14+
- Executing functions (sync)
1515
- Extension points (callbacks, middleware, API additions)
1616

1717
This does __not__ include:
@@ -86,4 +86,4 @@ Run tests inside a Docker container:
8686
```sh
8787
make docker-test
8888

89-
```
89+
```

Makefile

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,13 @@ img-mysql:
8686
img-postgres:
8787
/bin/bash -c "source ./helpers.sh && docker_pull_postgres"
8888

89-
.PHONY: img-minio
90-
img-minio:
91-
/bin/bash -c "source ./helpers.sh && docker_pull_minio"
92-
9389
.PHONY: pull-images
94-
pull-images: img-mysql img-postgres img-minio img-busybox
90+
pull-images: img-mysql img-postgres img-busybox
9591

9692
.PHONY: test-datastore
9793
test-datastore:
9894
cd api/datastore && go test ./...
9995

100-
.PHONY: test-log-datastore
101-
test-log-datastore:
102-
cd api/logs && go test ./...
103-
10496
.PHONY: test-build-arm
10597
test-build-arm:
10698
GOARCH=arm GOARM=5 $(MAKE) build

api/agent/agent.go

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,13 @@ const (
3232
pauseTimeout = 5 * time.Second // docker pause/unpause
3333
)
3434

35-
// TODO we should prob store async calls in db immediately since we're returning id (will 404 until post-execution)
36-
// TODO async calls need to add route.Headers as well
37-
// TODO handle timeouts / no response in sync & async (sync is json+503 atm, not 504, async is empty log+status)
38-
// see also: server/runner.go wrapping the response writer there, but need to handle async too (push down?)
39-
// TODO storing logs / call can push call over the timeout
40-
// TODO async is still broken, but way less so. we need to modify mq semantics
41-
// to be much more robust. now we're at least running it if we delete the msg,
42-
// but we may never store info about that execution so still broked (if fn
43-
// dies). need coordination w/ db.
44-
// TODO if async would store requests (or interchange format) it would be slick, but
45-
// if we're going to store full calls in db maybe we should only queue pointers to ids?
46-
// TODO examine cases where hot can't start a container and the user would never see an error
47-
// about why that may be so (say, whatever it is takes longer than the timeout, e.g.)
48-
// TODO if an image is not found or similar issues in getting a slot, then async should probably
49-
// mark the call as errored rather than forever trying & failing to run it
50-
// TODO it would be really nice if we made the ramToken wrap the driver cookie (less brittle,
51-
// if those leak the container leaks too...) -- not the allocation, but the token.Close and cookie.Close
52-
// TODO if machine is out of ram, just timeout immediately / wait for hot slot? (discuss policy)
53-
5435
// Agent exposes an api to create calls from various parameters and then submit
5536
// those calls, it also exposes a 'safe' shutdown mechanism via its Close method.
5637
// Agent has a few roles:
5738
// * manage the memory pool for a given server
5839
// * manage the container lifecycle for calls
5940
// * execute calls against containers
6041
// * invoke Start and End for each call appropriately
61-
// * check the mq for any async calls, and submit them
6242
//
6343
// Overview:
6444
// Upon submission of a call, Agent will start the call's timeout timer
@@ -96,7 +76,6 @@ type Agent interface {
9676

9777
type agent struct {
9878
cfg Config
99-
da CallHandler
10079
callListeners []fnext.CallListener
10180

10281
driver drivers.Driver
@@ -128,7 +107,7 @@ type Option func(*agent) error
128107
const RegistryToken = "FN_REGISTRY_TOKEN"
129108

130109
// New creates an Agent that executes functions locally as Docker containers.
131-
func New(da CallHandler, options ...Option) Agent {
110+
func New(options ...Option) Agent {
132111

133112
cfg, err := NewConfig()
134113
if err != nil {
@@ -140,7 +119,6 @@ func New(da CallHandler, options ...Option) Agent {
140119
}
141120

142121
a.shutWg = common.NewWaitGroup()
143-
a.da = da
144122
a.slotMgr = NewSlotQueueMgr()
145123
a.evictor = NewEvictor()
146124

@@ -175,19 +153,6 @@ func (a *agent) addStartup(sup func()) {
175153

176154
}
177155

178-
// WithAsync Enables Async operations on the agent
179-
func WithAsync(dqda DequeueDataAccess) Option {
180-
return func(a *agent) error {
181-
a.addStartup(func() {
182-
if !a.shutWg.AddSession(1) {
183-
logrus.Fatal("cannot start agent, unable to add session")
184-
}
185-
go a.asyncDequeue(dqda) // safe shutdown can nanny this fine
186-
})
187-
return nil
188-
}
189-
}
190-
191156
// WithConfig sets the agent config to the provided config
192157
func WithConfig(cfg *Config) Option {
193158
return func(a *agent) error {
@@ -353,18 +318,6 @@ func (a *agent) handleCallEnd(ctx context.Context, call *call, slot Slot, err er
353318
// for other containers to become idle or it may wait for resources to become
354319
// available to launch a new container.
355320
func (a *agent) getSlot(ctx context.Context, call *call) (Slot, error) {
356-
if call.Type == models.TypeAsync {
357-
// *) for async, slot deadline is also call.Timeout. This is because we would like to
358-
// allocate enough time for docker-pull, slot-wait, docker-start, etc.
359-
// and also make sure we have call.Timeout inside the container. Total time
360-
// to run an async becomes 2 * call.Timeout.
361-
// *) for sync, there's no slot deadline, the timeout is controlled by http-client
362-
// context (or runner gRPC context)
363-
tmp, cancel := context.WithTimeout(ctx, time.Duration(call.Timeout)*time.Second)
364-
ctx = tmp
365-
defer cancel()
366-
}
367-
368321
ctx, span := trace.StartSpan(ctx, "agent_get_slot")
369322
defer span.End()
370323

@@ -714,8 +667,7 @@ func (s *hotSlot) dispatch(ctx context.Context, call *call) error {
714667
func (s *hotSlot) writeResp(ctx context.Context, max uint64, resp *http.Response, w io.Writer) error {
715668
rw, ok := w.(http.ResponseWriter)
716669
if !ok {
717-
// WARNING: this bypasses container contract translation. Assuming this is
718-
// async mode, where we are storing response in call.stderr.
670+
// TODO(reed): this is strange, we should just enforce the response writer type?
719671
w = common.NewClampWriter(w, max, models.ErrFunctionResponseTooBig)
720672
return resp.Write(w)
721673
}

api/agent/agent_evict_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@ import (
1414
"github.com/fnproject/fn/api/agent/drivers"
1515
_ "github.com/fnproject/fn/api/agent/drivers/docker"
1616
"github.com/fnproject/fn/api/id"
17-
"github.com/fnproject/fn/api/logs"
1817
"github.com/fnproject/fn/api/models"
19-
"github.com/fnproject/fn/api/mqs"
2018
)
2119

2220
// create a simple non-blocking agent. Non-blocking does not queue, so it's
2321
// easier to test and see if evictions took place.
2422
func getAgentWithDriver() (Agent, drivers.Driver, error) {
25-
ls := logs.NewMock()
2623
cfg, err := NewConfig()
2724
if err != nil {
2825
return nil, nil, err
@@ -40,7 +37,7 @@ func getAgentWithDriver() (Agent, drivers.Driver, error) {
4037
return nil, nil, err
4138
}
4239

43-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)), WithConfig(cfg), WithDockerDriver(drv))
40+
a := New(WithConfig(cfg), WithDockerDriver(drv))
4441
return a, drv, nil
4542
}
4643

api/agent/agent_test.go

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ import (
2323
_ "github.com/fnproject/fn/api/agent/drivers/docker"
2424
"github.com/fnproject/fn/api/common"
2525
"github.com/fnproject/fn/api/id"
26-
"github.com/fnproject/fn/api/logs"
2726
"github.com/fnproject/fn/api/models"
28-
"github.com/fnproject/fn/api/mqs"
2927

3028
"github.com/sirupsen/logrus"
3129
)
@@ -96,9 +94,7 @@ func TestCallConfigurationRequest(t *testing.T) {
9694
},
9795
}
9896

99-
ls := logs.NewMock()
100-
101-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)))
97+
a := New()
10298
defer checkClose(t, a)
10399

104100
w := httptest.NewRecorder()
@@ -140,9 +136,6 @@ func TestCallConfigurationRequest(t *testing.T) {
140136
if model.Type != "sync" {
141137
t.Fatal("fn type mismatch", model.Type)
142138
}
143-
if model.Priority == nil {
144-
t.Fatal("GetCall should make priority non-nil so that async works because for whatever reason some clowns plumbed it all over the mqs even though the user can't specify it gg")
145-
}
146139
if model.Timeout != timeout {
147140
t.Fatal("timeout mismatch", model.Timeout, timeout)
148141
}
@@ -222,10 +215,7 @@ func TestCallConfigurationModel(t *testing.T) {
222215
Method: method,
223216
}
224217

225-
// FromModel doesn't need a datastore, for now...
226-
ls := logs.NewMock()
227-
228-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)))
218+
a := New()
229219
defer checkClose(t, a)
230220

231221
callI, err := a.GetCall(FromModel(cm))
@@ -259,10 +249,7 @@ func TestGetCallFromModelRoundTripACall(t *testing.T) {
259249
Payload: payload,
260250
}
261251

262-
// FromModel doesn't need a datastore, for now...
263-
ls := logs.NewMock()
264-
265-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)))
252+
a := New()
266253
defer checkClose(t, a)
267254

268255
callI, err := a.GetCall(FromModel(cm))
@@ -395,10 +382,7 @@ func TestSubmitError(t *testing.T) {
395382
Method: method,
396383
}
397384

398-
// FromModel doesn't need a datastore, for now...
399-
ls := logs.NewMock()
400-
401-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)))
385+
a := New()
402386
defer checkClose(t, a)
403387

404388
var wg sync.WaitGroup
@@ -453,10 +437,9 @@ func TestHungFDK(t *testing.T) {
453437

454438
url := "http://127.0.0.1:8080/invoke/" + fn.ID
455439

456-
ls := logs.NewMock()
457440
cfg, err := NewConfig()
458441
cfg.HotStartTimeout = time.Duration(3) * time.Second
459-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)), WithConfig(cfg))
442+
a := New(WithConfig(cfg))
460443
defer checkClose(t, a)
461444

462445
req, err := http.NewRequest("GET", url, &dummyReader{Reader: strings.NewReader(`{}`)})
@@ -507,10 +490,9 @@ func TestDockerPullHungRepo(t *testing.T) {
507490

508491
url := "http://127.0.0.1:8080/invoke/" + fn.ID
509492

510-
ls := logs.NewMock()
511493
cfg, err := NewConfig()
512494
cfg.HotPullTimeout = time.Duration(5) * time.Second
513-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)), WithConfig(cfg))
495+
a := New(WithConfig(cfg))
514496
defer checkClose(t, a)
515497

516498
req, err := http.NewRequest("GET", url, &dummyReader{Reader: strings.NewReader(`{}`)})
@@ -560,10 +542,9 @@ func TestDockerPullUnAuthorizedRepo(t *testing.T) {
560542

561543
url := "http://127.0.0.1:8080/invoke/" + fn.ID
562544

563-
ls := logs.NewMock()
564545
cfg, err := NewConfig()
565546
cfg.HotPullTimeout = time.Duration(5) * time.Second
566-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)), WithConfig(cfg))
547+
a := New(WithConfig(cfg))
567548
defer checkClose(t, a)
568549

569550
req, err := http.NewRequest("GET", url, &dummyReader{Reader: strings.NewReader(`{}`)})
@@ -608,9 +589,8 @@ func TestDockerPullBadRepo(t *testing.T) {
608589

609590
url := "http://127.0.0.1:8080/invoke/" + fn.ID
610591

611-
ls := logs.NewMock()
612592
cfg, err := NewConfig()
613-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)), WithConfig(cfg))
593+
a := New(WithConfig(cfg))
614594
defer checkClose(t, a)
615595

616596
req, err := http.NewRequest("GET", url, &dummyReader{Reader: strings.NewReader(`{}`)})
@@ -634,8 +614,6 @@ func TestDockerPullBadRepo(t *testing.T) {
634614
}
635615

636616
func TestHTTPWithoutContentLengthWorks(t *testing.T) {
637-
// TODO it may be a good idea to mock out the http server and use a real
638-
// response writer with sync, and also test that this works with async + log
639617
app := &models.App{ID: "app_id"}
640618
fn := &models.Fn{
641619
ID: "fn_id",
@@ -649,8 +627,7 @@ func TestHTTPWithoutContentLengthWorks(t *testing.T) {
649627

650628
url := "http://127.0.0.1:8080/invoke/" + fn.ID
651629

652-
ls := logs.NewMock()
653-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)))
630+
a := New()
654631
defer checkClose(t, a)
655632

656633
bodOne := `{"echoContent":"yodawg"}`
@@ -709,8 +686,7 @@ func TestGetCallReturnsResourceImpossibility(t *testing.T) {
709686
Memory: math.MaxUint64,
710687
}
711688

712-
ls := logs.NewMock()
713-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)))
689+
a := New()
714690
defer checkClose(t, a)
715691

716692
_, err := a.GetCall(FromModel(call))
@@ -738,8 +714,7 @@ func TestTmpFsRW(t *testing.T) {
738714

739715
url := "http://127.0.0.1:8080/invoke/" + fn.ID
740716

741-
ls := logs.NewMock()
742-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)))
717+
a := New()
743718
defer checkClose(t, a)
744719

745720
// Here we tell fn-test-utils to read file /proc/mounts and create a /tmp/salsa of 4MB
@@ -833,8 +808,7 @@ func TestTmpFsSize(t *testing.T) {
833808

834809
cfg.MaxTmpFsInodes = 1025
835810

836-
ls := logs.NewMock()
837-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)), WithConfig(cfg))
811+
a := New(WithConfig(cfg))
838812
defer checkClose(t, a)
839813

840814
// Here we tell fn-test-utils to read file /proc/mounts and create a /tmp/salsa of 4MB
@@ -988,8 +962,7 @@ func TestPipesAreClear(t *testing.T) {
988962
},
989963
}
990964

991-
ls := logs.NewMock()
992-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)))
965+
a := New()
993966
defer checkClose(t, a)
994967

995968
// test read this body after 5s (after call times out) and make sure we don't get yodawg
@@ -1132,8 +1105,7 @@ func TestCallsDontInterlace(t *testing.T) {
11321105
},
11331106
}
11341107

1135-
ls := logs.NewMock()
1136-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)))
1108+
a := New()
11371109
defer checkClose(t, a)
11381110

11391111
bodOne := `{"echoContent":"yodawg"}`
@@ -1233,8 +1205,7 @@ func TestNBIOResourceTracker(t *testing.T) {
12331205
cfg.MaxTotalMemory = 280 * 1024 * 1024
12341206
cfg.HotPoll = 20 * time.Millisecond
12351207

1236-
ls := logs.NewMock()
1237-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)), WithConfig(cfg))
1208+
a := New(WithConfig(cfg))
12381209
defer checkClose(t, a)
12391210

12401211
reqCount := 20
@@ -1300,8 +1271,7 @@ func TestDockerAuthExtn(t *testing.T) {
13001271
t.Fatalf("bad config %+v", cfg)
13011272
}
13021273

1303-
ls := logs.NewMock()
1304-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)))
1274+
a := New()
13051275
defer checkClose(t, a)
13061276

13071277
callIf, err := a.GetCall(FromModel(modelCall))
@@ -1421,8 +1391,7 @@ func TestContainerDisableIO(t *testing.T) {
14211391
t.Fatalf("bad config %+v", cfg)
14221392
}
14231393

1424-
ls := logs.NewMock()
1425-
a := New(NewDirectCallDataAccess(ls, new(mqs.Mock)))
1394+
a := New()
14261395
defer checkClose(t, a)
14271396

14281397
// NOTE: right now we disable stdin by default so this test should pass.

0 commit comments

Comments
 (0)