Skip to content

Commit

Permalink
Add logging and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
TheByronHimes committed Feb 7, 2024
1 parent e079dbc commit 2792809
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 28 deletions.
47 changes: 35 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,46 +83,69 @@ wps --help
### Parameters

The service requires the following configuration parameters:
- **`datasets_collection`** *(string)*: The name of the database collection for datasets. Default: `"datasets"`.

- **`work_packages_collection`** *(string)*: The name of the database collection for work packages. Default: `"workPackages"`.
- **`log_level`** *(string)*: The minimum log level to capture. Must be one of: `["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE"]`. Default: `"INFO"`.

- **`work_package_valid_days`** *(integer)*: How many days a work package (and its access token) stays valid. Default: `30`.
- **`service_name`** *(string)*: Default: `"wps"`.

- **`work_package_signing_key`** *(string, format: password)*: The private key for signing work order tokens.
- **`service_instance_id`** *(string)*: A string that uniquely identifies this instance across all instances of this service. A globally unique Kafka client ID will be created by concatenating the service_name and the service_instance_id.


Examples:

```json
"{\"crv\": \"P-256\", \"kty\": \"EC\", \"x\": \"...\", \"y\": \"...\"}"
"germany-bw-instance-001"
```


- **`db_connection_str`** *(string, format: password)*: MongoDB connection string. Might include credentials. For more information see: https://naiveskill.com/mongodb-connection-string/.
- **`log_format`**: If set, will replace JSON formatting with the specified string format. If not set, has no effect. In addition to the standard attributes, the following can also be specified: timestamp, service, instance, level, correlation_id, and details. Default: `null`.

- **Any of**

- *string*

- *null*


Examples:

```json
"mongodb://localhost:27017"
"%(timestamp)s - %(service)s - %(level)s - %(message)s"
```


- **`db_name`** *(string)*: Default: `"work-packages"`.
```json
"%(asctime)s - Severity: %(levelno)s - %(msg)s"
```

- **`service_name`** *(string)*: Default: `"wps"`.

- **`service_instance_id`** *(string)*: A string that uniquely identifies this instance across all instances of this service. A globally unique Kafka client ID will be created by concatenating the service_name and the service_instance_id.
- **`datasets_collection`** *(string)*: The name of the database collection for datasets. Default: `"datasets"`.

- **`work_packages_collection`** *(string)*: The name of the database collection for work packages. Default: `"workPackages"`.

- **`work_package_valid_days`** *(integer)*: How many days a work package (and its access token) stays valid. Default: `30`.

- **`work_package_signing_key`** *(string, format: password)*: The private key for signing work order tokens.


Examples:

```json
"germany-bw-instance-001"
"{\"crv\": \"P-256\", \"kty\": \"EC\", \"x\": \"...\", \"y\": \"...\"}"
```


- **`db_connection_str`** *(string, format: password)*: MongoDB connection string. Might include credentials. For more information see: https://naiveskill.com/mongodb-connection-string/.


Examples:

```json
"mongodb://localhost:27017"
```


- **`db_name`** *(string)*: Default: `"work-packages"`.

- **`kafka_servers`** *(array)*: A list of connection strings to connect to Kafka bootstrap servers.

- **Items** *(string)*
Expand Down
59 changes: 45 additions & 14 deletions config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,50 @@
"additionalProperties": false,
"description": "Modifies the orginal Settings class provided by the user",
"properties": {
"log_level": {
"default": "INFO",
"description": "The minimum log level to capture.",
"enum": [
"CRITICAL",
"ERROR",
"WARNING",
"INFO",
"DEBUG",
"TRACE"
],
"title": "Log Level",
"type": "string"
},
"service_name": {
"default": "wps",
"title": "Service Name",
"type": "string"
},
"service_instance_id": {
"description": "A string that uniquely identifies this instance across all instances of this service. A globally unique Kafka client ID will be created by concatenating the service_name and the service_instance_id.",
"examples": [
"germany-bw-instance-001"
],
"title": "Service Instance Id",
"type": "string"
},
"log_format": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "If set, will replace JSON formatting with the specified string format. If not set, has no effect. In addition to the standard attributes, the following can also be specified: timestamp, service, instance, level, correlation_id, and details",
"examples": [
"%(timestamp)s - %(service)s - %(level)s - %(message)s",
"%(asctime)s - Severity: %(levelno)s - %(msg)s"
],
"title": "Log Format"
},
"datasets_collection": {
"default": "datasets",
"description": "The name of the database collection for datasets",
Expand Down Expand Up @@ -45,19 +89,6 @@
"title": "Db Name",
"type": "string"
},
"service_name": {
"default": "wps",
"title": "Service Name",
"type": "string"
},
"service_instance_id": {
"description": "A string that uniquely identifies this instance across all instances of this service. A globally unique Kafka client ID will be created by concatenating the service_name and the service_instance_id.",
"examples": [
"germany-bw-instance-001"
],
"title": "Service Instance Id",
"type": "string"
},
"kafka_servers": {
"description": "A list of connection strings to connect to Kafka bootstrap servers.",
"examples": [
Expand Down Expand Up @@ -311,9 +342,9 @@
}
},
"required": [
"service_instance_id",
"work_package_signing_key",
"db_connection_str",
"service_instance_id",
"kafka_servers",
"dataset_change_event_topic",
"dataset_upsertion_event_type",
Expand Down
2 changes: 2 additions & 0 deletions example_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ kafka_ssl_cafile: ''
kafka_ssl_certfile: ''
kafka_ssl_keyfile: ''
kafka_ssl_password: ''
log_format: null
log_level: INFO
openapi_url: /openapi.json
port: 8080
service_instance_id: wps_1
Expand Down
8 changes: 6 additions & 2 deletions src/wps/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
from ghga_service_commons.api import ApiConfigBase
from ghga_service_commons.auth.ghga import AuthConfig
from hexkit.config import config_from_yaml
from hexkit.log import LoggingConfig
from hexkit.providers.akafka import KafkaConfig
from hexkit.providers.mongodb import MongoDbConfig

from wps.adapters.inbound.event_sub import EventSubTranslatorConfig
from wps.adapters.outbound.http import AccessCheckConfig
from wps.core.repository import WorkPackageConfig

SERVICE_NAME = "wps"

@config_from_yaml(prefix="wps")

@config_from_yaml(prefix=SERVICE_NAME)
class Config(
ApiConfigBase,
AuthConfig,
Expand All @@ -35,8 +38,9 @@ class Config(
KafkaConfig,
MongoDbConfig,
WorkPackageConfig,
LoggingConfig,
):
"""Config parameters and their defaults."""

service_name: str = "wps"
service_name: str = SERVICE_NAME
db_name: str = "work-packages"
3 changes: 3 additions & 0 deletions src/wps/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""In this module object construction and dependency injection is carried out."""

from ghga_service_commons.api import run_server
from hexkit.log import configure_logging

from wps.config import Config
from wps.inject import prepare_consumer, prepare_rest_app
Expand All @@ -24,6 +25,7 @@
async def run_rest_app() -> None:
"""Run the HTTP REST API."""
config = Config() # type: ignore
configure_logging(config=config)

async with prepare_rest_app(config=config) as app:
await run_server(app=app, config=config)
Expand All @@ -32,6 +34,7 @@ async def run_rest_app() -> None:
async def consume_events(run_forever: bool = True) -> None:
"""Run an event consumer listening to the configured topic."""
config = Config() # type: ignore
configure_logging(config=config)

async with prepare_consumer(config=config) as consumer:
await consumer.event_subscriber.run(forever=run_forever)

0 comments on commit 2792809

Please sign in to comment.