Skip to content

Rationale

Should contain all the required glue to make a service properly work with our infrastructure

How to share common code across services How to maintain it ?

What we need

Both woosauthenticator and counter_decorator needs to be changed to interact with application configuration.

What's done

Woosauthenticator needs authentication service and redis. Counterdecorator needs to get the metrics redis.

woosauthenticator and counter_decorator dependencies

graph TD
    woosauthenticator --> authentication_service
    woosauthenticator --> authentication_cache
    counter_decorator --> metrics_queue

To use the authenticator you need:

  • AUTHENTICATION_URL
  • AUTHENTICATION_CACHE_REDIS_URL

To use the counter_decorator you need: - COUNTER_REDIS_URL

Make it work with bender

woosauthenticator

You need to declare two extra dependencies in the application.json manifest:

  • One on for authentication service.
  • One on for authentication cache redis database.
{
  "dependencies": {
    "services": [{"name": "authentication", "test_value":  "http://localhost:34555"}],
    "databases": [{"name":  "authentication_cache", "type": "redis"}]
  }
}

counter_decorator

You would need a single dependency:

{
  "dependencies": {
  "databases": [
      {
        "name": "metrics_queue",
        "extras": {
          "queue_prefix": "counter"
        }
      }
    ]
  }
}

Implementation

We can make both of the libaries depend on django.conf.settings to fetch their configuration and handle their own clients.

But due to recent events regarding redis 15 minutes timeout it would be nice to be able to override the default clients parameters without having to make changes to every application known to man.

We can keep track of the needed clients (Http, redis) and deliver that workflow part of a library:

Example implementation of a get_redis_client.

from redis import Redis
from application_kit.settings import get_redis_instance
from bender.shared.manifest.url import BenderDbUrl


def get_redis_client(name) -> Redis:
    db_url : BenderDbUrl= get_redis_instance(name)
    parameters = db_url.get_parameters()
    del parameters['queue_prefix']

    redis_args = {
        "host": db_url.host,
        "db": db_url.database,
        "port": db_url.port,
        **parameters
    }
    return Redis(**redis_args)

Helper function example

from application_kit.settings import get_redis_instance
def something_needing_authentication_cache():
    client = get_redis_instance('authentication_cache')
    ...

The woosmap application_kit could provide both low level functions such as get_redis_client but also integrate the decorator and utility functions provided by counter_decorator and authenticator.

Application kit dependencies

graph TD
    application_kit --> authenticator
    application_kit --> metrics

    authenticator --> authentication_service
    authenticator --> authentication_cache
    metrics --> metrics_queue

Authentication should depend on application_kit, and we should add pydantic models for tokens inside it instead of manipulating raw jsons..

Application Kit startup

Optional Dependencies:

  • authentication_cache : authenticator should not try to cache when authentication_cache not fulfilled.
  • metrics_queue : metrics reporting should be disabled when metrics_queue is not fulfilled or whaaaaat ?.

The application manifest cannot be loaded at startup otherwise it's impossible to properly test application_kit.