Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rm grpc code, fix tests for http, update examples, docs #6

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading