Skip to content

Commit de287c1

Browse files
Merge pull request #22 from developmentseed/removeList
remove LIST and some requirements
2 parents 5eb3ef6 + b538ccf commit de287c1

File tree

11 files changed

+48
-103
lines changed

11 files changed

+48
-103
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
* update requirements
55
- `rio-tiler>=6.0,<7.0`
66
- `fastapi>=0.100.0`
7+
- `rasterio>=1.3.8`
8+
9+
* remove `wurlitzer` dependency
10+
11+
* only use `rasterio` logs
12+
13+
* remove `LIST` information **breaking change**
714

815
## 0.10.0 (2023-06-02)
916

README.md

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
---
3232

3333

34-
Inspect HEAD/LIST/GET requests withing Rasterio.
34+
Inspect HEAD/GET requests withing Rasterio.
3535

3636
Note: In GDAL 3.2, logging capabilities for /vsicurl, /vsis3 and the like was added (ref: https://github.com/OSGeo/gdal/pull/2742).
3737

@@ -66,7 +66,7 @@ def info(src_path: str):
6666

6767
meta = info("https://noaa-eri-pds.s3.amazonaws.com/2022_Hurricane_Ian/20221002a_RGB/20221002aC0795145w325100n.tif")
6868

69-
> 2022-10-25T00:20:24.215385+0200 | TILEBENCH | {"LIST": {"count": 0}, "HEAD": {"count": 1}, "GET": {"count": 1, "bytes": 32768, "ranges": ["0-32767"]}, "Timing": 0.8705799579620361}
69+
> 2023-10-18T23:00:11.184745+0200 | TILEBENCH | {"HEAD": {"count": 1}, "GET": {"count": 1, "bytes": 32768, "ranges": ["0-32767"]}, "Timing": 0.7379939556121826}
7070
```
7171

7272
```python
@@ -85,7 +85,7 @@ img = _read_tile(
8585
15,
8686
)
8787

88-
> 2022-10-25T00:21:32.895752+0200 | TILEBENCH | {"LIST": {"count": 0}, "HEAD": {"count": 1}, "GET": {"count": 2, "bytes": 409600, "ranges": ["0-32767", "32768-409599"]}, "Timing": 1.2970409393310547}
88+
> 2023-10-18T23:01:00.572263+0200 | TILEBENCH | {"HEAD": {"count": 1}, "GET": {"count": 2, "bytes": 409600, "ranges": ["0-32767", "32768-409599"]}, "Timing": 1.0749869346618652}
8989
```
9090

9191
## Command Line Interface (CLI)
@@ -119,9 +119,6 @@ $ tilebench random https://noaa-eri-pds.s3.amazonaws.com/2022_Hurricane_Ian/2022
119119
120120
$ tilebench profile https://noaa-eri-pds.s3.amazonaws.com/2022_Hurricane_Ian/20221002a_RGB/20221002aC0795145w325100n.tif --tile 15-9114-13215 --config GDAL_DISABLE_READDIR_ON_OPEN=EMPTY_DIR | jq
121121
{
122-
"LIST": {
123-
"count": 0
124-
},
125122
"HEAD": {
126123
"count": 1
127124
},
@@ -133,14 +130,11 @@ $ tilebench profile https://noaa-eri-pds.s3.amazonaws.com/2022_Hurricane_Ian/202
133130
"32768-409599"
134131
]
135132
},
136-
"Timing": 1.2364399433135986
133+
"Timing": 0.9715230464935303
137134
}
138135
139136
$ tilebench profile https://noaa-eri-pds.s3.amazonaws.com/2022_Hurricane_Ian/20221002a_RGB/20221002aC0795145w325100n.tif --tile 15-9114-13215 --config GDAL_DISABLE_READDIR_ON_OPEN=FALSE | jq
140137
{
141-
"LIST": {
142-
"count": 1
143-
},
144138
"HEAD": {
145139
"count": 8
146140
},
@@ -152,7 +146,7 @@ $ tilebench profile https://noaa-eri-pds.s3.amazonaws.com/2022_Hurricane_Ian/202
152146
"32768-409599"
153147
]
154148
},
155-
"Timing": 2.2018940448760986
149+
"Timing": 2.1837549209594727
156150
}
157151
```
158152

@@ -227,34 +221,7 @@ docker run \
227221

228222
## Contribution & Development
229223

230-
Issues and pull requests are more than welcome.
231-
232-
**dev install**
233-
234-
```bash
235-
$ git clone https://github.com/developmentseed/tilebench.git
236-
$ cd tilebench
237-
$ pip install -e .[dev]
238-
```
239-
240-
**pre-commit**
241-
242-
This repo is set to use `pre-commit` to run *isort*, *flake8*, *pydocstring*, *black* ("uncompromising Python code formatter") and mypy when committing new code.
243-
244-
```
245-
$ pre-commit install
246-
247-
$ git add .
248-
249-
$ git commit -m'my change'
250-
isort....................................................................Passed
251-
black....................................................................Passed
252-
Flake8...................................................................Passed
253-
Verifying PEP257 Compliance..............................................Passed
254-
mypy.....................................................................Passed
255-
256-
$ git push origin
257-
```
224+
See [CONTRIBUTING.md](https://github.com/developmentseed/tilebench/blob/main/CONTRIBUTING.md)
258225

259226
## License
260227

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ dependencies = [
2323
"fastapi>=0.100.0",
2424
"jinja2>=3.0,<4.0.0",
2525
"loguru",
26-
"rasterio>=1.3.0",
26+
"rasterio>=1.3.8",
2727
"rio-tiler>=6.0,<7.0",
28-
"wurlitzer",
2928
"uvicorn[standard]",
3029
]
3130

tests/test_cli.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_profile():
1818
assert not result.exception
1919
assert result.exit_code == 0
2020
log = json.loads(result.output)
21-
assert ["LIST", "HEAD", "GET", "Timing"] == list(log)
21+
assert ["HEAD", "GET", "Timing"] == list(log)
2222
# Make sure we didn't cache any request when `--tile` is not provided
2323
assert "0-" in log["GET"]["ranges"][0]
2424

@@ -38,15 +38,15 @@ def test_profile():
3838
assert not result.exception
3939
assert result.exit_code == 0
4040
log = json.loads(result.output)
41-
assert ["LIST", "HEAD", "GET", "Timing"] == list(log)
41+
assert ["HEAD", "GET", "Timing"] == list(log)
4242

4343
result = runner.invoke(
4444
cli, ["profile", COG_PATH, "--tilesize", 512, "--tile", "16-18229-26433"]
4545
)
4646
assert not result.exception
4747
assert result.exit_code == 0
4848
log = json.loads(result.output)
49-
assert ["LIST", "HEAD", "GET", "Timing"] == list(log)
49+
assert ["HEAD", "GET", "Timing"] == list(log)
5050

5151
result = runner.invoke(
5252
cli, ["profile", COG_PATH, "--add-kernels", "--add-stdout", "--add-cprofile"]
@@ -55,14 +55,12 @@ def test_profile():
5555
assert result.exit_code == 0
5656
log = json.loads(result.output)
5757
assert [
58-
"LIST",
5958
"HEAD",
6059
"GET",
6160
"WarpKernels",
6261
"Timing",
6362
"cprofile",
64-
"curl",
65-
"rasterio",
63+
"logs",
6664
] == list(log)
6765

6866

tests/test_middleware.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def skip():
4141
assert response.headers["Cache-Control"] == "no-cache"
4242
assert response.headers["VSI-Stats"]
4343
stats = response.headers["VSI-Stats"]
44-
assert "list;count=" in stats
4544
assert "head;count=" in stats
4645
assert "get;count=" in stats
4746

@@ -50,7 +49,6 @@ def skip():
5049
assert response.headers["content-type"] == "application/json"
5150
assert response.headers["VSI-Stats"]
5251
stats = response.headers["VSI-Stats"]
53-
assert "list;count=" in stats
5452
assert "head;count=" in stats
5553
assert "get;count=" in stats
5654

tests/test_reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _read_tile(src_path: str, x: int, y: int, z: int, tilesize: int = 256):
3737
assert data.shape
3838
assert mask.shape
3939
assert stats
40-
assert stats.get("LIST")
40+
assert stats.get("HEAD")
4141
assert stats.get("GET")
4242
assert stats.get("Timing")
4343
assert stats.get("WarpKernels")

tests/test_viz.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def test_viz():
2828
stats = response.headers["VSI-Stats"]
2929
assert "head;count=" in stats
3030
assert "get;count=" in stats
31-
assert "list;count=" in stats
3231

3332
response = client.get("/info.geojson")
3433
assert response.status_code == 200

tilebench/__init__.py

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,26 @@
1313

1414
import rasterio
1515
from loguru import logger as log
16-
from wurlitzer import pipes
1716

1817
fmt = "{time} | TILEBENCH | {message}"
1918
log.remove()
2019
log.add(sys.stderr, format=fmt)
2120

2221

23-
def parse_logs(rio_lines: List[str], curl_lines: List[str]) -> Dict[str, Any]:
22+
def parse_logs(logs: List[str]) -> Dict[str, Any]:
2423
"""Parse Rasterio and CURL logs."""
25-
# LIST
26-
list_requests = [line for line in rio_lines if " VSICURL: GetFileList" in line]
27-
list_summary = {
28-
"count": len(list_requests),
29-
}
30-
3124
# HEAD
32-
curl_head_requests = [line for line in curl_lines if line.startswith("> HEAD")]
25+
head_requests = len([line for line in logs if "CURL_INFO_HEADER_OUT: HEAD" in line])
3326
head_summary = {
34-
"count": len(curl_head_requests),
27+
"count": head_requests,
3528
}
3629

37-
# CURL GET
38-
# CURL logs failed requests
39-
curl_get_requests = [line for line in curl_lines if line.startswith("> GET")]
30+
# GET
31+
all_get_requests = len(
32+
[line for line in logs if "CURL_INFO_HEADER_OUT: GET" in line]
33+
)
4034

41-
# Rasterio GET
42-
# Rasterio only log successfull requests
43-
get_requests = [line for line in rio_lines if ": Downloading" in line]
35+
get_requests = [line for line in logs if ": Downloading" in line]
4436
get_values = [
4537
map(int, get.split(" Downloading ")[1].split(" ")[0].split("-"))
4638
for get in get_requests
@@ -49,17 +41,14 @@ def parse_logs(rio_lines: List[str], curl_lines: List[str]) -> Dict[str, Any]:
4941
data_transfer = sum([j - i + 1 for i, j in get_values])
5042

5143
get_summary = {
52-
"count": len(curl_get_requests),
44+
"count": all_get_requests,
5345
"bytes": data_transfer,
5446
"ranges": get_values_str,
5547
}
5648

57-
warp_kernel = [
58-
line.split(" ")[-2:] for line in rio_lines if "GDALWarpKernel" in line
59-
]
49+
warp_kernel = [line.split(" ")[-2:] for line in logs if "GDALWarpKernel" in line]
6050

6151
return {
62-
"LIST": list_summary,
6352
"HEAD": head_summary,
6453
"GET": get_summary,
6554
"WarpKernels": warp_kernel,
@@ -88,25 +77,23 @@ def wrapped_f(*args, **kwargs):
8877
logger.addHandler(handler)
8978

9079
gdal_config = config or {}
91-
gdal_config.update({"CPL_DEBUG": "ON", "CPL_CURL_VERBOSE": "TRUE"})
80+
gdal_config.update({"CPL_DEBUG": "ON", "CPL_CURL_VERBOSE": "YES"})
9281

93-
with pipes() as (_, curl_stream):
94-
with rasterio.Env(**gdal_config):
95-
with Timer() as t:
96-
prof = cProfile.Profile()
97-
retval = prof.runcall(func, *args, **kwargs)
98-
profile_stream = StringIO()
99-
ps = pstats.Stats(prof, stream=profile_stream)
100-
ps.strip_dirs().sort_stats("time", "ncalls").print_stats()
82+
with rasterio.Env(**gdal_config):
83+
with Timer() as t:
84+
prof = cProfile.Profile()
85+
retval = prof.runcall(func, *args, **kwargs)
86+
profile_stream = StringIO()
87+
ps = pstats.Stats(prof, stream=profile_stream)
88+
ps.strip_dirs().sort_stats("time", "ncalls").print_stats()
10189

10290
logger.removeHandler(handler)
10391
handler.close()
10492

105-
rio_lines = rio_stream.getvalue().splitlines()
106-
curl_lines = curl_stream.read().splitlines()
93+
logs = rio_stream.getvalue().splitlines()
10794
profile_lines = [p for p in profile_stream.getvalue().splitlines() if p]
10895

109-
results = parse_logs(rio_lines, curl_lines)
96+
results = parse_logs(logs)
11097
results["Timing"] = t.elapsed
11198

11299
if cprofile:
@@ -119,8 +106,7 @@ def wrapped_f(*args, **kwargs):
119106
results.pop("WarpKernels")
120107

121108
if raw:
122-
results["curl"] = curl_lines
123-
results["rasterio"] = rio_lines
109+
results["logs"] = logs
124110

125111
if not quiet:
126112
log.info(json.dumps(results))

tilebench/middleware.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from starlette.middleware.base import BaseHTTPMiddleware
1010
from starlette.requests import Request
1111
from starlette.types import ASGIApp, Message, Receive, Scope, Send
12-
from wurlitzer import pipes
1312

1413
from tilebench import parse_logs
1514

@@ -41,27 +40,24 @@ async def dispatch(self, request: Request, call_next):
4140
logger.addHandler(handler)
4241

4342
gdal_config = {"CPL_DEBUG": "ON", "CPL_CURL_VERBOSE": "TRUE"}
44-
with pipes() as (_, curl_stream):
45-
with rasterio.Env(**gdal_config, **self.config):
46-
response = await call_next(request)
43+
with rasterio.Env(**gdal_config, **self.config):
44+
response = await call_next(request)
4745

4846
logger.removeHandler(handler)
4947
handler.close()
5048

51-
if rio_stream or curl_stream:
49+
if rio_stream:
5250
rio_lines = rio_stream.getvalue().splitlines()
53-
curl_lines = curl_stream.read().splitlines()
5451

55-
results = parse_logs(rio_lines, curl_lines)
52+
results = parse_logs(rio_lines)
5653
head_results = "head;count={count}".format(**results["HEAD"])
57-
list_results = "list;count={count}".format(**results["LIST"])
5854
get_results = "get;count={count};size={bytes}".format(**results["GET"])
5955
ranges_results = "ranges; values={}".format(
6056
"|".join(results["GET"]["ranges"])
6157
)
6258
response.headers[
6359
"VSI-Stats"
64-
] = f"{list_results}, {head_results}, {get_results}, {ranges_results}"
60+
] = f"{head_results}, {get_results}, {ranges_results}"
6561

6662
return response
6763

tilebench/templates/index.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,18 +449,14 @@
449449
// Display the key/value pairs
450450
const stats = data.get("vsi-stats")
451451
if (stats) {
452-
const list = stats.split(',')[0]
453-
const listCount = list.split(';')[1].split('=')[1]
454-
455-
const head = stats.split(',')[1]
452+
const head = stats.split(',')[0]
456453
const headCount = head.split(';')[1].split('=')[1]
457454

458-
const get = stats.split(',')[2]
455+
const get = stats.split(',')[1]
459456
const getCount = get.split(';')[1].split('=')[1]
460457
const getSize = get.split(';')[2].split('=')[1]
461458

462459
html += '<table>'
463-
html += `<tr><td class="align-l">LIST</td><td class="px3 align-r">${listCount}</td></tr>`
464460
html += `<tr><td class="align-l">HEAD</td><td class="px3 align-r">${headCount}</td></tr>`
465461
html += `<tr><td class="align-l">GET</td><td class="px3 align-r">${getCount}</td></tr>`
466462
html += `<tr><td class="align-l">GET (bytes)</td><td class="px3 align-r">${getSize}</td></tr>`

0 commit comments

Comments
 (0)