Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

0 downloads

dbbasic-object-server/tests/test_analytics_bounds.py
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 signup: the person chooses the password and name on the confirm page 83c7aa6 2 weeks, 5 days ago History
test_analytics_bounds.py · 2.8 KB · 63 lines
1"""Analytics that measures visitors, and a log that stays bounded.
2
3Both of these were found the same way: a 961MB demo box went to 675MB
4resident and started swapping, and the "Top paths (visitors)" report
5turned out to be 45% one-hit rows made of vulnerability scanners and the
6operator's own deploy calls. Neither failure was a bug in the code that
7was written -- both were things nobody had told the system.
8"""
9
10import object_analytics
11
12
13# --- whose traffic is this ---------------------------------------------------
14
15def test_the_operators_own_automation_is_not_a_visitor():
16 """A deploy call and a package install are the observer, not the
17 observed; counting them made the top-paths report describe us."""
18 record = object_analytics.build_page_view(
19 path="/packages/app-shop/install", method="POST", status=200,
20 ip="203.0.113.9", headers={}, owners=frozenset(), is_operator=True)
21 assert record["is_owner"] == "true"
22
23
24def test_an_owner_ip_still_counts_as_the_owner():
25 record = object_analytics.build_page_view(
26 path="/shop", method="GET", status=200,
27 ip="203.0.113.9", headers={}, owners=frozenset({"203.0.113.9"}))
28 assert record["is_owner"] == "true"
29
30
31def test_an_ordinary_visitor_is_a_visitor():
32 record = object_analytics.build_page_view(
33 path="/shop", method="GET", status=200,
34 ip="198.51.100.4", headers={}, owners=frozenset())
35 assert record["is_owner"] == "false"
36
37
38def test_a_signed_in_member_is_still_real_traffic():
39 """The line is between somebody USING the site and somebody OPERATING
40 it. Which pages members actually use is among the most useful things
41 this collection knows, so a member is never flagged away."""
42 record = object_analytics.build_page_view(
43 path="/invoices", method="GET", status=200, ip="198.51.100.4",
44 headers={"cookie": "dbbasic_session=abc"}, owners=frozenset(),
45 user_id="dana")
46 assert record["is_owner"] == "false"
47 assert record["user_id"] == "dana"
48
49
50# --- how much of it we keep ----------------------------------------------------
51
52def test_the_row_cap_reads_from_the_environment():
53 assert object_analytics.max_rows({"DBBASIC_ANALYTICS_MAX_ROWS": "5000"}) == 5000
54 assert object_analytics.max_rows({}) == object_analytics.DEFAULT_MAX_ROWS
55 # 0 is a real answer meaning "no cap", not a missing setting.
56 assert object_analytics.max_rows({"DBBASIC_ANALYTICS_MAX_ROWS": "0"}) == 0
57 assert object_analytics.max_rows(
58 {"DBBASIC_ANALYTICS_MAX_ROWS": "not a number"}) == object_analytics.DEFAULT_MAX_ROWS
59
60
61def test_retention_days_still_defaults_sanely():
62 assert object_analytics.retention_days({"DBBASIC_ANALYTICS_RETENTION_DAYS": "7"}) == 7
63 assert object_analytics.retention_days({}) == object_analytics.DEFAULT_RETENTION_DAYS