Skip to content

Commit

Permalink
Merge branch 'feat/caching' into feat/grpc-sync-addition
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Schrottner <[email protected]>
  • Loading branch information
aepfli committed Dec 6, 2024
2 parents f91dd5c + 3c0e9cc commit c05b07d
Show file tree
Hide file tree
Showing 24 changed files with 618 additions and 247 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
name: "Build, lint, and test"

on:
push:
branches:
- main
pull_request:
types:
- opened
Expand All @@ -26,6 +29,7 @@ jobs:
package:
- "hooks/openfeature-hooks-opentelemetry"
- "providers/openfeature-provider-flagd"
- "providers/openfeature-provider-ofrep"

steps:
- uses: actions/checkout@v4
Expand All @@ -45,6 +49,11 @@ jobs:
run: hatch build
working-directory: ${{ matrix.package }}

- name: Type checking
if: matrix.python-version == '3.11'
working-directory: ${{ matrix.package }}
run: hatch run mypy:run

- name: Test with pytest
run: hatch test -c
working-directory: ${{ matrix.package }}
Expand Down
16 changes: 0 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,3 @@ repos:
- id: check-yaml
- id: trailing-whitespace
- id: check-merge-conflict

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
args: [--python-version=3.8]
additional_dependencies:
- openfeature-sdk>=0.4.0
- opentelemetry-api
- types-protobuf
- types-PyYAML
- types-requests
- mmh3
- semver
- panzi-json-logic
exclude: proto|tests
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ To run the integration tests you need to have a container runtime, like docker,
hatch run test
```

### Type checking

Run `mypy` by entering the package directory and running `hatch run mypy:run`.

## Pull Request

All contributions to the OpenFeature project are welcome via GitHub pull requests.
Expand Down
21 changes: 21 additions & 0 deletions hooks/openfeature-hooks-opentelemetry/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,31 @@ cov = [
"cov-report",
]

[tool.hatch.envs.mypy]
dependencies = [
"mypy[faster-cache]>=1.13.0",
]

[tool.hatch.envs.mypy.scripts]
run = "mypy"

[tool.hatch.build.targets.sdist]
exclude = [
".gitignore",
]

[tool.hatch.build.targets.wheel]
packages = ["src/openfeature"]

[tool.mypy]
mypy_path = "src"
files = "src"

python_version = "3.8" # should be identical to the minimum supported version
namespace_packages = true
explicit_package_bases = true
local_partial_types = true
pretty = true

strict = true
disallow_any_generics = false
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[mypy]
files = hooks,providers
files = hooks,providers/openfeature-provider-ofrep
exclude = proto|tests
untyped_calls_exclude = flagd.proto

Expand Down
33 changes: 1 addition & 32 deletions providers/openfeature-provider-flagd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,8 @@ The default options can be defined in the FlagdProvider constructor.
> [!NOTE]
> Some configurations are only applicable for RPC resolver.

<!--
### Unix socket support
Unix socket communication with flagd is facilitated by usaging of the linux-native `epoll` library on `linux-x86_64`
only (ARM support is pending the release of `netty-transport-native-epoll` v5).
Unix sockets are not supported on other platforms or architectures.
Expand All @@ -118,8 +116,7 @@ Unix sockets are not supported on other platforms or architectures.

Reconnection is supported by the underlying gRPC connections.
If the connection to flagd is lost, it will reconnect automatically.
A failure to connect will result in an [error event](https://openfeature.dev/docs/reference/concepts/events#provider_error) from the provider, though it will attempt to reconnect
indefinitely.
A failure to connect will result in an [error event](https://openfeature.dev/docs/reference/concepts/events#provider_error) from the provider, though it will attempt to reconnect indefinitely.

### Deadlines

Expand All @@ -131,24 +128,12 @@ They behave differently based on the resolver type.
If the remote evaluation call is not completed within this deadline, the gRPC call is terminated with the error `DEADLINE_EXCEEDED`
and the evaluation will default.

#### Deadlines with In-process resolver

In-process resolver with remote evaluation uses the `deadline` for synchronous gRPC calls to fetch metadata from flagd as part of its initialization process.
If fetching metadata fails within this deadline, the provider will try to reconnect.
The `streamDeadlineMs` defines a deadline for the streaming connection that listens to flag configuration updates from
flagd. After the deadline is exceeded, the provider closes the gRPC stream and will attempt to reconnect.

In-process resolver with offline evaluation uses the `deadline` for file reads to fetch flag definitions.
If the provider cannot open and read the file within this deadline, the provider will default the evaluation.


### TLS

TLS is available in situations where flagd is running on another host.

<!--
You may optionally supply an X.509 certificate in PEM format. Otherwise, the default certificate store will be used.
```java
FlagdProvider flagdProvider = new FlagdProvider(
FlagdOptions.builder()
Expand All @@ -159,22 +144,6 @@ FlagdProvider flagdProvider = new FlagdProvider(
```
-->

### Caching (RPC only)

> [!NOTE]
> The in-process resolver does not benefit from caching since all evaluations are done locally and do not involve I/O.
The provider attempts to establish a connection to flagd's event stream (up to 5 times by default).
If the connection is successful and caching is enabled, each flag returned with the reason `STATIC` is cached until an event is received
concerning the cached flag (at which point it is removed from the cache).

On invocation of a flag evaluation (if caching is available), an attempt is made to retrieve the entry from the cache, if
found the flag is returned with the reason `CACHED`.

By default, the provider is configured to
use [least recently used (lru)](https://pypi.org/project/cachebox/)
caching with up to 1000 entries.

## License

Apache 2.0 - See [LICENSE](./LICENSE) for more information.
46 changes: 42 additions & 4 deletions providers/openfeature-provider-flagd/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ classifiers = [
]
keywords = []
dependencies = [
"openfeature-sdk>=0.4.0",
"openfeature-sdk>=0.6.0",
"grpcio>=1.68.0",
"protobuf>=4.25.2",
"mmh3>=4.1.0",
Expand Down Expand Up @@ -60,6 +60,20 @@ cov = [
"cov-report",
]


[tool.hatch.envs.mypy]
dependencies = [
"mypy[faster-cache]>=1.13.0",
"types-protobuf",
"types-pyyaml",
]
pre-install-commands = [
"hatch build",
]

[tool.hatch.envs.mypy.scripts]
run = "mypy"

[tool.hatch.build.hooks.protobuf]
generate_pyi = false
dependencies = [
Expand All @@ -83,8 +97,6 @@ outputs = ["{proto_path}/{proto_name}_pb2_grpc.pyi"]
exclude = [
".gitignore",
"/openfeature",
"test-harness",
"spec"
]

[tool.hatch.build.targets.wheel]
Expand All @@ -93,6 +105,32 @@ packages = ["src/openfeature"]
[tool.coverage.run]
omit = [
# exclude generated files
"src/schemas/*",
"src/openfeature/schemas/*",
"tests/**",
]

[tool.mypy]
mypy_path = "src"
files = "src"

python_version = "3.8" # should be identical to the minimum supported version
namespace_packages = true
explicit_package_bases = true
local_partial_types = true
pretty = true

strict = true
disallow_any_generics = false

[[tool.mypy.overrides]]
module = [
"grpc.*",
"json_logic.*",
]
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = [
"openfeature.schemas.*"
]
warn_unused_ignores = false
10 changes: 10 additions & 0 deletions providers/openfeature-provider-flagd/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[pytest]
markers =
rpc: tests for rpc mode.
in-process: tests for rpc mode.
customCert: Supports custom certs.
unixsocket: Supports unixsockets.
events: Supports events.
sync: Supports sync.
caching: Supports caching.
offline: Supports offline.
Loading

0 comments on commit c05b07d

Please sign in to comment.