Skip to content

Commit

Permalink
Parameterize and configure tests using YAML (#23)
Browse files Browse the repository at this point in the history
Co-authored-by: David Gauldie <dgauldie@uncharted.software>
Co-authored-by: Brandon Rose <rose.brandon.m@gmail.com>
  • Loading branch information
3 people authored Aug 29, 2023
1 parent b86fc88 commit f38285b
Show file tree
Hide file tree
Showing 40 changed files with 1,035 additions and 16,334 deletions.
35 changes: 0 additions & 35 deletions .github/workflows/lint.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@ repos:
rev: v4.4.0
hooks:
- id: check-yaml
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export LANG
.PHONY:init
init:.env
poetry install --with api
poetry run pre-commit install
git submodule update --init;

# Environment file copy
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Terarium TA1 Middleware Service
# Terarium Knowledge Middleware

[![codecov](https://codecov.io/github/DARPA-ASKEM/TA1-Service/branch/main/graph/badge.svg?token=XEARJHESHY)](https://codecov.io/github/DARPA-ASKEM/TA1-Service)
[![codecov](https://codecov.io/github/DARPA-ASKEM/knowledge-middleware/branch/main/graph/badge.svg?token=XEARJHESHY)](https://codecov.io/github/DARPA-ASKEM/knowledge-middleware)

The TA1 Middleware Service is designed to provide an intermediate job queue for management of long running TA1 extraction and profiling tasks. It enables the Terarium HMI to request TA1 tasks to be performed asynchronously, with robust error handling, and with customized ETL of TA1 responses into Terarium specific schemas and specifications. It currently supports the following functions:
The Knowledge Middleware is designed to provide an intermediate job queue for management of long-running extraction and profiling tasks. It enables the Terarium HMI to request large knowledge discovery and curation tasks to be performed asynchronously, with robust error handling, and with customized ETL of backend service responses into Terarium specific schemas and specifications. It currently supports the following functions:

1. Equation to AMR: both LaTeX and MathML
2. Code to AMR: code snippets only
Expand Down Expand Up @@ -44,8 +44,11 @@ pytest --cov . tests
### Testing Configuration

To modify your test configuration, edit the `tests/conftest.py` file. In particular note that setting `LIVE` to `TRUE` and adding the correct endpoints for TA1 will send real payloads to TA1 services and validate the results.
Set environment variable `MOCK_TA1` to `False` and adding the correct endpoints for TA1 will send real payloads to TA1 services and validate the results.

To add additional scenarios, create a new directory in `tests/scenarios`. The directory must contain a `config.yaml` where each tests you wish to be run
will be specified in `enabled`.

## License

[Apache License 2.0](LICENSE)
[Apache License 2.0](LICENSE)
8 changes: 4 additions & 4 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ RUN pip install --no-cache-dir poetry==1.5.1
RUN poetry config virtualenvs.create false && \
poetry install --no-root --no-cache --with api

COPY api ta1-service/api
COPY lib ta1-service/lib
WORKDIR /ta1-service
COPY api knowledge-middleware/api
COPY lib knowledge-middleware/lib
WORKDIR /knowledge-middleware

EXPOSE 8000
ENV PYTHONPATH=/ta1-service
ENV PYTHONPATH=/knowledge-middleware
CMD [ "uvicorn", "api.server:app", "--reload", "--host", "0.0.0.0", "--port", "8000" ]
14 changes: 7 additions & 7 deletions api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

def build_api(*args) -> FastAPI:
api = FastAPI(
title="Terarium TA1 Middleware Service",
description="Middleware for managing interactions with various TA1 services.",
title="Terarium Knowledge Middleware Service",
description="Middleware for managing interactions with various services.",
docs_url="/",
)
origins = [
Expand Down Expand Up @@ -98,21 +98,21 @@ def equations_to_amr(

@app.post("/code_to_amr")
def code_to_amr(
artifact_id: str, name: Optional[str] = None, description: Optional[str] = None, redis=Depends(get_redis)
code_id: str, name: Optional[str] = None, description: Optional[str] = None, redis=Depends(get_redis)
) -> ExtractionJob:
"""
Converts a code artifact to an AMR. Assumes that the code file is the first
file (and only) attached to the artifact.
Converts a code object to an AMR. Assumes that the code file is the first
file (and only) attached to the code.
Args:
```
artifact_id (str): the id of the code artifact
code_id (str): the id of the code
name (str, optional): the name to set on the newly created model
description (str, optional): the description to set on the newly created model
```
"""
operation_name = "operations.code_to_amr"
options = {"artifact_id": artifact_id, "name": name, "description": description}
options = {"code_id": code_id, "name": name, "description": description}

resp = create_job(operation_name=operation_name, options=options, redis=redis)

Expand Down
2 changes: 1 addition & 1 deletion api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

# REDIS CONNECTION AND QUEUE OBJECTS
def get_redis():
redis = Redis(
return Redis(
settings.REDIS_HOST,
settings.REDIS_PORT,
)
Expand Down
20 changes: 10 additions & 10 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ function "check_suffix" {
# ----------------------------------------------------------------------------------------------------------------------

group "prod" {
targets = ["ta1-service-api", "ta1-service-worker"]
targets = ["knowledge-middleware-api", "knowledge-middleware-worker"]
}

group "default" {
targets = ["ta1-service-api-base", "ta1-service-worker-base"]
targets = ["knowledge-middleware-api-base", "knowledge-middleware-worker-base"]
}

# ----------------------------------------------------------------------------------------------------------------------
Expand All @@ -41,22 +41,22 @@ target "_platforms" {
platforms = ["linux/amd64", "linux/arm64"]
}

target "ta1-service-api-base" {
target "knowledge-middleware-api-base" {
context = "."
tags = tag("ta1-service-api", "", "")
tags = tag("knowledge-middleware-api", "", "")
dockerfile = "api/Dockerfile"
}

target "ta1-service-worker-base" {
target "knowledge-middleware-worker-base" {
context = "."
tags = tag("ta1-service-worker", "", "")
tags = tag("knowledge-middleware-worker", "", "")
dockerfile = "worker/Dockerfile"
}

target "ta1-service-api" {
inherits = ["_platforms", "ta1-service-api-base"]
target "knowledge-middleware-api" {
inherits = ["_platforms", "knowledge-middleware-api-base"]
}

target "ta1-service-worker" {
inherits = ["_platforms", "ta1-service-worker-base"]
target "knowledge-middleware-worker" {
inherits = ["_platforms", "knowledge-middleware-worker-base"]
}
16 changes: 8 additions & 8 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
version: "3.9"
networks:
ta1-service:
knowledge-middleware:
driver: bridge
name: ta1-service
name: knowledge-middleware
services:
api:
container_name: api-ta1-service
container_name: api-knowledge-middleware
build:
context: ./
dockerfile: api/Dockerfile
Expand All @@ -15,22 +15,22 @@ services:
env_file:
- .env
networks:
- ta1-service
- knowledge-middleware
depends_on:
- redis
volumes:
- $PWD/api:/api
extra_hosts:
- "host.docker.internal:host-gateway"
redis:
container_name: redis-ta1-service
container_name: redis-knowledge-middleware
image: redis
ports:
- "6379:6379"
networks:
- ta1-service
- knowledge-middleware
rqworker:
container_name: worker-ta1-service
container_name: worker-knowledge-middleware
build:
context: ./
dockerfile: worker/Dockerfile
Expand All @@ -39,4 +39,4 @@ services:
depends_on:
- redis
networks:
- ta1-service
- knowledge-middleware
30 changes: 15 additions & 15 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
version: "3.9"
networks:
ta1-service:
knowledge-middleware:
driver: bridge
name: ta1-service
name: knowledge-middleware
data-api:
external: true
services:
extraction-api:
container_name: api-ta1-service
container_name: api-knowledge-middleware
build:
context: ./
dockerfile: api/Dockerfile
Expand All @@ -17,7 +17,7 @@ services:
env_file:
- .env
networks:
- ta1-service
- knowledge-middleware
- data-api
depends_on:
- redis
Expand All @@ -26,14 +26,14 @@ services:
extra_hosts:
- "host.docker.internal:host-gateway"
redis:
container_name: redis-ta1-service
container_name: redis-knowledge-middleware
image: redis
ports:
- "6379:6379"
networks:
- ta1-service
- knowledge-middleware
rqworker:
container_name: worker-ta1-service
container_name: worker-knowledge-middleware
build:
context: ./
dockerfile: worker/Dockerfile
Expand All @@ -42,26 +42,26 @@ services:
depends_on:
- redis
networks:
- ta1-service
- knowledge-middleware
- data-api
mit-tr:
extends:
file: ./askem-ta1-dockervm/end-to-end-rest/docker-compose.yml
service: mit-tr
networks:
- ta1-service
- knowledge-middleware
skema-tr:
extends:
file: ./askem-ta1-dockervm/end-to-end-rest/docker-compose.yml
service: skema-tr
networks:
- ta1-service
- knowledge-middleware
skema-py:
extends:
file: ./askem-ta1-dockervm/end-to-end-rest/docker-compose.yml
service: skema-py
networks:
- ta1-service
- knowledge-middleware
skema-unified:
extends:
file: ./askem-ta1-dockervm/end-to-end-rest/docker-compose.yml
Expand All @@ -71,25 +71,25 @@ services:
file: ./askem-ta1-dockervm/end-to-end-rest/docker-compose.yml
service: skema-rs
networks:
- ta1-service
- knowledge-middleware
graphdb:
extends:
file: ./askem-ta1-dockervm/end-to-end-rest/docker-compose.yml
service: graphdb
networks:
- ta1-service
- knowledge-middleware
eq2mml:
extends:
file: ./askem-ta1-dockervm/end-to-end-rest/docker-compose.yml
service: eq2mml
networks:
- ta1-service
- knowledge-middleware
mathjax:
extends:
file: ./askem-ta1-dockervm/end-to-end-rest/docker-compose.yml
service: mathjax
networks:
- ta1-service
- knowledge-middleware

volumes:
mg_lib:
Expand Down
3 changes: 2 additions & 1 deletion env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ TDS_URL=http://data-service.staging.terarium.ai
SKEMA_RS_URL=http://skema-rs.staging.terarium.ai
TA1_UNIFIED_URL=http://skema-unified.staging.terarium.ai
MIT_TR_URL=http://mit-tr.staging.terarium.ai
LOG_LEVEL=INFO
LOG_LEVEL=INFO
MOCK_TA1=True
7 changes: 3 additions & 4 deletions lib/settings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pydantic_settings import BaseSettings

class Settings(BaseSettings):
LIVE: bool = False
REDIS_HOST: str = "redis.ta1-service"
MOCK_TA1: bool = True
REDIS_HOST: str = "redis.knowledge-middleware"
REDIS_PORT: int = 6379
TA1_UNIFIED_URL: str = "http://ta1:5"
SKEMA_RS_URL: str = "http://skema-rs.staging.terarium.ai"
Expand All @@ -11,5 +11,4 @@ class Settings(BaseSettings):
OPENAI_API_KEY: str = "foo"
LOG_LEVEL: str = "INFO"


settings = Settings()
settings = Settings()
Loading

0 comments on commit f38285b

Please sign in to comment.