Skip to content

Commit

Permalink
Bump ns version to 3.0.0 and use hexkit v4 (GSI-1340) (#21)
Browse files Browse the repository at this point in the history
* Bump ns version to 3.0.0 and use hexkit v4

* Ruff formatting
  • Loading branch information
TheByronHimes authored Feb 11, 2025
1 parent 7d4ab9b commit 3a86e36
Show file tree
Hide file tree
Showing 15 changed files with 1,264 additions and 1,069 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/.dev_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ smtp_auth:
password: test
from_address: "[email protected]"
use_starttls: false
db_connection_str: "mongodb://mongodb:27017"
mongo_dsn: "mongodb://mongodb:27017"
db_name: "dev_db"
5 changes: 3 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"visualstudioexptteam.vscodeintellicode",
"ymotongpoo.licenser",
"charliermarsh.ruff",
"ms-python.mypy-type-checker"
"ms-python.mypy-type-checker",
"-ms-python.autopep8"
]
}
},
Expand All @@ -71,4 +72,4 @@
// details can be found here: https://github.com/devcontainers/features/tree/main/src/docker-outside-of-docker
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
}
}
}
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ repos:
- id: no-commit-to-branch
args: [--branch, dev, --branch, int, --branch, main]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.4
rev: v0.9.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
rev: v1.15.0
hooks:
- id: mypy
args: [--no-warn-unused-ignores]
6 changes: 3 additions & 3 deletions .pyproject_generation/pyproject_custom.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[project]
name = "ns"
version = "2.1.0"
version = "3.0.0"
description = "The Notification Service (NS) handles notification kafka events."
dependencies = [
"typer>=0.12",
"ghga-event-schemas>=3.0.0, <4",
"ghga-service-commons>=3.0.0",
"hexkit[akafka,mongodb]>=3.0.0",
"ghga-service-commons>=3.3",
"hexkit[akafka,mongodb]>=4",
]

[project.urls]
Expand Down
2 changes: 2 additions & 0 deletions .pyproject_generation/pyproject_template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fixable = [
"UP", # e.g. List -> list
"I", # sort imports
"D", # pydocstyle
"RUF022", # sort items in __all__
]
ignore = [
"E111", # indentation with invalid multiple (for formatter)
Expand All @@ -59,6 +60,7 @@ ignore = [
"D206", # indent-with-spaces (for formatter)
"D300", # triple-single-quotes (for formatter)
"UP040", # type statement (not yet supported by mypy)
"PLC0206", # Extracting value from dictionary without calling `.items()`
]
select = [
"C90", # McCabe Complexity
Expand Down
119 changes: 115 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ We recommend using the provided Docker container.

A pre-build version is available at [docker hub](https://hub.docker.com/repository/docker/ghga/notification-service):
```bash
docker pull ghga/notification-service:2.1.0
docker pull ghga/notification-service:3.0.0
```

Or you can build the container yourself from the [`./Dockerfile`](./Dockerfile):
```bash
# Execute in the repo's root dir:
docker build -t ghga/notification-service:2.1.0 .
docker build -t ghga/notification-service:3.0.0 .
```

For production-ready deployment, we recommend using Kubernetes, however,
for simple use cases, you could execute the service using docker
on a single server:
```bash
# The entrypoint is preconfigured:
docker run -p 8080:8080 ghga/notification-service:2.1.0 --help
docker run -p 8080:8080 ghga/notification-service:3.0.0 --help
```

If you prefer not to use containers, you may install the service from source:
Expand All @@ -64,7 +64,7 @@ ns --help
### Parameters

The service requires the following configuration parameters:
- **`db_connection_str`** *(string, format: password, required)*: MongoDB connection string. Might include credentials. For more information see: https://naiveskill.com/mongodb-connection-string/.
- **`mongo_dsn`** *(string, format: multi-host-uri, required)*: MongoDB connection string. Might include credentials. For more information see: https://naiveskill.com/mongodb-connection-string/.


Examples:
Expand All @@ -84,6 +84,32 @@ The service requires the following configuration parameters:
```


- **`mongo_timeout`**: Timeout in seconds for API calls to MongoDB. The timeout applies to all steps needed to complete the operation, including server selection, connection checkout, serialization, and server-side execution. When the timeout expires, PyMongo raises a timeout exception. If set to None, the operation will not time out (default MongoDB behavior). Default: `null`.

- **Any of**

- *integer*: Exclusive minimum: `0`.

- *null*


Examples:

```json
300
```


```json
600
```


```json
null
```


- **`log_level`** *(string)*: The minimum log level to capture. Must be one of: `["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE"]`. Default: `"INFO"`.

- **`service_name`** *(string)*: Default: `"ns"`.
Expand Down Expand Up @@ -223,6 +249,91 @@ The service requires the following configuration parameters:
```


- **`kafka_max_retries`** *(integer)*: The maximum number of times to immediately retry consuming an event upon failure. Works independently of the dead letter queue. Minimum: `0`. Default: `0`.


Examples:

```json
0
```


```json
1
```


```json
2
```


```json
3
```


```json
5
```


- **`kafka_enable_dlq`** *(boolean)*: A flag to toggle the dead letter queue. If set to False, the service will crash upon exhausting retries instead of publishing events to the DLQ. If set to True, the service will publish events to the DLQ topic after exhausting all retries. Default: `false`.


Examples:

```json
true
```


```json
false
```


- **`kafka_dlq_topic`** *(string)*: The name of the topic used to resolve error-causing events. Default: `"dlq"`.


Examples:

```json
"dlq"
```


- **`kafka_retry_backoff`** *(integer)*: The number of seconds to wait before retrying a failed event. The backoff time is doubled for each retry attempt. Minimum: `0`. Default: `0`.


Examples:

```json
0
```


```json
1
```


```json
2
```


```json
3
```


```json
5
```


## Definitions


Expand Down
78 changes: 72 additions & 6 deletions config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
"additionalProperties": false,
"description": "Modifies the original Settings class provided by the user",
"properties": {
"db_connection_str": {
"mongo_dsn": {
"description": "MongoDB connection string. Might include credentials. For more information see: https://naiveskill.com/mongodb-connection-string/",
"examples": [
"mongodb://localhost:27017"
],
"format": "password",
"title": "Db Connection Str",
"type": "string",
"writeOnly": true
"format": "multi-host-uri",
"minLength": 1,
"title": "Mongo Dsn",
"type": "string"
},
"db_name": {
"description": "Name of the database located on the MongoDB server.",
Expand All @@ -45,6 +45,25 @@
"title": "Db Name",
"type": "string"
},
"mongo_timeout": {
"anyOf": [
{
"exclusiveMinimum": 0,
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"description": "Timeout in seconds for API calls to MongoDB. The timeout applies to all steps needed to complete the operation, including server selection, connection checkout, serialization, and server-side execution. When the timeout expires, PyMongo raises a timeout exception. If set to None, the operation will not time out (default MongoDB behavior).",
"examples": [
300,
600,
null
],
"title": "Mongo Timeout"
},
"log_level": {
"default": "INFO",
"description": "The minimum log level to capture.",
Expand Down Expand Up @@ -238,10 +257,57 @@
"exclusiveMinimum": 0,
"title": "Kafka Max Message Size",
"type": "integer"
},
"kafka_max_retries": {
"default": 0,
"description": "The maximum number of times to immediately retry consuming an event upon failure. Works independently of the dead letter queue.",
"examples": [
0,
1,
2,
3,
5
],
"minimum": 0,
"title": "Kafka Max Retries",
"type": "integer"
},
"kafka_enable_dlq": {
"default": false,
"description": "A flag to toggle the dead letter queue. If set to False, the service will crash upon exhausting retries instead of publishing events to the DLQ. If set to True, the service will publish events to the DLQ topic after exhausting all retries",
"examples": [
true,
false
],
"title": "Kafka Enable DLQ",
"type": "boolean"
},
"kafka_dlq_topic": {
"default": "dlq",
"description": "The name of the topic used to resolve error-causing events.",
"examples": [
"dlq"
],
"title": "Kafka DLQ Topic",
"type": "string"
},
"kafka_retry_backoff": {
"default": 0,
"description": "The number of seconds to wait before retrying a failed event. The backoff time is doubled for each retry attempt.",
"examples": [
0,
1,
2,
3,
5
],
"minimum": 0,
"title": "Kafka Retry Backoff",
"type": "integer"
}
},
"required": [
"db_connection_str",
"mongo_dsn",
"db_name",
"service_instance_id",
"plaintext_email_template",
Expand Down
7 changes: 6 additions & 1 deletion example_config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
db_connection_str: '**********'
db_name: dev_db
from_address: [email protected]
generate_correlation_id: true
html_email_template: '<!DOCTYPE html><html><head></head><body style="color: #00393f;padding:
12px;"><h2>Dear $recipient_name,</h2><p>$plaintext_body</p><p>Warm regards,</p><h3>The
GHGA Team</h3></body></html>'
kafka_dlq_topic: dlq
kafka_enable_dlq: false
kafka_max_message_size: 1048576
kafka_max_retries: 0
kafka_retry_backoff: 0
kafka_security_protocol: PLAINTEXT
kafka_servers:
- kafka:9092
Expand All @@ -16,6 +19,8 @@ kafka_ssl_password: ''
log_format: null
log_level: INFO
log_traceback: true
mongo_dsn: '**********'
mongo_timeout: null
notification_event_topic: notifications
notification_event_type: notification
plaintext_email_template: 'Dear $recipient_name,
Expand Down
Loading

0 comments on commit 3a86e36

Please sign in to comment.