Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .mbtiles support #549

Merged
merged 137 commits into from
Jan 9, 2023
Merged

Add .mbtiles support #549

merged 137 commits into from
Jan 9, 2023

Conversation

nyurik
Copy link
Member

@nyurik nyurik commented Jan 8, 2023

Merge after #548 and #517

Adds a new .mbtiles backend, without the grid support. Uses extensive tile content detection, i.e. if the content is gzipped, png, jpeg, gif, webp.

From CLI, can be as easy as adding a path to a directory that contains a .mbtiles file (works just like pmtiles support)

# All *.mbtiles files in this dir will be published.
# The filename will be used as the source ID
martin ./tests/fixtures

From configuration file, the path can be specified in a number of ways (same as pmtiles)

mbtiles:
  paths:
    # scan this whole dir, matching all *.mbtiles files
    - /dir-path
    # specific mbtiles file will be published as mbtiles2 source
    - /path/to/mbtiles2.mbtiles
  sources:
      # named source matching source name to a single file
      pm-src1: /tmp/mbtiles.mbtiles
      # named source, where the filename is explicitly set. This way we will be able to add more options later
      pm-src2:
        path: /tmp/mbtiles.mbtiles

Fixes #494

nyurik added 30 commits December 6, 2022 21:41
* All tests and internal code now uses ST_TileEnvelope function
* Remove `tile_bbox`
* Rename test function sources for clarity - this will be needed in a subsequent PR to add other function tests
Can handle the `getmvt(z,x,y) -> [bytea,md5]` case and several others.
* All table sources now use the same system as functions
* Proper table name escaping
* Prepared statements might speed things up, but this is not certain because we prepare on each get request. At least now we can optimize in one place.
BREAKING:
* srid is now the same type as PG -- i32
* renamed config vals `table_sources` and `function_sources` into `tables` and `functions`

Fixes:
* predictable order of instantiation
* bounding boxes computed in parallel for all tables (when not configured)
* split up discovery and query creation - this way user overrides happen before the final query is generated
* more proper name escaping
* lots of test improvements
* Fix id column issue
* Detect if postgis is newer than 3.1 and use st_tileenvolope margin param
* Use `PathBuf` instead of `String` where dealing with files
* Parse keep_alive as u64
* More config tests to crash if martin output contains warnings or errors
* Use `PathBuf` instead of `String` where dealing with files
* Parse keep_alive as u64
* More config tests to crash if martin output contains warnings or errors
* Use `PathBuf` instead of `String` where dealing with files
* Parse keep_alive as u64
* More config tests to crash if martin output contains warnings or errors
* Use `PathBuf` instead of `String` where dealing with files
* Parse keep_alive as u64
* More config tests to crash if martin output contains warnings or errors
* Since this is a library, all errors should have a strongly typed enum.
* table bounds computing function was not escaping identifiers
* table bounds computation was also silently ignoring all errors
@nyurik nyurik requested a review from stepankuzmin January 8, 2023 07:18
@codecov-commenter
Copy link

codecov-commenter commented Jan 8, 2023

Codecov Report

Base: 58.65% // Head: 57.75% // Decreases project coverage by -0.89% ⚠️

Coverage data is based on head (051c632) compared to base (ba65e34).
Patch coverage: 59.47% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #549      +/-   ##
==========================================
- Coverage   58.65%   57.75%   -0.90%     
==========================================
  Files          27       29       +2     
  Lines        2242     2507     +265     
==========================================
+ Hits         1315     1448     +133     
- Misses        927     1059     +132     
Impacted Files Coverage Δ
src/args/connections.rs 77.50% <ø> (ø)
src/lib.rs 41.64% <ø> (-1.59%) ⬇️
src/mbtiles/mod.rs 0.00% <0.00%> (ø)
src/pmtiles/mod.rs 27.63% <0.00%> (-1.95%) ⬇️
src/utils/utilities.rs 50.00% <ø> (-9.68%) ⬇️
src/config.rs 58.53% <36.36%> (-1.74%) ⬇️
martin-tile-utils/src/lib.rs 73.68% <60.00%> (-0.74%) ⬇️
src/srv/server.rs 76.26% <66.66%> (-2.24%) ⬇️
martin-mbtiles/src/lib.rs 72.37% <72.37%> (ø)
src/args/pg.rs 84.05% <100.00%> (ø)
... and 7 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@maxammann
Copy link
Contributor

I'm looking right now for a mbtiles server so this comes just in time 😅

I'll test this out now, for a code review the PR is maybe too large. Maybe you can leave comments where you wish reviews.

@nyurik
Copy link
Member Author

nyurik commented Jan 8, 2023

Thanks, let me know if you run into any issues. The reason this pr is so big is because it includes two other prs. If you review them in order, they will be much smaller. @stepankuzmin said he will try to get to them today

- /dir-path
- /path/to/pmtiles2.pmtiles
sources:
pm-src1: /tmp/pmtiles.pmtiles
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should also add the *.mbtiles test here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no point because this test is not specific to pmtiles - it decodes a sub-element under pmtiles: or mbtiles: keys. I will change the filenames to make it clearer.

@maxammann
Copy link
Contributor

Not sure where it comes from but I have an emptry string in the tiles array:

image

pub async fn get_metadata(&self) -> MbtResult<Metadata> {
let mut res = Metadata {
tilejson: tilejson! {
tiles: vec![String::new()],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this adds an empty string in the tiles array.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll need to fix this, and also handle the x-forwarded-for header (there is a ticket for that). I'll have time tonight to look at it, in a few hrs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That header works for me already. It places the correct host and protocol

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which header? We currently handle x-rewrite-url, which is a really bad one from the security perspective. See #504

@nyurik nyurik merged commit 9e5ed2f into maplibre:main Jan 9, 2023
@nyurik nyurik deleted the mbtiles branch January 9, 2023 05:10
@nyurik nyurik mentioned this pull request Feb 7, 2023
@ewagstaff
Copy link

@nyurik is there a good source to read more about what this change allows? Would this mean MapLibre can display data from a static .mbtiles file without the need to spin up a map server?

@nyurik
Copy link
Member Author

nyurik commented Feb 17, 2023

@ewagstaff this change simply allows mbtiles file to be Martin's source of data, just like Postgres and .pmtiles files. Martin itself is a map server, but if your data is in a file format, Martin would not need any additional servers. If you want completely serverless, take a look at pmtiles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement .mbtiles support
5 participants