ws-availability 1.0.4__tar.gz → 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ws_availability-1.1.0/Dockerfile.api +18 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/Dockerfile.cacher +16 -14
- ws_availability-1.1.0/PKG-INFO +206 -0
- ws_availability-1.1.0/README.md +187 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/apps/data_access_layer.py +5 -2
- {ws_availability-1.0.4 → ws_availability-1.1.0}/apps/globals.py +6 -4
- {ws_availability-1.0.4 → ws_availability-1.1.0}/apps/restriction.py +162 -161
- {ws_availability-1.0.4 → ws_availability-1.1.0}/apps/root.py +3 -2
- ws_availability-1.1.0/apps/scheduler.py +140 -0
- ws_availability-1.1.0/apps/sentry.py +95 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/apps/settings.py +41 -17
- ws_availability-1.1.0/apps/updater.py +143 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/apps/wfcatalog_client.py +182 -43
- {ws_availability-1.0.4 → ws_availability-1.1.0}/docker-compose.yml +64 -64
- {ws_availability-1.0.4 → ws_availability-1.1.0}/pyproject.toml +10 -8
- {ws_availability-1.0.4 → ws_availability-1.1.0}/tests/test_data_access.py +4 -2
- ws_availability-1.1.0/tests/test_docker_compose.py +126 -0
- ws_availability-1.1.0/tests/test_gunicorn_conf.py +113 -0
- ws_availability-1.1.0/tests/test_issue60_protection.py +96 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/tests/test_restriction.py +9 -3
- ws_availability-1.1.0/tests/test_settings.py +145 -0
- ws_availability-1.1.0/tests/test_updater.py +127 -0
- ws_availability-1.1.0/tests/test_wfcatalog_query.py +280 -0
- ws_availability-1.1.0/ws_availability.egg-info/PKG-INFO +206 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/ws_availability.egg-info/SOURCES.txt +7 -0
- ws_availability-1.1.0/ws_availability.egg-info/requires.txt +10 -0
- ws_availability-1.0.4/Dockerfile.api +0 -16
- ws_availability-1.0.4/PKG-INFO +0 -438
- ws_availability-1.0.4/README.md +0 -420
- ws_availability-1.0.4/tests/test_settings.py +0 -42
- ws_availability-1.0.4/tests/test_wfcatalog_query.py +0 -134
- ws_availability-1.0.4/ws_availability.egg-info/PKG-INFO +0 -438
- ws_availability-1.0.4/ws_availability.egg-info/requires.txt +0 -9
- {ws_availability-1.0.4 → ws_availability-1.1.0}/LICENSE +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/MANIFEST.in +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/apps/__init__.py +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/apps/models.py +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/apps/parameters.py +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/apps/redis_client.py +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/apps/utils.py +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/setup.cfg +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/templates/doc.html +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/templates/wadl.xml +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/tests/test.py +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/tests/test_merge_parameter.py +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/tests/test_orderby.py +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/tests/test_query_no_endtime.py +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/tests/test_wfcatalog_filtering.py +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/views/main.js +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/ws_availability.egg-info/dependency_links.txt +0 -0
- {ws_availability-1.0.4 → ws_availability-1.1.0}/ws_availability.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
FROM python:3.13-slim
|
|
2
|
+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
|
|
3
|
+
|
|
4
|
+
WORKDIR /appli
|
|
5
|
+
COPY pyproject.toml uv.lock ./
|
|
6
|
+
RUN uv sync --frozen --no-dev --no-progress
|
|
7
|
+
|
|
8
|
+
COPY start.py config.py* gunicorn.conf.py ./
|
|
9
|
+
COPY apps ./apps/
|
|
10
|
+
COPY templates ./templates/
|
|
11
|
+
COPY tests ./tests/
|
|
12
|
+
|
|
13
|
+
# Place executables in the environment at the front of the path
|
|
14
|
+
ENV PATH="/appli/.venv/bin:$PATH"
|
|
15
|
+
|
|
16
|
+
# Default CMD when running the image without docker-compose. Worker count
|
|
17
|
+
# comes from gunicorn.conf.py → Config.GUNICORN_WORKERS (defaults to 1).
|
|
18
|
+
CMD ["/bin/bash", "-c", "gunicorn -c gunicorn.conf.py --timeout 600 --bind 0.0.0.0:9001 start:app"]
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
FROM python:3.
|
|
2
|
-
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
|
|
3
|
-
|
|
4
|
-
WORKDIR /appli
|
|
5
|
-
COPY pyproject.toml uv.lock ./
|
|
6
|
-
RUN uv sync --frozen --no-dev --no-progress
|
|
7
|
-
|
|
8
|
-
COPY cache.py config.py ./
|
|
9
|
-
COPY apps ./apps/
|
|
10
|
-
|
|
11
|
-
# Place executables in the environment at the front of the path
|
|
12
|
-
ENV PATH="/appli/.venv/bin:$PATH"
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
FROM python:3.13-slim
|
|
2
|
+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
|
|
3
|
+
|
|
4
|
+
WORKDIR /appli
|
|
5
|
+
COPY pyproject.toml uv.lock ./
|
|
6
|
+
RUN uv sync --frozen --no-dev --no-progress
|
|
7
|
+
|
|
8
|
+
COPY cache.py config.py* ./
|
|
9
|
+
COPY apps ./apps/
|
|
10
|
+
|
|
11
|
+
# Place executables in the environment at the front of the path
|
|
12
|
+
ENV PATH="/appli/.venv/bin:$PATH"
|
|
13
|
+
# Set PYTHONPATH so 'from apps.sentry import ...' resolves correctly
|
|
14
|
+
ENV PYTHONPATH="/appli"
|
|
15
|
+
|
|
16
|
+
CMD ["python", "apps/scheduler.py"]
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ws-availability
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Requires-Python: >=3.13
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: flask>=3.0
|
|
9
|
+
Requires-Dist: gunicorn>=23.0
|
|
10
|
+
Requires-Dist: obspy>=1.4.1
|
|
11
|
+
Requires-Dist: pymongo>=4.6
|
|
12
|
+
Requires-Dist: redis>=5.0
|
|
13
|
+
Requires-Dist: requests>=2.32
|
|
14
|
+
Requires-Dist: pydantic>=2.0.0
|
|
15
|
+
Requires-Dist: pydantic-settings>=2.12.0
|
|
16
|
+
Requires-Dist: sentry-sdk[flask]>=2.0.0
|
|
17
|
+
Requires-Dist: apscheduler>=3.11.2
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# FDSNWS-Availability
|
|
21
|
+
|
|
22
|
+
A Flask implementation of the [FDSN Availability web service 1.0](http://www.fdsn.org/webservices/fdsnws-availability-1.0.pdf). It reports the time spans for which time-series data exist, served from a WFCatalog MongoDB.
|
|
23
|
+
|
|
24
|
+
It runs as three Docker containers: the **API** (Flask + gunicorn, port 9001), a **Redis** cache, and a **cacher** that keeps the restriction inventory and the `availability` view up to date on a built-in daily schedule.
|
|
25
|
+
|
|
26
|
+
> **Upgrading from v1.0.x?** Follow [`BETA.md`](BETA.md) for the exact upgrade steps (config.py changes, the in-app scheduler replacing host cron).
|
|
27
|
+
|
|
28
|
+
## Deployment
|
|
29
|
+
|
|
30
|
+
First, get and configure the repo (needed either way):
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
git clone https://github.com/EIDA/ws-availability.git
|
|
34
|
+
cd ws-availability
|
|
35
|
+
cp config.py.sample config.py # edit MongoDB creds, FDSNWS_STATION_URL, SENTRY_ENVIRONMENT
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Then pick one of:
|
|
39
|
+
|
|
40
|
+
### Option A — Build locally
|
|
41
|
+
|
|
42
|
+
Builds the images on your host. No registry access needed.
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
docker-compose up -d --build
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Option B — Pull pre-built images
|
|
49
|
+
|
|
50
|
+
Each **tagged release** publishes images to GHCR, so you can skip the build. Replace `<version>` with a release tag (e.g. `1.1.0`, or `1.1` for the latest 1.1.x):
|
|
51
|
+
|
|
52
|
+
```yaml
|
|
53
|
+
# docker-compose.override.yml
|
|
54
|
+
services:
|
|
55
|
+
api:
|
|
56
|
+
image: ghcr.io/eida/ws-availability/api:<version>
|
|
57
|
+
cacher:
|
|
58
|
+
image: ghcr.io/eida/ws-availability/cacher:<version>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
docker-compose pull
|
|
63
|
+
docker-compose up -d
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
> Pre-built images exist only for tagged releases. To build from an untagged branch instead, use Option A (build locally).
|
|
67
|
+
|
|
68
|
+
Either way, three containers come up. Check it:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
curl "127.0.0.1:9001/version" # -> 1.1.0
|
|
72
|
+
curl "127.0.0.1:9001/extent?net=NA&start=2023-02-01"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
For a node that already has a populated WFCatalog, that's the whole install. A brand-new database also needs the one-time [database setup](#first-time-database-setup). Requires MongoDB ≥ 4.2.
|
|
76
|
+
|
|
77
|
+
## Endpoints
|
|
78
|
+
|
|
79
|
+
API on port `9001`. `/query` (time spans per channel) and `/extent` (one row per channel) accept GET and POST. Also `/version`, `/application.wadl`, and `/` (landing page).
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
curl "127.0.0.1:9001/extent?net=NA&start=2023-02-01"
|
|
83
|
+
#Network Station Location Channel Quality SampleRate Earliest Latest Updated TimeSpans Restriction
|
|
84
|
+
NA SABA BHZ D 40.0 2023-02-01T00:00:00.000000Z 2023-02-14T00:00:00.000000Z 2023-02-14T07:41:41Z 1 OPEN
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Configuration
|
|
88
|
+
|
|
89
|
+
Everything lives in `config.py` (copied from `config.py.sample`, gitignored so upgrades never touch it). Set these in the `RUNMODE == "production"` block:
|
|
90
|
+
|
|
91
|
+
| Key | Default | Description |
|
|
92
|
+
|-----|---------|-------------|
|
|
93
|
+
| `MONGODB_HOST` | `host.docker.internal` | WFCatalog MongoDB host. |
|
|
94
|
+
| `MONGODB_PORT` | `27017` | MongoDB port. |
|
|
95
|
+
| `MONGODB_USR` / `MONGODB_PWD` | empty | MongoDB credentials (leave empty if no auth). |
|
|
96
|
+
| `MONGODB_NAME` | `wfrepo` | Database name; also used as `authSource` unless `MONGODB_AUTH_SOURCE` is set. |
|
|
97
|
+
| `MONGODB_AUTH_SOURCE` | `None` | Optional. Mongo auth database when it differs from `MONGODB_NAME` (e.g. `admin`). Falls back to `MONGODB_NAME` when unset. |
|
|
98
|
+
| `FDSNWS_STATION_URL` | `https://orfeus-eu.org/fdsnws/station/1/query` | FDSNWS-Station endpoint to harvest restriction info from. |
|
|
99
|
+
| `CACHE_HOST` | `cache` | Redis host. |
|
|
100
|
+
| `CACHE_PORT` | `6379` | Redis port. |
|
|
101
|
+
| `CACHE_INVENTORY_KEY` | `inventory` | Redis key for the restriction inventory. |
|
|
102
|
+
| `CACHE_INVENTORY_PERIOD` | `0` | Inventory cache TTL in seconds; `0` = never expire. |
|
|
103
|
+
| `CACHE_RESP_PERIOD` | `1200` | Response cache TTL in seconds. |
|
|
104
|
+
| `SENTRY_DSN` | empty | Sentry DSN; empty disables Sentry. |
|
|
105
|
+
| `SENTRY_TRACES_SAMPLE_RATE` | `1.0` | Fraction of requests traced, `0.0`–`1.0`. |
|
|
106
|
+
| `SENTRY_ENVIRONMENT` | `{{node}}_production` | **Unique per-node tag** (e.g. `noa_production`) so Sentry can tell deployments apart. Must be changed from the placeholder. |
|
|
107
|
+
| `GUNICORN_WORKERS` | `1` | Number of gunicorn worker processes. Raise (2–3, or `(2 × CPU cores) + 1`) if you have CPU/RAM headroom. Read by `gunicorn.conf.py` at container start. |
|
|
108
|
+
|
|
109
|
+
## What runs daily
|
|
110
|
+
|
|
111
|
+
The cacher runs a built-in scheduler — no host cron needed:
|
|
112
|
+
|
|
113
|
+
- **03:00 UTC** — refresh the restriction inventory from FDSNWS-Station into Redis.
|
|
114
|
+
- **06:00 UTC** — update the `availability` view from the last 4 days of WFCatalog data.
|
|
115
|
+
- **On startup** — both run once, so a restart leaves data fresh.
|
|
116
|
+
|
|
117
|
+
## Tuning (optional)
|
|
118
|
+
|
|
119
|
+
- **Workers** — set `GUNICORN_WORKERS` in `config.py` (default `1`). `gunicorn.conf.py` reads it at startup. Raise if you have CPU/RAM headroom.
|
|
120
|
+
- **Row/stream caps** — `MAX_DATA_ROWS` (default 2.5M) and `MAX_STREAMS` (default 2000) env vars guard against oversized requests (HTTP 413).
|
|
121
|
+
|
|
122
|
+
### Parallel fan-out
|
|
123
|
+
|
|
124
|
+
By default, each request is answered by a **single** MongoDB cursor. The `availability` collection holds one document per channel-per-day, so a long time range means many documents fetched in sequential round-trips — most of the time is spent waiting on the database, one batch after another.
|
|
125
|
+
|
|
126
|
+
Fan-out splits the request's time range into day-aligned windows and runs them as **concurrent** cursors, then merges the pieces back together. The waiting overlaps instead of stacking up, so a multi-month query finishes noticeably faster. Because each window is a separate day range, the slices never overlap and the merged result is **byte-identical** to the single-cursor answer — only the speed differs.
|
|
127
|
+
|
|
128
|
+
It is **off by default**, applies to **both `/query` and `/extent`** (they share the same fetch layer), and only engages when a request's time range is at least `FANOUT_MIN_DAYS` — shorter requests stay single-cursor because the thread overhead wouldn't pay off. Controlled by these environment variables:
|
|
129
|
+
|
|
130
|
+
| Variable | Default | Effect |
|
|
131
|
+
|----------|---------|--------|
|
|
132
|
+
| `FANOUT_ENABLED` | `false` | Master switch. When `false`, behaves exactly like the single-cursor path. |
|
|
133
|
+
| `FANOUT_MIN_DAYS` | `7` | Minimum request range, in days, before fan-out engages. |
|
|
134
|
+
| `FANOUT_WINDOW_DAYS` | `30` | Size of each window. A 90-day query becomes ~3 windows. |
|
|
135
|
+
| `FANOUT_MAX_WORKERS` | `4` | Max windows run at once — also the number of MongoDB connections a fan-out request uses. |
|
|
136
|
+
|
|
137
|
+
Best for long, narrow queries (months/years of a few channels). Before enabling on a busy node, check that `workers × FANOUT_MAX_WORKERS` stays within your MongoDB connection budget.
|
|
138
|
+
|
|
139
|
+
## Development
|
|
140
|
+
|
|
141
|
+
Requires Python ≥ 3.13 and [uv](https://docs.astral.sh/uv/).
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
cp config.py.sample config.py # edit for RUNMODE=test
|
|
145
|
+
uv sync
|
|
146
|
+
docker run -p 6379:6379 -d redis:7.0-alpine # Redis is required
|
|
147
|
+
uv run python cache.py # build the restriction inventory
|
|
148
|
+
RUNMODE=test uv run gunicorn --bind 0.0.0.0:9001 start:app
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Tests: `uv run pytest tests/`
|
|
152
|
+
|
|
153
|
+
## First-time database setup
|
|
154
|
+
|
|
155
|
+
*Skip this if you already run ws-availability — the view and index already exist.*
|
|
156
|
+
|
|
157
|
+
For a brand-new WFCatalog database, build the materialized view once:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# Build the availability view (adjust daysBack to how far back you want)
|
|
161
|
+
mongosh -u USER -p PASSWORD --authenticationDatabase wfrepo --eval "daysBack=365" views/main.js
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The compound index `{ net: 1, sta: 1, loc: 1, cha: 1, ts: 1, te: 1 }` is created automatically by the API at startup (built in the background). If queries feel slow right after a brand-new install, give it a moment to finish.
|
|
165
|
+
|
|
166
|
+
After the initial build, the cacher keeps the view current automatically (see [What runs daily](#what-runs-daily)) — **no host cron is needed** (earlier versions required one; it has been replaced by the built-in scheduler).
|
|
167
|
+
|
|
168
|
+
### Back-processing
|
|
169
|
+
|
|
170
|
+
The daily scheduler only refreshes a rolling recent window. To reprocess a specific historical range or a subset of streams — e.g. after a data correction or a backfill — run `views/main.js` manually with parameters (`networks`/`stations` accept regex):
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
# A specific month
|
|
174
|
+
mongosh -u USER -p PASSWORD --authenticationDatabase wfrepo \
|
|
175
|
+
--eval "start='2023-01-01'; end='2023-01-31'" views/main.js
|
|
176
|
+
|
|
177
|
+
# One network/station over a range
|
|
178
|
+
mongosh -u USER -p PASSWORD --authenticationDatabase wfrepo \
|
|
179
|
+
--eval "networks='NL'; stations='HGN'; start='2022-12-01'; end='2023-01-31'" views/main.js
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Troubleshooting
|
|
183
|
+
|
|
184
|
+
If the service isn't working — often right after an upgrade — it's usually a configuration problem:
|
|
185
|
+
|
|
186
|
+
1. **Check the logs** for runtime errors or connection failures:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
docker logs fdsnws-availability-api
|
|
190
|
+
docker logs fdsnws-availability-cacher
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
2. **Verify `config.py` has every field** the current version expects. New versions add keys; list what yours is missing versus the sample:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
diff <(grep -oE '^[[:space:]]*[A-Z_]+ =' config.py | tr -d ' =' | sort -u) \
|
|
197
|
+
<(grep -oE '^[[:space:]]*[A-Z_]+ =' config.py.sample | tr -d ' =' | sort -u)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Lines prefixed `>` are keys present in the sample but missing from your `config.py` — add them.
|
|
201
|
+
|
|
202
|
+
3. **Check database access** — confirm the MongoDB and Redis connection parameters in `config.py` are correct and that both services are reachable from the containers.
|
|
203
|
+
|
|
204
|
+
## References
|
|
205
|
+
|
|
206
|
+
Forked from [gitlab.com/resif/ws-availability](https://gitlab.com/resif/ws-availability) — thanks to our colleagues at RESIF for sharing their FDSNWS-Availability implementation. 💐
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# FDSNWS-Availability
|
|
2
|
+
|
|
3
|
+
A Flask implementation of the [FDSN Availability web service 1.0](http://www.fdsn.org/webservices/fdsnws-availability-1.0.pdf). It reports the time spans for which time-series data exist, served from a WFCatalog MongoDB.
|
|
4
|
+
|
|
5
|
+
It runs as three Docker containers: the **API** (Flask + gunicorn, port 9001), a **Redis** cache, and a **cacher** that keeps the restriction inventory and the `availability` view up to date on a built-in daily schedule.
|
|
6
|
+
|
|
7
|
+
> **Upgrading from v1.0.x?** Follow [`BETA.md`](BETA.md) for the exact upgrade steps (config.py changes, the in-app scheduler replacing host cron).
|
|
8
|
+
|
|
9
|
+
## Deployment
|
|
10
|
+
|
|
11
|
+
First, get and configure the repo (needed either way):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
git clone https://github.com/EIDA/ws-availability.git
|
|
15
|
+
cd ws-availability
|
|
16
|
+
cp config.py.sample config.py # edit MongoDB creds, FDSNWS_STATION_URL, SENTRY_ENVIRONMENT
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Then pick one of:
|
|
20
|
+
|
|
21
|
+
### Option A — Build locally
|
|
22
|
+
|
|
23
|
+
Builds the images on your host. No registry access needed.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
docker-compose up -d --build
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Option B — Pull pre-built images
|
|
30
|
+
|
|
31
|
+
Each **tagged release** publishes images to GHCR, so you can skip the build. Replace `<version>` with a release tag (e.g. `1.1.0`, or `1.1` for the latest 1.1.x):
|
|
32
|
+
|
|
33
|
+
```yaml
|
|
34
|
+
# docker-compose.override.yml
|
|
35
|
+
services:
|
|
36
|
+
api:
|
|
37
|
+
image: ghcr.io/eida/ws-availability/api:<version>
|
|
38
|
+
cacher:
|
|
39
|
+
image: ghcr.io/eida/ws-availability/cacher:<version>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
docker-compose pull
|
|
44
|
+
docker-compose up -d
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
> Pre-built images exist only for tagged releases. To build from an untagged branch instead, use Option A (build locally).
|
|
48
|
+
|
|
49
|
+
Either way, three containers come up. Check it:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
curl "127.0.0.1:9001/version" # -> 1.1.0
|
|
53
|
+
curl "127.0.0.1:9001/extent?net=NA&start=2023-02-01"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
For a node that already has a populated WFCatalog, that's the whole install. A brand-new database also needs the one-time [database setup](#first-time-database-setup). Requires MongoDB ≥ 4.2.
|
|
57
|
+
|
|
58
|
+
## Endpoints
|
|
59
|
+
|
|
60
|
+
API on port `9001`. `/query` (time spans per channel) and `/extent` (one row per channel) accept GET and POST. Also `/version`, `/application.wadl`, and `/` (landing page).
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
curl "127.0.0.1:9001/extent?net=NA&start=2023-02-01"
|
|
64
|
+
#Network Station Location Channel Quality SampleRate Earliest Latest Updated TimeSpans Restriction
|
|
65
|
+
NA SABA BHZ D 40.0 2023-02-01T00:00:00.000000Z 2023-02-14T00:00:00.000000Z 2023-02-14T07:41:41Z 1 OPEN
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Configuration
|
|
69
|
+
|
|
70
|
+
Everything lives in `config.py` (copied from `config.py.sample`, gitignored so upgrades never touch it). Set these in the `RUNMODE == "production"` block:
|
|
71
|
+
|
|
72
|
+
| Key | Default | Description |
|
|
73
|
+
|-----|---------|-------------|
|
|
74
|
+
| `MONGODB_HOST` | `host.docker.internal` | WFCatalog MongoDB host. |
|
|
75
|
+
| `MONGODB_PORT` | `27017` | MongoDB port. |
|
|
76
|
+
| `MONGODB_USR` / `MONGODB_PWD` | empty | MongoDB credentials (leave empty if no auth). |
|
|
77
|
+
| `MONGODB_NAME` | `wfrepo` | Database name; also used as `authSource` unless `MONGODB_AUTH_SOURCE` is set. |
|
|
78
|
+
| `MONGODB_AUTH_SOURCE` | `None` | Optional. Mongo auth database when it differs from `MONGODB_NAME` (e.g. `admin`). Falls back to `MONGODB_NAME` when unset. |
|
|
79
|
+
| `FDSNWS_STATION_URL` | `https://orfeus-eu.org/fdsnws/station/1/query` | FDSNWS-Station endpoint to harvest restriction info from. |
|
|
80
|
+
| `CACHE_HOST` | `cache` | Redis host. |
|
|
81
|
+
| `CACHE_PORT` | `6379` | Redis port. |
|
|
82
|
+
| `CACHE_INVENTORY_KEY` | `inventory` | Redis key for the restriction inventory. |
|
|
83
|
+
| `CACHE_INVENTORY_PERIOD` | `0` | Inventory cache TTL in seconds; `0` = never expire. |
|
|
84
|
+
| `CACHE_RESP_PERIOD` | `1200` | Response cache TTL in seconds. |
|
|
85
|
+
| `SENTRY_DSN` | empty | Sentry DSN; empty disables Sentry. |
|
|
86
|
+
| `SENTRY_TRACES_SAMPLE_RATE` | `1.0` | Fraction of requests traced, `0.0`–`1.0`. |
|
|
87
|
+
| `SENTRY_ENVIRONMENT` | `{{node}}_production` | **Unique per-node tag** (e.g. `noa_production`) so Sentry can tell deployments apart. Must be changed from the placeholder. |
|
|
88
|
+
| `GUNICORN_WORKERS` | `1` | Number of gunicorn worker processes. Raise (2–3, or `(2 × CPU cores) + 1`) if you have CPU/RAM headroom. Read by `gunicorn.conf.py` at container start. |
|
|
89
|
+
|
|
90
|
+
## What runs daily
|
|
91
|
+
|
|
92
|
+
The cacher runs a built-in scheduler — no host cron needed:
|
|
93
|
+
|
|
94
|
+
- **03:00 UTC** — refresh the restriction inventory from FDSNWS-Station into Redis.
|
|
95
|
+
- **06:00 UTC** — update the `availability` view from the last 4 days of WFCatalog data.
|
|
96
|
+
- **On startup** — both run once, so a restart leaves data fresh.
|
|
97
|
+
|
|
98
|
+
## Tuning (optional)
|
|
99
|
+
|
|
100
|
+
- **Workers** — set `GUNICORN_WORKERS` in `config.py` (default `1`). `gunicorn.conf.py` reads it at startup. Raise if you have CPU/RAM headroom.
|
|
101
|
+
- **Row/stream caps** — `MAX_DATA_ROWS` (default 2.5M) and `MAX_STREAMS` (default 2000) env vars guard against oversized requests (HTTP 413).
|
|
102
|
+
|
|
103
|
+
### Parallel fan-out
|
|
104
|
+
|
|
105
|
+
By default, each request is answered by a **single** MongoDB cursor. The `availability` collection holds one document per channel-per-day, so a long time range means many documents fetched in sequential round-trips — most of the time is spent waiting on the database, one batch after another.
|
|
106
|
+
|
|
107
|
+
Fan-out splits the request's time range into day-aligned windows and runs them as **concurrent** cursors, then merges the pieces back together. The waiting overlaps instead of stacking up, so a multi-month query finishes noticeably faster. Because each window is a separate day range, the slices never overlap and the merged result is **byte-identical** to the single-cursor answer — only the speed differs.
|
|
108
|
+
|
|
109
|
+
It is **off by default**, applies to **both `/query` and `/extent`** (they share the same fetch layer), and only engages when a request's time range is at least `FANOUT_MIN_DAYS` — shorter requests stay single-cursor because the thread overhead wouldn't pay off. Controlled by these environment variables:
|
|
110
|
+
|
|
111
|
+
| Variable | Default | Effect |
|
|
112
|
+
|----------|---------|--------|
|
|
113
|
+
| `FANOUT_ENABLED` | `false` | Master switch. When `false`, behaves exactly like the single-cursor path. |
|
|
114
|
+
| `FANOUT_MIN_DAYS` | `7` | Minimum request range, in days, before fan-out engages. |
|
|
115
|
+
| `FANOUT_WINDOW_DAYS` | `30` | Size of each window. A 90-day query becomes ~3 windows. |
|
|
116
|
+
| `FANOUT_MAX_WORKERS` | `4` | Max windows run at once — also the number of MongoDB connections a fan-out request uses. |
|
|
117
|
+
|
|
118
|
+
Best for long, narrow queries (months/years of a few channels). Before enabling on a busy node, check that `workers × FANOUT_MAX_WORKERS` stays within your MongoDB connection budget.
|
|
119
|
+
|
|
120
|
+
## Development
|
|
121
|
+
|
|
122
|
+
Requires Python ≥ 3.13 and [uv](https://docs.astral.sh/uv/).
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
cp config.py.sample config.py # edit for RUNMODE=test
|
|
126
|
+
uv sync
|
|
127
|
+
docker run -p 6379:6379 -d redis:7.0-alpine # Redis is required
|
|
128
|
+
uv run python cache.py # build the restriction inventory
|
|
129
|
+
RUNMODE=test uv run gunicorn --bind 0.0.0.0:9001 start:app
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Tests: `uv run pytest tests/`
|
|
133
|
+
|
|
134
|
+
## First-time database setup
|
|
135
|
+
|
|
136
|
+
*Skip this if you already run ws-availability — the view and index already exist.*
|
|
137
|
+
|
|
138
|
+
For a brand-new WFCatalog database, build the materialized view once:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
# Build the availability view (adjust daysBack to how far back you want)
|
|
142
|
+
mongosh -u USER -p PASSWORD --authenticationDatabase wfrepo --eval "daysBack=365" views/main.js
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
The compound index `{ net: 1, sta: 1, loc: 1, cha: 1, ts: 1, te: 1 }` is created automatically by the API at startup (built in the background). If queries feel slow right after a brand-new install, give it a moment to finish.
|
|
146
|
+
|
|
147
|
+
After the initial build, the cacher keeps the view current automatically (see [What runs daily](#what-runs-daily)) — **no host cron is needed** (earlier versions required one; it has been replaced by the built-in scheduler).
|
|
148
|
+
|
|
149
|
+
### Back-processing
|
|
150
|
+
|
|
151
|
+
The daily scheduler only refreshes a rolling recent window. To reprocess a specific historical range or a subset of streams — e.g. after a data correction or a backfill — run `views/main.js` manually with parameters (`networks`/`stations` accept regex):
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# A specific month
|
|
155
|
+
mongosh -u USER -p PASSWORD --authenticationDatabase wfrepo \
|
|
156
|
+
--eval "start='2023-01-01'; end='2023-01-31'" views/main.js
|
|
157
|
+
|
|
158
|
+
# One network/station over a range
|
|
159
|
+
mongosh -u USER -p PASSWORD --authenticationDatabase wfrepo \
|
|
160
|
+
--eval "networks='NL'; stations='HGN'; start='2022-12-01'; end='2023-01-31'" views/main.js
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Troubleshooting
|
|
164
|
+
|
|
165
|
+
If the service isn't working — often right after an upgrade — it's usually a configuration problem:
|
|
166
|
+
|
|
167
|
+
1. **Check the logs** for runtime errors or connection failures:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
docker logs fdsnws-availability-api
|
|
171
|
+
docker logs fdsnws-availability-cacher
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
2. **Verify `config.py` has every field** the current version expects. New versions add keys; list what yours is missing versus the sample:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
diff <(grep -oE '^[[:space:]]*[A-Z_]+ =' config.py | tr -d ' =' | sort -u) \
|
|
178
|
+
<(grep -oE '^[[:space:]]*[A-Z_]+ =' config.py.sample | tr -d ' =' | sort -u)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Lines prefixed `>` are keys present in the sample but missing from your `config.py` — add them.
|
|
182
|
+
|
|
183
|
+
3. **Check database access** — confirm the MongoDB and Redis connection parameters in `config.py` are correct and that both services are reachable from the containers.
|
|
184
|
+
|
|
185
|
+
## References
|
|
186
|
+
|
|
187
|
+
Forked from [gitlab.com/resif/ws-availability](https://gitlab.com/resif/ws-availability) — thanks to our colleagues at RESIF for sharing their FDSNWS-Availability implementation. 💐
|
|
@@ -9,9 +9,9 @@ from typing import Any
|
|
|
9
9
|
from flask import make_response
|
|
10
10
|
|
|
11
11
|
from apps.globals import Error
|
|
12
|
-
from apps.globals import MAX_DATA_ROWS
|
|
13
12
|
from apps.globals import SCHEMAVERSION
|
|
14
13
|
from apps.globals import QUALITY, SAMPLERATE, START, END, UPDATED, STATUS, COUNT
|
|
14
|
+
from apps.settings import settings
|
|
15
15
|
from apps.utils import error_request
|
|
16
16
|
from apps.utils import overflow_error
|
|
17
17
|
from apps.utils import tictac
|
|
@@ -419,7 +419,7 @@ def get_output(param_dic_list: list[dict]) -> Any:
|
|
|
419
419
|
|
|
420
420
|
nrows = len(data)
|
|
421
421
|
logging.info(f"Number of collected rows: {nrows}")
|
|
422
|
-
if nrows >
|
|
422
|
+
if nrows > settings.max_data_rows:
|
|
423
423
|
return overflow_error(Error.TOO_MUCH_ROWS)
|
|
424
424
|
|
|
425
425
|
indexes = get_indexes(params)
|
|
@@ -435,6 +435,9 @@ def get_output(param_dic_list: list[dict]) -> Any:
|
|
|
435
435
|
response = get_response(params, data)
|
|
436
436
|
logging.debug(f"Processing in {tictac(tic)} seconds.")
|
|
437
437
|
return response
|
|
438
|
+
except ValueError as ex:
|
|
439
|
+
# Catch breadth/complexity errors from Redis guardrails and return 413
|
|
440
|
+
return overflow_error(str(ex))
|
|
438
441
|
except Exception as ex:
|
|
439
442
|
logging.exception(str(ex))
|
|
440
443
|
finally:
|
|
@@ -13,11 +13,11 @@ UPDATED = 8
|
|
|
13
13
|
STATUS = 9
|
|
14
14
|
COUNT = 10 # timespancount
|
|
15
15
|
|
|
16
|
+
from apps.settings import settings
|
|
17
|
+
|
|
16
18
|
# limitations
|
|
17
19
|
TIMEOUT = 600
|
|
18
20
|
MAX_DAYS = None
|
|
19
|
-
MAX_ROWS = "2_500_000"
|
|
20
|
-
MAX_DATA_ROWS = int(MAX_ROWS.replace(",", ""))
|
|
21
21
|
MAX_MERGEGAPS = 10000000000
|
|
22
22
|
|
|
23
23
|
# available parameter values
|
|
@@ -38,7 +38,7 @@ ORDERBY = (
|
|
|
38
38
|
# error message constants
|
|
39
39
|
DOCUMENTATION_URI = "http://www.fdsn.org/webservices/fdsnws-availability-1.0.pdf"
|
|
40
40
|
SERVICE = "fdsnws-availability"
|
|
41
|
-
VERSION = "1.0
|
|
41
|
+
VERSION = "1.1.0"
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
class Error:
|
|
@@ -47,7 +47,9 @@ class Error:
|
|
|
47
47
|
VALID_PARAM = "Valid parameters."
|
|
48
48
|
START_LATER = "The starttime cannot be later than the endtime: "
|
|
49
49
|
TOO_LONG_DURATION = "Too many days requested (greater than "
|
|
50
|
-
TOO_MUCH_ROWS = f"The request exceeds the limit of {
|
|
50
|
+
TOO_MUCH_ROWS = f"The request exceeds the limit of {settings.max_data_rows} rows."
|
|
51
|
+
TOO_MANY_STREAMS = f"The request matches too many streams (limit is {settings.max_streams}). Please be more specific."
|
|
52
|
+
BROAD_QUERY = "Request too broad: please provide starttime/endtime, or specify at least a station or channel."
|
|
51
53
|
UNSPECIFIED = "Error processing your request."
|
|
52
54
|
NODATA = "Your query doesn't match any available data."
|
|
53
55
|
TIMEOUT = f"Your query exceeds timeout ({TIMEOUT} seconds)."
|