Skip to content

Commit

Permalink
module: move src/schema_registry to src/karapace/api
Browse files Browse the repository at this point in the history
  • Loading branch information
nosahama committed Jan 24, 2025
1 parent 6fe0cf4 commit 69d4c87
Show file tree
Hide file tree
Showing 67 changed files with 246 additions and 247 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# Include source directories and files required for building.
!go
!src/karapace
!src/schema_registry
!requirements/*.txt
!README.rst
!LICENSE
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
RUNNER_UID: ${{ env.RUNNER_UID }}
RUNNER_GID: ${{ env.RUNNER_GID }}
COVERAGE_FILE: "/opt/karapace/coverage/.coverage.${{ matrix.python-version }}"
PYTEST_ARGS: "--cov=karapace --cov=schema_registry --cov-append --numprocesses 4"
PYTEST_ARGS: "--cov=karapace --cov-append --numprocesses 4"

- run: make e2e-tests-in-docker
env:
Expand All @@ -85,7 +85,7 @@ jobs:
RUNNER_UID: ${{ env.RUNNER_UID }}
RUNNER_GID: ${{ env.RUNNER_GID }}
COVERAGE_FILE: "/opt/karapace/coverage/.coverage.${{ matrix.python-version }}"
PYTEST_ARGS: "--cov=karapace --cov=schema_registry --cov-append --numprocesses 4"
PYTEST_ARGS: "--cov=karapace --cov-append --numprocesses 4"

- run: make integration-tests-in-docker
env:
Expand All @@ -94,7 +94,7 @@ jobs:
RUNNER_UID: ${{ env.RUNNER_UID }}
RUNNER_GID: ${{ env.RUNNER_GID }}
COVERAGE_FILE: "/opt/karapace/coverage/.coverage.${{ matrix.python-version }}"
PYTEST_ARGS: "--cov=karapace --cov=schema_registry --cov-append --random-order --numprocesses 4"
PYTEST_ARGS: "--cov=karapace --cov-append --random-order --numprocesses 4"

- name: Archive logs
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ src/karapace.egg-info/
/kafka_*/
venv
*.so
src/karapace/core/version.py
src/karapace/version.py
.run
.python-version
.hypothesis/
Expand Down
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ integration-tests-in-docker: start-karapace-docker-resources

.PHONY: type-check-mypy-in-docker
type-check-mypy-in-docker: start-karapace-docker-resources
$(KARAPACE-CLI) $(PYTHON) -m mypy src
$(KARAPACE-CLI) $(PYTHON) -m mypy src/karapace

.PHONY: cli
cli: start-karapace-docker-resources
Expand Down
2 changes: 1 addition & 1 deletion container/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ services:
entrypoint:
- python3
- -m
- schema_registry
- karapace.api
depends_on:
- kafka
- opentelemetry-collector
Expand Down
4 changes: 2 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[mypy]
mypy_path = $MYPY_CONFIG_FILE_DIR/stubs
python_version = 3.10
packages = karapace,schema_registry
packages = karapace
show_error_codes = True
pretty = True
warn_redundant_casts = True
Expand All @@ -15,7 +15,7 @@ warn_no_return = True
warn_unreachable = True
strict_equality = True

[mypy-schema_registry.controller]
[mypy-karapace.api.controller]
ignore_errors = True

[mypy-karapace.core.compatibility.jsonschema.checks]
Expand Down
Empty file added src/karapace/__init__.py
Empty file.
File renamed without changes.
68 changes: 68 additions & 0 deletions src/karapace/api/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Copyright (c) 2024 Aiven Ltd
See LICENSE for details
"""

from karapace.core.container import KarapaceContainer
from karapace.api.container import SchemaRegistryContainer
from karapace.api.factory import create_karapace_application, karapace_schema_registry_lifespan
from karapace.api.telemetry.container import TelemetryContainer

import karapace.api.controller
import karapace.api.factory
import karapace.api.routers.compatibility
import karapace.api.routers.config
import karapace.api.routers.health
import karapace.api.routers.master_availability
import karapace.api.routers.metrics
import karapace.api.routers.mode
import karapace.api.routers.schemas
import karapace.api.routers.subjects
import karapace.api.telemetry.meter
import karapace.api.telemetry.middleware
import karapace.api.telemetry.setup
import karapace.api.telemetry.tracer
import karapace.api.user
import uvicorn

if __name__ == "__main__":
karapace_container = KarapaceContainer()
karapace_container.wire(
modules=[
__name__,
karapace.api.controller,
karapace.api.telemetry.tracer,
karapace.api.telemetry.meter,
]
)

telemetry_container = TelemetryContainer(karapace_container=karapace_container)
telemetry_container.wire(
modules=[
karapace.api.telemetry.setup,
karapace.api.telemetry.middleware,
]
)

schema_registry_container = SchemaRegistryContainer(
karapace_container=karapace_container, telemetry_container=telemetry_container
)
schema_registry_container.wire(
modules=[
__name__,
karapace.api.factory,
karapace.api.user,
karapace.api.routers.health,
karapace.api.routers.metrics,
karapace.api.routers.subjects,
karapace.api.routers.schemas,
karapace.api.routers.config,
karapace.api.routers.compatibility,
karapace.api.routers.mode,
karapace.api.routers.master_availability,
]
)

config = karapace_container.config()
app = create_karapace_application(config=config, lifespan=karapace_schema_registry_lifespan)
uvicorn.run(app, host=config.host, port=config.port, log_level=config.log_level.lower(), log_config=None)
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from dependency_injector import containers, providers
from karapace.core.container import KarapaceContainer
from schema_registry.controller import KarapaceSchemaRegistryController
from schema_registry.registry import KarapaceSchemaRegistry
from schema_registry.telemetry.container import TelemetryContainer
from karapace.api.controller import KarapaceSchemaRegistryController
from karapace.api.registry import KarapaceSchemaRegistry
from karapace.api.telemetry.container import TelemetryContainer


class SchemaRegistryContainer(containers.DeclarativeContainer):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
from karapace.core.statsd import StatsClient
from karapace.core.typing import JsonData, JsonObject, SchemaId, Subject, Version
from karapace.core.utils import JSONDecodeError
from schema_registry.registry import KarapaceSchemaRegistry
from schema_registry.routers.errors import no_primary_url_error, SchemaErrorCodes, SchemaErrorMessages
from schema_registry.routers.requests import (
from karapace.api.registry import KarapaceSchemaRegistry
from karapace.api.routers.errors import no_primary_url_error, SchemaErrorCodes, SchemaErrorMessages
from karapace.api.routers.requests import (
CompatibilityCheckResponse,
CompatibilityLevelResponse,
CompatibilityRequest,
Expand Down
12 changes: 6 additions & 6 deletions src/schema_registry/factory.py → src/karapace/api/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
from karapace.core.forward_client import ForwardClient
from karapace.core.logging_setup import configure_logging, log_config_without_secrets
from karapace.core.statsd import StatsClient
from schema_registry.container import SchemaRegistryContainer
from schema_registry.http_handlers import setup_exception_handlers
from schema_registry.middlewares import setup_middlewares
from schema_registry.registry import KarapaceSchemaRegistry
from schema_registry.routers.setup import setup_routers
from schema_registry.telemetry.setup import setup_metering, setup_tracing
from karapace.api.container import SchemaRegistryContainer
from karapace.api.http_handlers import setup_exception_handlers
from karapace.api.middlewares import setup_middlewares
from karapace.api.registry import KarapaceSchemaRegistry
from karapace.api.routers.setup import setup_routers
from karapace.api.telemetry.setup import setup_metering, setup_tracing
from typing import AsyncContextManager

import logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse
from http import HTTPStatus
from schema_registry.routers.errors import KarapaceValidationError
from karapace.api.routers.errors import KarapaceValidationError
from starlette.exceptions import HTTPException as StarletteHTTPException
from starlette.requests import Request as StarletteHTTPRequest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from karapace.core.key_format import KeyFormatter
from karapace.core.offset_watcher import OffsetWatcher
from karapace.core.utils import json_encode
from karapace.core.version import __version__
from karapace.version import __version__
from typing import Any, Final

import logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from fastapi import FastAPI, HTTPException, Request, Response
from fastapi.responses import JSONResponse
from karapace.core.content_type import check_schema_headers
from schema_registry.telemetry.middleware import setup_telemetry_middleware
from karapace.api.telemetry.middleware import setup_telemetry_middleware


def setup_middlewares(app: FastAPI) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from karapace.core.statsd import StatsClient
from karapace.core.typing import JsonObject, SchemaReaderStoppper, Subject, Version
from karapace.core.utils import json_decode, JSONDecodeError, shutdown
from schema_registry.telemetry.tracer import Tracer
from karapace.api.telemetry.tracer import Tracer
from threading import Event, Lock, Thread
from typing import Final

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
)
from karapace.core.schema_references import LatestVersionReference, Reference
from karapace.core.typing import JsonObject, Mode, PrimaryInfo, SchemaId, Subject, Version
from schema_registry.messaging import KarapaceProducer
from schema_registry.reader import KafkaSchemaReader
from schema_registry.telemetry.tracer import Tracer
from karapace.api.messaging import KarapaceProducer
from karapace.api.reader import KafkaSchemaReader
from karapace.api.telemetry.tracer import Tracer

import asyncio
import logging
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from fastapi import APIRouter, Depends
from karapace.core.auth import AuthenticatorAndAuthorizer, Operation, User
from karapace.core.typing import Subject
from schema_registry.container import SchemaRegistryContainer
from schema_registry.controller import KarapaceSchemaRegistryController
from schema_registry.routers.errors import unauthorized
from schema_registry.routers.raw_path_router import RawPathRoute
from schema_registry.routers.requests import CompatibilityCheckResponse, SchemaRequest
from schema_registry.user import get_current_user
from karapace.api.container import SchemaRegistryContainer
from karapace.api.controller import KarapaceSchemaRegistryController
from karapace.api.routers.errors import unauthorized
from karapace.api.routers.raw_path_router import RawPathRoute
from karapace.api.routers.requests import CompatibilityCheckResponse, SchemaRequest
from karapace.api.user import get_current_user
from typing import Annotated
from urllib.parse import unquote_plus

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from karapace.core.auth import AuthenticatorAndAuthorizer, Operation, User
from karapace.core.forward_client import ForwardClient
from karapace.core.typing import Subject
from schema_registry.container import SchemaRegistryContainer
from schema_registry.controller import KarapaceSchemaRegistryController
from schema_registry.registry import KarapaceSchemaRegistry
from schema_registry.routers.errors import no_primary_url_error, unauthorized
from schema_registry.routers.raw_path_router import RawPathRoute
from schema_registry.routers.requests import CompatibilityLevelResponse, CompatibilityRequest, CompatibilityResponse
from schema_registry.user import get_current_user
from karapace.api.container import SchemaRegistryContainer
from karapace.api.controller import KarapaceSchemaRegistryController
from karapace.api.registry import KarapaceSchemaRegistry
from karapace.api.routers.errors import no_primary_url_error, unauthorized
from karapace.api.routers.raw_path_router import RawPathRoute
from karapace.api.routers.requests import CompatibilityLevelResponse, CompatibilityRequest, CompatibilityResponse
from karapace.api.user import get_current_user
from typing import Annotated
from urllib.parse import unquote_plus

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from opentelemetry.trace import Span
from opentelemetry.trace.status import StatusCode
from pydantic import BaseModel
from schema_registry.container import SchemaRegistryContainer
from schema_registry.registry import KarapaceSchemaRegistry
from schema_registry.telemetry.tracer import Tracer
from karapace.api.container import SchemaRegistryContainer
from karapace.api.registry import KarapaceSchemaRegistry
from karapace.api.telemetry.tracer import Tracer


class HealthStatus(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from karapace.core.config import Config
from karapace.core.forward_client import ForwardClient
from pydantic import BaseModel
from schema_registry.container import SchemaRegistryContainer
from schema_registry.registry import KarapaceSchemaRegistry
from karapace.api.container import SchemaRegistryContainer
from karapace.api.registry import KarapaceSchemaRegistry
from typing import Final

import logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dependency_injector.wiring import inject, Provide
from fastapi import APIRouter, Depends, Response
from karapace.core.instrumentation.prometheus import PrometheusInstrumentation
from schema_registry.container import SchemaRegistryContainer
from karapace.api.container import SchemaRegistryContainer

metrics_router = APIRouter(
prefix=PrometheusInstrumentation.METRICS_ENDPOINT_PATH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from fastapi import APIRouter, Depends
from karapace.core.auth import AuthenticatorAndAuthorizer, Operation, User
from karapace.core.typing import Subject
from schema_registry.container import SchemaRegistryContainer
from schema_registry.controller import KarapaceSchemaRegistryController
from schema_registry.routers.errors import unauthorized
from schema_registry.routers.raw_path_router import RawPathRoute
from schema_registry.routers.requests import ModeResponse
from schema_registry.user import get_current_user
from karapace.api.container import SchemaRegistryContainer
from karapace.api.controller import KarapaceSchemaRegistryController
from karapace.api.routers.errors import unauthorized
from karapace.api.routers.raw_path_router import RawPathRoute
from karapace.api.routers.requests import ModeResponse
from karapace.api.user import get_current_user
from typing import Annotated
from urllib.parse import unquote_plus

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from karapace.core.schema_type import SchemaType
from karapace.core.typing import Subject
from pydantic import BaseModel, ConfigDict, Field, field_validator
from schema_registry.routers.errors import KarapaceValidationError
from karapace.api.routers.errors import KarapaceValidationError
from typing import Any


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from dependency_injector.wiring import inject, Provide
from fastapi import APIRouter, Depends, Query
from karapace.core.auth import AuthenticatorAndAuthorizer, User
from schema_registry.container import SchemaRegistryContainer
from schema_registry.controller import KarapaceSchemaRegistryController
from schema_registry.routers.requests import SchemaListingItem, SchemasResponse, SubjectVersion
from schema_registry.user import get_current_user
from karapace.api.container import SchemaRegistryContainer
from karapace.api.controller import KarapaceSchemaRegistryController
from karapace.api.routers.requests import SchemaListingItem, SchemasResponse, SubjectVersion
from karapace.api.user import get_current_user
from typing import Annotated

schemas_router = APIRouter(
Expand Down
27 changes: 27 additions & 0 deletions src/karapace/api/routers/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Copyright (c) 2024 Aiven Ltd
See LICENSE for details
"""

from fastapi import FastAPI
from karapace.api.routers.compatibility import compatibility_router
from karapace.api.routers.config import config_router
from karapace.api.routers.health import health_router
from karapace.api.routers.master_availability import master_availability_router
from karapace.api.routers.metrics import metrics_router
from karapace.api.routers.mode import mode_router
from karapace.api.routers.root import root_router
from karapace.api.routers.schemas import schemas_router
from karapace.api.routers.subjects import subjects_router


def setup_routers(app: FastAPI) -> None:
app.include_router(compatibility_router)
app.include_router(config_router)
app.include_router(health_router)
app.include_router(mode_router)
app.include_router(root_router)
app.include_router(schemas_router)
app.include_router(subjects_router)
app.include_router(metrics_router)
app.include_router(master_availability_router)
Loading

0 comments on commit 69d4c87

Please sign in to comment.