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

PGStac #126

Merged
merged 68 commits into from
Jun 18, 2021
Merged

PGStac #126

merged 68 commits into from
Jun 18, 2021

Conversation

bitner
Copy link
Collaborator

@bitner bitner commented Apr 22, 2021

Adds pgstac backend to stac_fastapi.

Supersedes #119 with automatic detection of async endpoints.

Adds 1:1 tests for all tests in sqlalchemy branch with the exception of the Context and BulkLoad plugin tests which are not supported on PGStac.

Updates the Makefile, Docker, and CI configurations to add support for running/testing pgstac.

Copy link
Contributor

@kylebarron kylebarron left a comment

Choose a reason for hiding this comment

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

Very cool. I'm excited!

stac_fastapi/api/stac_fastapi/api/app.py Outdated Show resolved Hide resolved
stac_fastapi/pgstac/setup.py Outdated Show resolved Hide resolved
@property
def reader_connection_string(self):
"""Create reader psql connection string."""
return f"postgresql://{self.postgres_user}:{self.postgres_pass}@{self.postgres_host_reader}:{self.postgres_port}/{self.postgres_dbname}"
Copy link
Contributor

Choose a reason for hiding this comment

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

I see pydantic has a PostgresDsn type. Maybe it would be useful for validation purposes to have reader_connection_string be a field with init=False that's set within __post_init__? Then you'd have fuller validation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can look at that later (across both pgstac and sqlalchemy - which this is set up identically to right now). I know I ran into some issue initially when I did use the PostgresDsn type, I think it had some issues when you didn't directly supply some non-required fields IIRC.

stac_fastapi/pgstac/stac_fastapi/pgstac/schemas.py Outdated Show resolved Hide resolved
stac_fastapi/pgstac/stac_fastapi/pgstac/transactions.py Outdated Show resolved Hide resolved
@bitner
Copy link
Collaborator Author

bitner commented Jun 15, 2021

@bitner checked out the branch for this PR and tried docker-compose build; docker-compose up, and am getting a loop of:

stac-fastapi-sqlalchemy | error walking file system: FileNotFoundError [Errno 2] No such file or directory: '/app/venv/bin/python3.8'

in the logs. This doesn't happen on master. Any ideas?
@lossyrob do you have a virtual environment somewhere in the tree under stac-fastapi? I think this could be the watchgod reloader on uvicorn

@@ -51,10 +83,10 @@ services:
volumes:
- ./:/app
command: >
bash -c "sleep 10 && alembic upgrade head && python /app/scripts/ingest_joplin.py"
bash -c "sleep 10 && cd stac_fastapi/sqlalchemy && alembic upgrade head && python scripts/ingest_joplin.py"
Copy link
Member

Choose a reason for hiding this comment

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

Migration is broken with this change, fixed by:

Suggested change
bash -c "sleep 10 && cd stac_fastapi/sqlalchemy && alembic upgrade head && python scripts/ingest_joplin.py"
bash -c "sleep 10 && cd stac_fastapi/sqlalchemy && alembic upgrade head && cd ../.. && python scripts/ingest_joplin.py"

@lossyrob
Copy link
Member

@bitner I was able to work around the venv issue by not loading the entire source into the container, which I think is better practice anyway.

diff --git a/Dockerfile b/Dockerfile
index ee0412f..21b7c64 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -12,7 +12,7 @@ ARG install_dev_dependencies=true
 WORKDIR /app

 # Install stac_fastapi.types
-COPY . /app
+COPY ./stac_fastapi /app/stac_fastapi

 ENV PATH=$PATH:/install/bin

diff --git a/docker-compose.yml b/docker-compose.yml
index c5124ac..bd6a98e 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -25,7 +25,7 @@ services:
     ports:
       - "8081:8081"
     volumes:
-      - ./:/app
+      - ./stac_fastapi:/app/stac_fastapi
     depends_on:
       - database
     command:
@@ -55,7 +55,7 @@ services:
     ports:
       - "8082:8082"
     volumes:
-      - ./:/app
+      - ./stac_fastapi:/app/stac_fastapi
     depends_on:
       - database
     command:
@@ -81,7 +81,8 @@ services:
       - POSTGRES_HOST=database
       - POSTGRES_PORT=5432
     volumes:
-      - ./:/app
+      - ./stac_fastapi:/app/stac_fastapi
+      - ./scripts:/app/scripts
     command: >
       bash -c "sleep 10 && cd stac_fastapi/sqlalchemy && alembic upgrade head && python scripts/ingest_joplin.py"
     depends_on:

Now I'm getting new errors on docker-compose up 🤔

stac-db                 | 2021-06-16 17:29:37.915 UTC [223] FATAL:  sorry, too many clients already
stac-fastapi-pgstac     | asyncpg.exceptions.TooManyConnectionsError: sorry, too many clients already
sqlalchemy-migration_1  | sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL:  sorry, too many clients already

(there's a bunch of those, all related to too many clients).

Confused on how that's not working for me and working for others - there doesn't seem to be any environment variables that I may be loading in and it's all containerized...any ideas on this one?

@bitner
Copy link
Collaborator Author

bitner commented Jun 16, 2021

Hey @lossyrob ,

That looks like you are running out of PG connections, wondering if things just were finishing quicker on my machine so I wasn't hitting that?.

I just pushed a change for docker-compose that

  1. does not use --reload for uvicorn
  2. makes the changes you pointed out to limit the directories mounted
  3. uses a pool of 1 by default for asyncpg
  4. bumps up the number of total postgres connections in the docker pg instance

Famous words: "works on my system", but maybe if you still are running into issues we hop on a call to try to debug?

@geospatial-jeff geospatial-jeff self-requested a review June 17, 2021 06:45
Copy link
Collaborator

@geospatial-jeff geospatial-jeff left a comment

Choose a reason for hiding this comment

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

nice work @bitner!

@lossyrob
Copy link
Member

lossyrob commented Jun 17, 2021

Looking good, but ingest_joplin.py is broken. Are you running it as part of testing? Or perhaps because the data is already there it's not running the ingest? You should stop and remove the containers to clear the data and try the startup process again to make sure a clean dev environment runs.

The script points to a non-existent data_dir, should be:

def ingest_joplin_data(data_dir=Path.cwd() / "stac_fastapi" / "sqlalchemy" / "tests" / "data" / "joplin"):

Seems like this broke during the subpackage reorg, but I'd recommend fixing here before merge.

Edit: I see this is mentioned in #150

Copy link
Member

@lossyrob lossyrob left a comment

Choose a reason for hiding this comment

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

Is there a development data ingest step for pgstac? If not, we should implement one similar to ingest_joplin.py (or just reuse that). That way it'll be easier to use in the dev environment in general, and manually inspect the JSON responses for this review. Thanks!

"""
request = kwargs["request"]
base_url = str(request.base_url)
landing_page = LandingPage(
Copy link
Member

Choose a reason for hiding this comment

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

Missing the "collections" link

Link(
rel="data",
type=MimeTypes.json,
href=urljoin(base_url, "collections"),
),

Perhaps we can define a def get_landing_page(self) method that both implementations could use, to ensure consistency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lossyrob get_landing_page is still dependent on the backend (to get the list of collections), so the direct get_landing_page() still needs to be defined for both backends. I do think that we should look to move the Link generation code into a common place across backends, but I think it's best to do that after this has been merged so we can track things a bit more granularly that are touching both backends. For this PR, I've tried to avoid doing too many things that would change/affect the sqlalchemy backend.

I just pushed a commit that:

  1. moves the test data out of sqlalchemy
  2. modifies ingest_joplin.py to take an app_host parameter
  3. adds ingest_joplin.py runner to docker-compose for pgstac backend
  4. modifies /collections to return empty array rather than not found error (and changes test that was expecting not found)
  5. adds missing collections/ link to landing page

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha - thanks for the quick commits, I'll take another look at this and report back!

Copy link
Member

Choose a reason for hiding this comment

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

Hitting http://localhost:8082/collections/joplin/items with the development data, looks like the null issue has popped up again?

Response JSON
{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -94.6334839,
              37.0595608
            ],
            [
              -94.6334839,
              37.0332547
            ],
            [
              -94.6005249,
              37.0332547
            ],
            [
              -94.6005249,
              37.0595608
            ],
            [
              -94.6334839,
              37.0595608
            ]
          ]
        ]
      },
      "properties": {
        "gsd": 0.5971642834779395,
        "title": null,
        "width": 2500,
        "height": 2500,
        "created": null,
        "mission": null,
        "updated": null,
        "datetime": "2000-02-02T00:00:00Z",
        "platform": null,
        "proj:epsg": 3857,
        "providers": null,
        "description": null,
        "instruments": null,
        "orientation": "nadir",
        "end_datetime": null,
        "constellation": null,
        "start_datetime": null
      },
      "id": "fe916452-ba6f-4631-9154-c249924a122d",
      "bbox": [
        -94.6334839,
        37.0332547,
        -94.6005249,
        37.0595608
      ],
      "stac_version": "1.0.0-beta.2",
      "assets": {
        "COG": {
          "gsd": null,
          "href": "https://arturo-stac-api-test-data.s3.amazonaws.com/joplin/images/may24C355000e4102500n.tif",
          "type": "image/tiff; application=geotiff; profile=cloud-optimized",
          "bands": null,
          "roles": null,
          "title": "NOAA STORM COG",
          "created": null,
          "mission": null,
          "updated": null,
          "platform": null,
          "multihash": null,
          "providers": null,
          "description": null,
          "instruments": null,
          "end_datetime": null,
          "constellation": null,
          "polarizations": null,
          "start_datetime": null
        }
      },
      "links": [
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "collection",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "parent",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/",
          "rel": "root",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/fe916452-ba6f-4631-9154-c249924a122d",
          "rel": "self",
          "type": "application/geo+json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/fe916452-ba6f-4631-9154-c249924a122d/tiles",
          "rel": "alternate",
          "type": "application/json",
          "title": "tiles"
        }
      ],
      "collection": "joplin"
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -94.6911621,
              37.1033841
            ],
            [
              -94.6911621,
              37.0770932
            ],
            [
              -94.6582031,
              37.0770932
            ],
            [
              -94.6582031,
              37.1033841
            ],
            [
              -94.6911621,
              37.1033841
            ]
          ]
        ]
      },
      "properties": {
        "gsd": 0.5971642834779395,
        "title": null,
        "width": 2500,
        "height": 2500,
        "created": null,
        "mission": null,
        "updated": null,
        "datetime": "2000-02-02T00:00:00Z",
        "platform": null,
        "proj:epsg": 3857,
        "providers": null,
        "description": null,
        "instruments": null,
        "orientation": "nadir",
        "end_datetime": null,
        "constellation": null,
        "start_datetime": null
      },
      "id": "f7f164c9-cfdf-436d-a3f0-69864c38ba2a",
      "bbox": [
        -94.6911621,
        37.0770932,
        -94.6582031,
        37.1033841
      ],
      "stac_version": "1.0.0-beta.2",
      "assets": {
        "COG": {
          "gsd": null,
          "href": "https://arturo-stac-api-test-data.s3.amazonaws.com/joplin/images/may24C350000e4107500n.tif",
          "type": "image/tiff; application=geotiff; profile=cloud-optimized",
          "bands": null,
          "roles": null,
          "title": "NOAA STORM COG",
          "created": null,
          "mission": null,
          "updated": null,
          "platform": null,
          "multihash": null,
          "providers": null,
          "description": null,
          "instruments": null,
          "end_datetime": null,
          "constellation": null,
          "polarizations": null,
          "start_datetime": null
        }
      },
      "links": [
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "collection",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "parent",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/",
          "rel": "root",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/f7f164c9-cfdf-436d-a3f0-69864c38ba2a",
          "rel": "self",
          "type": "application/geo+json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/f7f164c9-cfdf-436d-a3f0-69864c38ba2a/tiles",
          "rel": "alternate",
          "type": "application/json",
          "title": "tiles"
        }
      ],
      "collection": "joplin"
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -94.4631958,
              37.0836668
            ],
            [
              -94.4631958,
              37.057369
            ],
            [
              -94.4329834,
              37.057369
            ],
            [
              -94.4329834,
              37.0836668
            ],
            [
              -94.4631958,
              37.0836668
            ]
          ]
        ]
      },
      "properties": {
        "gsd": 0.5971642834779395,
        "title": null,
        "width": 2500,
        "height": 2500,
        "created": null,
        "mission": null,
        "updated": null,
        "datetime": "2000-02-02T00:00:00Z",
        "platform": null,
        "proj:epsg": 3857,
        "providers": null,
        "description": null,
        "instruments": null,
        "orientation": "nadir",
        "end_datetime": null,
        "constellation": null,
        "start_datetime": null
      },
      "id": "f734401c-2df0-4694-a353-cdd3ea760cdc",
      "bbox": [
        -94.4631958,
        37.057369,
        -94.4329834,
        37.0836668
      ],
      "stac_version": "1.0.0-beta.2",
      "assets": {
        "COG": {
          "gsd": null,
          "href": "https://arturo-stac-api-test-data.s3.amazonaws.com/joplin/images/may24C370000e4105000n.tif",
          "type": "image/tiff; application=geotiff; profile=cloud-optimized",
          "bands": null,
          "roles": null,
          "title": "NOAA STORM COG",
          "created": null,
          "mission": null,
          "updated": null,
          "platform": null,
          "multihash": null,
          "providers": null,
          "description": null,
          "instruments": null,
          "end_datetime": null,
          "constellation": null,
          "polarizations": null,
          "start_datetime": null
        }
      },
      "links": [
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "collection",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "parent",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/",
          "rel": "root",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/f734401c-2df0-4694-a353-cdd3ea760cdc",
          "rel": "self",
          "type": "application/geo+json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/f734401c-2df0-4694-a353-cdd3ea760cdc/tiles",
          "rel": "alternate",
          "type": "application/json",
          "title": "tiles"
        }
      ],
      "collection": "joplin"
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -94.43573,
              37.0836668
            ],
            [
              -94.43573,
              37.0595608
            ],
            [
              -94.402771,
              37.0595608
            ],
            [
              -94.402771,
              37.0836668
            ],
            [
              -94.43573,
              37.0836668
            ]
          ]
        ]
      },
      "properties": {
        "gsd": 0.5971642834779395,
        "title": null,
        "width": 2500,
        "height": 2500,
        "created": null,
        "mission": null,
        "updated": null,
        "datetime": "2000-02-02T00:00:00Z",
        "platform": null,
        "proj:epsg": 3857,
        "providers": null,
        "description": null,
        "instruments": null,
        "orientation": "nadir",
        "end_datetime": null,
        "constellation": null,
        "start_datetime": null
      },
      "id": "f490b7af-0019-45e2-854b-3854d07fd063",
      "bbox": [
        -94.43573,
        37.0595608,
        -94.402771,
        37.0836668
      ],
      "stac_version": "1.0.0-beta.2",
      "assets": {
        "COG": {
          "gsd": null,
          "href": "https://arturo-stac-api-test-data.s3.amazonaws.com/joplin/images/may24C372500e4105000n.tif",
          "type": "image/tiff; application=geotiff; profile=cloud-optimized",
          "bands": null,
          "roles": null,
          "title": "NOAA STORM COG",
          "created": null,
          "mission": null,
          "updated": null,
          "platform": null,
          "multihash": null,
          "providers": null,
          "description": null,
          "instruments": null,
          "end_datetime": null,
          "constellation": null,
          "polarizations": null,
          "start_datetime": null
        }
      },
      "links": [
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "collection",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "parent",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/",
          "rel": "root",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/f490b7af-0019-45e2-854b-3854d07fd063",
          "rel": "self",
          "type": "application/geo+json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/f490b7af-0019-45e2-854b-3854d07fd063/tiles",
          "rel": "alternate",
          "type": "application/json",
          "title": "tiles"
        }
      ],
      "collection": "joplin"
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -94.6884155,
              37.0595608
            ],
            [
              -94.6884155,
              37.0332547
            ],
            [
              -94.6554565,
              37.0332547
            ],
            [
              -94.6554565,
              37.0595608
            ],
            [
              -94.6884155,
              37.0595608
            ]
          ]
        ]
      },
      "properties": {
        "gsd": 0.5971642834779395,
        "title": null,
        "width": 2500,
        "height": 2500,
        "created": null,
        "mission": null,
        "updated": null,
        "datetime": "2000-02-02T00:00:00Z",
        "platform": null,
        "proj:epsg": 3857,
        "providers": null,
        "description": null,
        "instruments": null,
        "orientation": "nadir",
        "end_datetime": null,
        "constellation": null,
        "start_datetime": null
      },
      "id": "f2cca2a3-288b-4518-8a3e-a4492bb60b08",
      "bbox": [
        -94.6884155,
        37.0332547,
        -94.6554565,
        37.0595608
      ],
      "stac_version": "1.0.0-beta.2",
      "assets": {
        "COG": {
          "gsd": null,
          "href": "https://arturo-stac-api-test-data.s3.amazonaws.com/joplin/images/may24C350000e4102500n.tif",
          "type": "image/tiff; application=geotiff; profile=cloud-optimized",
          "bands": null,
          "roles": null,
          "title": "NOAA STORM COG",
          "created": null,
          "mission": null,
          "updated": null,
          "platform": null,
          "multihash": null,
          "providers": null,
          "description": null,
          "instruments": null,
          "end_datetime": null,
          "constellation": null,
          "polarizations": null,
          "start_datetime": null
        }
      },
      "links": [
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "collection",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "parent",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/",
          "rel": "root",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/f2cca2a3-288b-4518-8a3e-a4492bb60b08",
          "rel": "self",
          "type": "application/geo+json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/f2cca2a3-288b-4518-8a3e-a4492bb60b08/tiles",
          "rel": "alternate",
          "type": "application/json",
          "title": "tiles"
        }
      ],
      "collection": "joplin"
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -94.6609497,
              37.0595608
            ],
            [
              -94.6609497,
              37.0332547
            ],
            [
              -94.6279907,
              37.0332547
            ],
            [
              -94.6279907,
              37.0595608
            ],
            [
              -94.6609497,
              37.0595608
            ]
          ]
        ]
      },
      "properties": {
        "gsd": 0.5971642834779395,
        "title": null,
        "width": 2500,
        "height": 2500,
        "created": null,
        "mission": null,
        "updated": null,
        "datetime": "2000-02-02T00:00:00Z",
        "platform": null,
        "proj:epsg": 3857,
        "providers": null,
        "description": null,
        "instruments": null,
        "orientation": "nadir",
        "end_datetime": null,
        "constellation": null,
        "start_datetime": null
      },
      "id": "ea0fddf4-56f9-4a16-8a0b-f6b0b123b7cf",
      "bbox": [
        -94.6609497,
        37.0332547,
        -94.6279907,
        37.0595608
      ],
      "stac_version": "1.0.0-beta.2",
      "assets": {
        "COG": {
          "gsd": null,
          "href": "https://arturo-stac-api-test-data.s3.amazonaws.com/joplin/images/may24C352500e4102500n.tif",
          "type": "image/tiff; application=geotiff; profile=cloud-optimized",
          "bands": null,
          "roles": null,
          "title": "NOAA STORM COG",
          "created": null,
          "mission": null,
          "updated": null,
          "platform": null,
          "multihash": null,
          "providers": null,
          "description": null,
          "instruments": null,
          "end_datetime": null,
          "constellation": null,
          "polarizations": null,
          "start_datetime": null
        }
      },
      "links": [
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "collection",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "parent",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/",
          "rel": "root",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/ea0fddf4-56f9-4a16-8a0b-f6b0b123b7cf",
          "rel": "self",
          "type": "application/geo+json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/ea0fddf4-56f9-4a16-8a0b-f6b0b123b7cf/tiles",
          "rel": "alternate",
          "type": "application/json",
          "title": "tiles"
        }
      ],
      "collection": "joplin"
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -94.6060181,
              37.0595608
            ],
            [
              -94.6060181,
              37.0332547
            ],
            [
              -94.5730591,
              37.0332547
            ],
            [
              -94.5730591,
              37.0595608
            ],
            [
              -94.6060181,
              37.0595608
            ]
          ]
        ]
      },
      "properties": {
        "gsd": 0.5971642834779395,
        "title": null,
        "width": 2500,
        "height": 2500,
        "created": null,
        "mission": null,
        "updated": null,
        "datetime": "2000-02-02T00:00:00Z",
        "platform": null,
        "proj:epsg": 3857,
        "providers": null,
        "description": null,
        "instruments": null,
        "orientation": "nadir",
        "end_datetime": null,
        "constellation": null,
        "start_datetime": null
      },
      "id": "e0a02e4e-aa0c-412e-8f63-6f5344f829df",
      "bbox": [
        -94.6060181,
        37.0332547,
        -94.5730591,
        37.0595608
      ],
      "stac_version": "1.0.0-beta.2",
      "assets": {
        "COG": {
          "gsd": null,
          "href": "https://arturo-stac-api-test-data.s3.amazonaws.com/joplin/images/may24C357500e4102500n.tif",
          "type": "image/tiff; application=geotiff; profile=cloud-optimized",
          "bands": null,
          "roles": null,
          "title": "NOAA STORM COG",
          "created": null,
          "mission": null,
          "updated": null,
          "platform": null,
          "multihash": null,
          "providers": null,
          "description": null,
          "instruments": null,
          "end_datetime": null,
          "constellation": null,
          "polarizations": null,
          "start_datetime": null
        }
      },
      "links": [
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "collection",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "parent",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/",
          "rel": "root",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/e0a02e4e-aa0c-412e-8f63-6f5344f829df",
          "rel": "self",
          "type": "application/geo+json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/e0a02e4e-aa0c-412e-8f63-6f5344f829df/tiles",
          "rel": "alternate",
          "type": "application/json",
          "title": "tiles"
        }
      ],
      "collection": "joplin"
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -94.4659424,
              37.1077651
            ],
            [
              -94.4659424,
              37.0814756
            ],
            [
              -94.4329834,
              37.0814756
            ],
            [
              -94.4329834,
              37.1077651
            ],
            [
              -94.4659424,
              37.1077651
            ]
          ]
        ]
      },
      "properties": {
        "gsd": 0.5971642834779395,
        "title": null,
        "width": 2500,
        "height": 2500,
        "created": null,
        "mission": null,
        "updated": null,
        "datetime": "2000-02-02T00:00:00Z",
        "platform": null,
        "proj:epsg": 3857,
        "providers": null,
        "description": null,
        "instruments": null,
        "orientation": "nadir",
        "end_datetime": null,
        "constellation": null,
        "start_datetime": null
      },
      "id": "da6ef938-c58f-4bab-9d4e-89f6ae667da2",
      "bbox": [
        -94.4659424,
        37.0814756,
        -94.4329834,
        37.1077651
      ],
      "stac_version": "1.0.0-beta.2",
      "assets": {
        "COG": {
          "gsd": null,
          "href": "https://arturo-stac-api-test-data.s3.amazonaws.com/joplin/images/may24C370000e4107500n.tif",
          "type": "image/tiff; application=geotiff; profile=cloud-optimized",
          "bands": null,
          "roles": null,
          "title": "NOAA STORM COG",
          "created": null,
          "mission": null,
          "updated": null,
          "platform": null,
          "multihash": null,
          "providers": null,
          "description": null,
          "instruments": null,
          "end_datetime": null,
          "constellation": null,
          "polarizations": null,
          "start_datetime": null
        }
      },
      "links": [
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "collection",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "parent",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/",
          "rel": "root",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/da6ef938-c58f-4bab-9d4e-89f6ae667da2",
          "rel": "self",
          "type": "application/geo+json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/da6ef938-c58f-4bab-9d4e-89f6ae667da2/tiles",
          "rel": "alternate",
          "type": "application/json",
          "title": "tiles"
        }
      ],
      "collection": "joplin"
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -94.5758057,
              37.0836668
            ],
            [
              -94.5758057,
              37.057369
            ],
            [
              -94.5455933,
              37.057369
            ],
            [
              -94.5455933,
              37.0836668
            ],
            [
              -94.5758057,
              37.0836668
            ]
          ]
        ]
      },
      "properties": {
        "gsd": 0.5971642834779395,
        "title": null,
        "width": 2500,
        "height": 2500,
        "created": null,
        "mission": null,
        "updated": null,
        "datetime": "2000-02-02T00:00:00Z",
        "platform": null,
        "proj:epsg": 3857,
        "providers": null,
        "description": null,
        "instruments": null,
        "orientation": "nadir",
        "end_datetime": null,
        "constellation": null,
        "start_datetime": null
      },
      "id": "d8461d8c-3d2b-4e4e-a931-7ae61ca06dbf",
      "bbox": [
        -94.5758057,
        37.057369,
        -94.5455933,
        37.0836668
      ],
      "stac_version": "1.0.0-beta.2",
      "assets": {
        "COG": {
          "gsd": null,
          "href": "https://arturo-stac-api-test-data.s3.amazonaws.com/joplin/images/may24C360000e4105000n.tif",
          "type": "image/tiff; application=geotiff; profile=cloud-optimized",
          "bands": null,
          "roles": null,
          "title": "NOAA STORM COG",
          "created": null,
          "mission": null,
          "updated": null,
          "platform": null,
          "multihash": null,
          "providers": null,
          "description": null,
          "instruments": null,
          "end_datetime": null,
          "constellation": null,
          "polarizations": null,
          "start_datetime": null
        }
      },
      "links": [
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "collection",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "parent",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/",
          "rel": "root",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/d8461d8c-3d2b-4e4e-a931-7ae61ca06dbf",
          "rel": "self",
          "type": "application/geo+json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/d8461d8c-3d2b-4e4e-a931-7ae61ca06dbf/tiles",
          "rel": "alternate",
          "type": "application/json",
          "title": "tiles"
        }
      ],
      "collection": "joplin"
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -94.6609497,
              37.1033841
            ],
            [
              -94.6609497,
              37.0770932
            ],
            [
              -94.6279907,
              37.0770932
            ],
            [
              -94.6279907,
              37.1033841
            ],
            [
              -94.6609497,
              37.1033841
            ]
          ]
        ]
      },
      "properties": {
        "gsd": 0.5971642834779395,
        "title": null,
        "width": 2500,
        "height": 2500,
        "created": null,
        "mission": null,
        "updated": null,
        "datetime": "2000-02-02T00:00:00Z",
        "platform": null,
        "proj:epsg": 3857,
        "providers": null,
        "description": null,
        "instruments": null,
        "orientation": "nadir",
        "end_datetime": null,
        "constellation": null,
        "start_datetime": null
      },
      "id": "d4eccfa2-7d77-4624-9e2a-3f59102285bb",
      "bbox": [
        -94.6609497,
        37.0770932,
        -94.6279907,
        37.1033841
      ],
      "stac_version": "1.0.0-beta.2",
      "assets": {
        "COG": {
          "gsd": null,
          "href": "https://arturo-stac-api-test-data.s3.amazonaws.com/joplin/images/may24C352500e4107500n.tif",
          "type": "image/tiff; application=geotiff; profile=cloud-optimized",
          "bands": null,
          "roles": null,
          "title": "NOAA STORM COG",
          "created": null,
          "mission": null,
          "updated": null,
          "platform": null,
          "multihash": null,
          "providers": null,
          "description": null,
          "instruments": null,
          "end_datetime": null,
          "constellation": null,
          "polarizations": null,
          "start_datetime": null
        }
      },
      "links": [
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "collection",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin",
          "rel": "parent",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/",
          "rel": "root",
          "type": "application/json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/d4eccfa2-7d77-4624-9e2a-3f59102285bb",
          "rel": "self",
          "type": "application/geo+json"
        },
        {
          "href": "http://localhost:8082/collections/joplin/items/d4eccfa2-7d77-4624-9e2a-3f59102285bb/tiles",
          "rel": "alternate",
          "type": "application/json",
          "title": "tiles"
        }
      ],
      "collection": "joplin"
    }
  ],
  "stac_version": "1.0.0-beta.2",
  "links": [
    {
      "href": "http://localhost:8082/collections/joplin/items",
      "rel": "items",
      "type": "application/geo+json"
    },
    {
      "href": "http://localhost:8082/",
      "rel": "parent",
      "type": "application/json"
    },
    {
      "href": "http://localhost:8082/",
      "rel": "root",
      "type": "application/json"
    },
    {
      "href": "http://localhost:8082/collections/joplin",
      "rel": "self",
      "type": "application/json"
    },
    {
      "href": "http://localhost:8082/collections/joplin/items?token=next:d191a6fd-7881-4421-805c-e246371e5cc4",
      "rel": "next",
      "type": "application/json",
      "method": "GET",
      "merge": false
    }
  ],
  "timeStamp": "2021-06-17T14:58:21.337549+00:00"
}  

Copy link
Member

Choose a reason for hiding this comment

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

(Unresolving as there's a new issue mentioned, should made a new thread)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kylebarron you going to just keep thumbsupping contradicting comments? ;-)

Copy link
Contributor

@kylebarron kylebarron Jun 17, 2021

Choose a reason for hiding this comment

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

Calling me out 🙈 Well first I read @geospatial-jeff 's comment, and that made sense, but then I read your comment, and that made sense too 😂

...unthumbsupping comments to hide my ignorance 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Honestly, I claim ignorance on a lot of the intricacies with async & python, so I really have no clue which would be more correct. My laziness definitely tends towards the solution with the least amount of work/repetition.

Copy link
Collaborator

@geospatial-jeff geospatial-jeff Jun 17, 2021

Choose a reason for hiding this comment

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

If your route handler is async def you need to wrap any synchronous code (ex. sqlalchemy pre v1.4) with a thread pool executor to prevent synchronous calls from blocking the event loop. If this is not the case a potentially long database call might prevent the fastapi application from handling new requests because the event loop is blocked. Using a synchronous route handler wraps the entire function call in a thread pool executor which is why you can safely execute synchronous code in a non-blocking fashion.

Also because the backend clients are decoupled from the API layer and may not necessarily be called within the context of FastAPI, we generally don't want async def functions that are running blocking code to begin with.

We could switch everything to async and just make people aware that they need to be executing synchronous code in threads but I'm not a fan of being overly opinionated about how code is executed as this will change based on the context.

Copy link
Collaborator

Choose a reason for hiding this comment

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

My preference is still creating an AsyncBaseClient and BaseClient so we can explicitly support both concurrency models.

stac_fastapi/pgstac/stac_fastapi/pgstac/core.py Outdated Show resolved Hide resolved
Copy link
Member

@lossyrob lossyrob left a comment

Choose a reason for hiding this comment

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

Finished manual tests comparing the sqlalchemy vs pgstac output in the dev environment. Nice work! 🚀

@geospatial-jeff geospatial-jeff merged commit 95265d0 into stac-utils:master Jun 18, 2021
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.

5 participants