Commit Graph

747 Commits

Author SHA1 Message Date
Reed Allman
337e962416 add pagination to all list endpoints
calls, apps, and routes listing were previously returning the entire data set,
which just won't scale. this adds pagination with cursoring forward to each of
these endpoints (see the [docs](docs/definitions.md)).

the patch is really mostly tests, shouldn't be that bad to pick through.

some blarble about implementation is in order:

calls are sorted by ids but allow searching within certain `created_at` ranges
(finally). this is because sorting by `created_at` isn't feasible when
combined with paging, as `created_at` is not guaranteed to be unique -- id's
are (eliding theoreticals). i.e. on a page boundary, if there are 200 calls
with the same `created_at`, providing a `cursor` of that `created_at` will
skip over the remaining N calls with that `created_at`.  also using id will be
better on the index anyway (well, less of them). yay having sortable ids! I
can't discern any issues doing this, as even if 200 calls have the same
created_at, they will have different ids, and the sort should allow paginating
them just fine. ids are also url safe, so the id works as the cursor value
just fine.

apps and routes are sorted by alphabetical order. as they aren't guaranteed to
be url safe, we are base64'ing them in the front end to a url safe format and
then returning them, and then base64 decoding them when we get them. this does
mean that they can be relatively large if the path/app is long, but if we
don't want to add ids then they were going to be pretty big anyway. a bonus
that this kind of obscures them. if somebody has better idea on formatting, by
all means.

notably, we are not using the sql paging facilities, and we are baking our own
based on cursors, which ends up being much more efficient for querying longer
lists of resources. this also should be easy to implement in other non-sql dbs
and the cursoring formats we can change on the fly since we are just exposing
them as opaque strings. the front end deals with the base64 / formatting, etc
and the back end is taking raw values (strfmt.DateTime or the id for calls).
the cursor that is being passed to/by the user is simply the last resource on the
previous page, so in theory we don't even need to return it, but it does make
it a little easier to use, also, cursor being blank on the last page depends
on page full-ness, so sometimes users will get a cursor when there are no
results on next page (1/N chance, and it's not really end of world -- actually
searching for the next thing would make things more complex). there are ample
tests for this behavior.

I've turned off all query parameters allowing `LIKE` queries on certain listing
endpoints, as we should not expose sql behavior through our API in the event
that we end up not using a sql db down the road. I think we should only allow
prefix matching, which sql can support as well as other types of databases
relatively cheaply, but this is not hooked up here as it didn't 'just work'
when I was fiddling with it (can add later, they're unnecessary and weren't
wired in before in front end).

* remove route listing across apps (unused)
* fix panic when doing `/app//`. this is prob possible for other types of
endpoints, out of scope here. added a guard in front of all endpoints for this
* adds `from_time` and `to_time` query parameters to calls, so you can e.g.
list the last hour of tasks. these are not required and default to
oldest/newest.
* hooked back up the datastore tests to the sql db, only run with sqlite atm,
but these are useful, added a lot to them too.
* added a bunch of tests to the front end, so pretty sure this all works now.
* added to swagger, we'll need to re-gen. also wrote some words about
pagination workings, I'm not sure how best to link to these, feedback welcome.
* not sure how we want to manage indexes, but we may need to add some (looking
at created_at, mostly)
* `?route` changed to `?path` in routes listing, to keep consistency with
everything else
* don't 404 when searching for calls where the route doesn't exist, just
return an empty list (it's a query param ffs)

closes #141
2017-09-20 06:50:49 -07:00
CI
9ceda5ec72 functions: 0.3.111 release [skip ci] 2017-09-21 00:18:17 +00:00
Reed Allman
f7f4d659ea Merge pull request #347 from fnproject/fix-queries-for-mysql-pg
Split queries to make them work on Postgres and MySQL
2017-09-20 17:07:24 -07:00
Denis Makogon
f4699ea0ba Adding API tests that verifies recently changed code bevaviour 2017-09-21 02:25:36 +03:00
Denis Makogon
830c86efe7 Make app delete more stable
We still need to delete app and check how may rows affected in apps table.
 But we don't really care about other tables and rows affected there: routes, calls, logs

 We need to delete app out of loop to check for invalid numbers of rows affected:
 - zero rows means nothing happend

 Despite apps table, zero rows affected if valid case for routes, calls and logs
2017-09-21 02:04:27 +03:00
Denis Makogon
a09159308c Run queries inside one transaction 2017-09-21 01:21:41 +03:00
Denis Makogon
7a9591fd45 Split queries to make them work on Postgres and MySQL
Only SQLite supports multiple deletes in one transaction/statement,
 but other are not.
2017-09-21 00:55:39 +03:00
CI
950b62994a functions: 0.3.110 release [skip ci] 2017-09-20 19:49:55 +00:00
Travis Reeder
deb2ae8103 Merge branch 'master' into app-yaml 2017-09-20 11:49:33 -07:00
Travis Reeder
904f288ed6 Replace FN_ROUTE with FN_PATH 2017-09-20 11:35:18 -07:00
CI
6a5b5fbcd4 functions: 0.3.109 release [skip ci] 2017-09-19 22:40:27 +00:00
CI
e1248bca5e functions: 0.3.108 release [skip ci] 2017-09-19 17:53:34 +00:00
Nigel Deakin
ae69bb37e3 Update global stats charts to show bteakdown by function 2017-09-19 15:05:37 +01:00
CI
3c3f771207 functions: 0.3.107 release [skip ci] 2017-09-19 05:45:16 +00:00
Reed Allman
f335d34636 add server option to limit request size (#320)
we're going to want to do this in our service version of this thing, but
adding this here so that it's usable by everyone. just an option, can add it
to server configuration, but response is nicely formatted, etc.

closes #277
2017-09-18 22:34:19 -07:00
Travis Reeder
75e2051169 Example app structure. round 1. 2017-09-18 17:16:59 -07:00
CI
a935a7102d functions: 0.3.106 release [skip ci] 2017-09-18 22:39:49 +00:00
CI
893edfcd63 functions: 0.3.104 release [skip ci] 2017-09-15 17:36:21 +00:00
Reed Allman
58ead3f7b6 Merge pull request #327 from fnproject/loggyloo
add id to all call invocation logs
2017-09-15 10:26:03 -07:00
CI
1a8a878e9f functions: 0.3.103 release [skip ci] 2017-09-15 00:18:17 +00:00
CI
02571220c3 functions: 0.3.102 release [skip ci] 2017-09-14 18:18:21 +00:00
CI
67d0b9cb9f functions: 0.3.101 release [skip ci] 2017-09-14 18:07:38 +00:00
CI
4a4849b5e2 functions: 0.3.100 release [skip ci] 2017-09-14 17:19:19 +00:00
Reed Allman
53ff665d69 not ready for spans yet in hot land 2017-09-08 05:06:35 -07:00
CI
913342c4d5 functions: 0.3.105 release [skip ci] 2017-09-18 21:11:00 +00:00
Reed Allman
f0d720cf2f Merge pull request #318 from fnproject/fnlog-fiddler
make fn logger more reasonable
2017-09-18 13:59:31 -07:00
Reed Allman
0f50e4b7fc fix neg content length 2017-09-08 01:59:54 -07:00
Reed Allman
4ce9163d99 nuke some TODO yey 2017-09-07 20:15:39 -07:00
Reed Allman
1811b4e230 make fn logger more reasonable
something still feels off with this, but i tinkered with it for a day-ish and
didn't come up with anything a whole lot better. doing a lot of the
maneuvering in the caller seemed better but it was just bloating up GetCall so
went back to having it basically like it was, but returning the limited
underlying buffer to read from so we can ship to the db.

some small changes to the LogStore interface, swapped it to take an
io.Reader instead of a string for more flexibility in the future while
essentially maintaining the same level of performance that we have now.
i'm guessing in the not so distant future we'll ship these to some s3 like
service and it would be better to stream them in than carry around a giant
string anyway. also, carrying around up to 1MB buffers in memory isn't great,
we may want to switch to file backed logs for calls, too. using io.Reader for
logs should make #279 more reasonable if/once we move to some s3-like thing,
we can stream from the log storage service direct to clients.

this fixes the span being out of whack and allows the 'right' context to be
used to upload logs (next to inserting the call). deletes the dbWriter we had,
and we just do this in call.End now (which makes sense to me at least).
removes the dupe code for making an stderr for hot / cold and simplifies the
way to get a func logger (no more 7 param methods yay).

closes #298
2017-09-07 20:15:39 -07:00
Reed Allman
1d0a63ca99 add id to all call invocation logs 2017-09-07 18:37:22 -07:00
Reed Allman
700078ccb9 bubble up some docker errors to user
currently:

* container ran out of memory (code 137)
* container exited with other code != 0
* unable to pull image (auth/404)

there may be others but this is a good start (the most common). notably, for
both hot and cold these should bubble up (if deterministic, which hub isn't
always), and these are useful for users to use in debugging why things aren't
working.

added tests to make sure that these behaviors are working.

also changed the behavior such that when the container exits we return a 502
instead of a 503, just to be able to distinguish the fact that fn is working
as expected but the container is acting funky (400 is weird here, so idk).

removed references to old IsUserVisible crap and slightly changed the
interface for RunResult for plumbing reasons (to get the error type,
specifically).

fixed an issue where if ~/.docker/config.json exists sometimes pulling images
wouldn't work deterministically (should be more inline w/ expectations now)

closes #275
2017-09-07 11:55:50 -07:00
CI
d395c4edda functions: 0.3.99 release [skip ci] 2017-09-13 18:28:45 +00:00
Denis Makogon
5683d01603 Fix error handling 2017-09-13 21:03:53 +03:00
CI
95aa5aa190 functions: 0.3.98 release [skip ci] 2017-09-13 17:24:11 +00:00
Reed Allman
cb11749a67 Merge pull request #321 from fnproject/uncap-slice
oops, try to pre-allocate slice of useful size but if not allow expan…
2017-09-13 10:12:30 -07:00
Reed Allman
3707935f56 Merge pull request #314 from fnproject/302
Implementing force delete for apps
2017-09-13 10:01:59 -07:00
Denis Makogon
b2ca5ebc64 Run all statements in one transaction 2017-09-12 23:39:18 +03:00
Denis Makogon
93d4a5730b Running deletes in single transaction 2017-09-12 23:30:31 +03:00
Denis Makogon
0b47c8c40c Fix sql statements 2017-09-12 20:42:52 +03:00
Denis Makogon
bdb7e7fd7b Addressing more comments 2017-09-12 20:09:22 +03:00
Denis Makogon
4052a7d428 Addressing review comments 2017-09-12 20:07:40 +03:00
Denis Makogon
8c9e7443cb Removing no longer valid tests 2017-09-11 23:38:19 +03:00
Denis Makogon
6b7accd3c6 Simplifying app delete per review comments 2017-09-11 23:15:01 +03:00
Reed Allman
f032ce0556 info line this (#316) 2017-09-11 13:05:49 -07:00
CI
6aeca53b5a functions: 0.3.97 release [skip ci] 2017-09-11 18:43:29 +00:00
Reed Allman
c71c170ac8 Merge pull request #299 from fnproject/fn-the-things
FN_ prefix env vars
2017-09-11 11:33:43 -07:00
Chad Arimura
d0901c104f Update ping.go
updating ping
2017-09-11 11:16:17 -07:00
Denis Makogon
78f2d51bfa Implementing force delete for apps
Deployment-Impact: DB schema changed

API Impact: HTTP DELETE /apps/{app} accepts query parameters: /apps/{app}?force=True

Closes: #302
2017-09-11 17:32:35 +03:00
Denis Makogon
3e190342fb Implementing batch deletes for calls, logs and routes
Partially-Closes: #302
2017-09-11 11:41:27 +03:00
Denis Makogon
774d53662f Making logs app-bound
Partially-Closes: #302
2017-09-11 11:04:54 +03:00