Skip to content

Commit

Permalink
Merge pull request #6 from evo-company/rm-old-grpc-client
Browse files Browse the repository at this point in the history
rm grpc code, fix tests for http, update examples, docs
  • Loading branch information
n4mespace authored Feb 19, 2024
2 parents 92b75d9 + d50477b commit 72b8140
Show file tree
Hide file tree
Showing 39 changed files with 439 additions and 1,761 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ TODO:
- add docs, automate docs build
- add tests
- add `tracer` / `stats_collector` for http manager
- rm old grpc client
14 changes: 2 additions & 12 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
Examples
========

Here you can find examples for gRPC and HTTP clients with:
Here you can find examples for HTTP clients with:

- `aiohttp`
- `Sanic`
- `Flask`
- `WSGI`
- `httpx`
- `requests`

Prerequisites:

- sync + grpc:

> pip install featureflags-client[grpclib]
- async + grpc:

> pip install featureflags-client[grpcio]
- async + http:

> pip install featureflags-client[httpx]
Expand Down
4 changes: 0 additions & 4 deletions examples/grpc/config.py

This file was deleted.

8 changes: 0 additions & 8 deletions examples/grpc/flags.py

This file was deleted.

78 changes: 0 additions & 78 deletions examples/grpc/sanic_app.py

This file was deleted.

34 changes: 0 additions & 34 deletions examples/grpc/wsgi_app.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
import logging

import config
import flags
from aiohttp import web
from grpclib.client import Channel

from featureflags_client.grpc.client import FeatureFlagsClient
from featureflags_client.grpc.managers.asyncio import AsyncIOManager
from featureflags_client.http.client import FeatureFlagsClient
from featureflags_client.http.managers.dummy import AsyncDummyManager

log = logging.getLogger(__name__)


async def on_start(app):
app["ff_manager"] = AsyncIOManager(
app["config"].FF_PROJECT,
[flags.REQUEST_QUERY],
Channel(app["config"].FF_HOST, app["config"].FF_PORT),
# Dummy manager just uses Defaults values for flags, mainly for tests.
app["ff_manager"] = AsyncDummyManager(
url=config.FF_URL,
project=config.FF_PROJECT,
variables=[flags.REQUEST_QUERY],
defaults=flags.Defaults,
request_timeout=5,
refresh_interval=10,
)
app["ff_client"] = FeatureFlagsClient(flags.Defaults, app["ff_manager"])
app["ff_client"] = FeatureFlagsClient(app["ff_manager"])

try:
await app["ff_manager"].preload(timeout=5)
await app["ff_client"].preload_async()
except Exception:
log.exception(
"Unable to preload feature flags, application will "
"start working with defaults and retry later"
)

# Async managers need to `start` and `wait_closed` to be able to
# run flags update loop
app["ff_manager"].start()


async def on_stop(app):
app["ff_manager"].close()
await app["ff_manager"].wait_closed()


Expand All @@ -49,13 +56,13 @@ async def index(request):

def create_app():
app = web.Application(middlewares=[middleware])

app.router.add_get("/", index)
app.on_startup.append(on_start)
app.on_cleanup.append(on_stop)

import config

app["config"] = config

return app


Expand Down
18 changes: 12 additions & 6 deletions examples/grpc/flask_app.py → examples/http/dummy_sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@
import config
import flags
from flask import Flask, g, request
from grpc import insecure_channel
from werkzeug.local import LocalProxy

from featureflags_client.grpc.client import FeatureFlagsClient
from featureflags_client.grpc.managers.sync import SyncManager
from featureflags_client.http.client import FeatureFlagsClient
from featureflags_client.http.managers.dummy import DummyManager

app = Flask(__name__)


def get_ff_client():
ff_client = getattr(g, "_ff_client", None)
if ff_client is None:
channel = insecure_channel(f"{config.FF_HOST}:{config.FF_PORT}")
manager = SyncManager(config.FF_PROJECT, [flags.REQUEST_QUERY], channel)
ff_client = g._ff_client = FeatureFlagsClient(flags.Defaults, manager)
# Dummy manager just uses Defaults values for flags, mainly for tests.
manager = DummyManager(
url=config.FF_URL,
project=config.FF_PROJECT,
variables=[flags.REQUEST_QUERY],
defaults=flags.Defaults,
request_timeout=5,
refresh_interval=10,
)
ff_client = g._ff_client = FeatureFlagsClient(manager)
return ff_client


Expand Down
95 changes: 0 additions & 95 deletions featureflags_client/grpc/client.py

This file was deleted.

Loading

0 comments on commit 72b8140

Please sign in to comment.